Reload header profile picture on change. Show PostContentMenu only if it is the creator own page

This commit is contained in:
Dominic Villemure
2024-07-05 02:19:42 -04:00
parent d6ab03ad18
commit 45bdac0de1
3 changed files with 47 additions and 13 deletions

View File

@@ -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 }