From 45bdac0de1cf3de86a25e51c0ca89abc437218a6 Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Fri, 5 Jul 2024 02:19:42 -0400 Subject: [PATCH] Reload header profile picture on change. Show PostContentMenu only if it is the creator own page --- src/stores/user.js | 37 +++++++++++++++++++++++++++++-------- src/views/main/Creator.vue | 4 +++- src/views/main/Header.vue | 19 +++++++++++++++---- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/stores/user.js b/src/stores/user.js index 30e23f6..1b45f26 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -4,6 +4,7 @@ import MyUserModel from "@/models/myUserModel.js"; export const useUserStore = defineStore('user', () => { const user = ref({}); + const hasChanged = ref(false); function getCurrentUser() { return this.user.value; @@ -12,6 +13,7 @@ export const useUserStore = defineStore('user', () => { try { const myUser = await client.get("/api/GetMyUser"); this.user.value = MyUserModel.createFromApiResult(myUser.data); + this.hasChanged = false; } catch (e){ this.user.value = MyUserModel.getDefaultUser(); console.log("User not logged.") @@ -19,33 +21,52 @@ export const useUserStore = defineStore('user', () => { } async function updateCurrentUser(client, myUserModel, profilePicture, bannerPicture, websiteIcon) { - this.user.value = myUserModel; await client.patch("/api/UpdateMyUser/profile", myUserModel) - + if (typeof myUserModel.storedDataUrls.profilePictureUrl !== "object") { - const updateProfilePictureEndpoint = profilePicture !== null && profilePicture.size !== 0 ? `/api/UpdateMyUser/profile-picture` : `/api/UpdateMyUser/profile-picture?url=${myUserModel.storedDataUrls.profilePictureUrl}`; - this.user.value.storedDataUrls.profilePictureUrl = await client.post(updateProfilePictureEndpoint, profilePicture, { + const haveNewProfilePicture = profilePicture !== null && profilePicture.size !== 0; + const updateProfilePictureEndpoint = haveNewProfilePicture ? `/api/UpdateMyUser/profile-picture` : `/api/UpdateMyUser/profile-picture?url=${myUserModel.storedDataUrls.profilePictureUrl}`; + const response = await client.post(updateProfilePictureEndpoint, profilePicture, { headers: { 'Content-Type': 'application/octet-stream', } }); + + if (haveNewProfilePicture) { + this.user.value.storedDataUrls.profilePictureUrl = response.data; + } } if (typeof myUserModel.storedDataUrls.bannerPictureUrl !== "object") { - const updateBannerPictureEndpoint = bannerPicture !== null && bannerPicture.size !== 0 ? `/api/UpdateMyUser/banner-picture` : `/api/UpdateMyUser/banner-picture?url=${myUserModel.storedDataUrls.bannerPictureUrl}`; - this.user.value.storedDataUrls.bannerPictureUrl = await client.post(updateBannerPictureEndpoint, bannerPicture, { + const haveNewBannerPicture = bannerPicture !== null && bannerPicture.size !== 0; + + const updateBannerPictureEndpoint = haveNewBannerPicture ? `/api/UpdateMyUser/banner-picture` : `/api/UpdateMyUser/banner-picture?url=${myUserModel.storedDataUrls.bannerPictureUrl}`; + const response = await client.post(updateBannerPictureEndpoint, bannerPicture, { headers: { 'Content-Type': 'application/octet-stream', } }); + + if (haveNewBannerPicture) { + this.user.value.storedDataUrls.bannerPictureUrl = response.data; + } } if (typeof myUserModel.storedDataUrls.websiteIconUrl !== "object") { - const updateWebsiteIconEndpoint = websiteIcon !== null && websiteIcon.size !== 0 ? `/api/UpdateMyUser/website-icon` : `/api/UpdateMyUser/website-icon?url=${myUserModel.storedDataUrls.websiteIconUrl}`; - this.user.value.storedDataUrls.websiteIconUrl = await client.post(updateWebsiteIconEndpoint, websiteIcon, { + const haveNewWebsiteIcon = websiteIcon !== null && websiteIcon.size !== 0; + + const updateWebsiteIconEndpoint = haveNewWebsiteIcon ? `/api/UpdateMyUser/website-icon` : `/api/UpdateMyUser/website-icon?url=${myUserModel.storedDataUrls.websiteIconUrl}`; + const response = await client.post(updateWebsiteIconEndpoint, websiteIcon, { headers: { 'Content-Type': 'application/octet-stream', } }); + + if (haveNewWebsiteIcon) { + this.user.value.storedDataUrls.websiteIconUrl = response.data; + } } + + this.user.value = myUserModel; + this.hasChanged = true; } return { user, getCurrentUser, setCurrentUser, updateCurrentUser } diff --git a/src/views/main/Creator.vue b/src/views/main/Creator.vue index 4735b09..7168076 100644 --- a/src/views/main/Creator.vue +++ b/src/views/main/Creator.vue @@ -13,7 +13,7 @@ - + @@ -57,9 +57,11 @@ import {useClient} from "@/plugins/api.js"; import {useRoute} from "vue-router"; import CreatorBanner from "@/views/main/CreatorBanner.vue"; import StripePayment from "@/views/StripePayment.vue"; +import {useUserStore} from "@/stores/user.js"; const client = useClient(); const route = useRoute(); +const userStore = useUserStore(); const user = ref(null); const loading = ref(true); diff --git a/src/views/main/Header.vue b/src/views/main/Header.vue index 4abb414..e11fdcd 100644 --- a/src/views/main/Header.vue +++ b/src/views/main/Header.vue @@ -104,16 +104,17 @@