diff --git a/src/stores/user.js b/src/stores/user.js index 1512730..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,26 +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) - - this.user.value.storedDataUrls.profilePictureUrl = await client.post("/api/UpdateMyUser/profile-picture", profilePicture, { - headers: { - 'Content-Type': 'application/octet-stream', - } - }); - this.user.value.storedDataUrls.bannerPictureUrl = await client.post("/api/UpdateMyUser/banner-picture", bannerPicture, { - headers: { - 'Content-Type': 'application/octet-stream', + if (typeof myUserModel.storedDataUrls.profilePictureUrl !== "object") { + 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 haveNewBannerPicture = bannerPicture !== null && bannerPicture.size !== 0; - this.user.value.storedDataUrls.websiteIconUrl = await client.post("/api/UpdateMyUser/website-icon", websiteIcon, { - headers: { - 'Content-Type': 'application/octet-stream', + 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 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 d608ba2..185620a 100644 --- a/src/views/main/Creator.vue +++ b/src/views/main/Creator.vue @@ -1,49 +1,90 @@ - diff --git a/src/views/main/CreatorBanner.vue b/src/views/main/CreatorBanner.vue new file mode 100644 index 0000000..f050f6d --- /dev/null +++ b/src/views/main/CreatorBanner.vue @@ -0,0 +1,118 @@ + + + \ No newline at end of file diff --git a/src/views/main/Header.vue b/src/views/main/Header.vue index 7e5b01c..b9d2214 100644 --- a/src/views/main/Header.vue +++ b/src/views/main/Header.vue @@ -39,7 +39,9 @@ class="rounded-full w-32 md:w-64 lg:w-96 mx-2" append-inner-icon="mdi-magnify" @click.stop - @click:append-inner="onSearch"> + @click:append-inner="onSearch" + @keyup.enter="onSearch" + >