Reload header profile picture on change. Show PostContentMenu only if it is the creator own page
This commit is contained in:
@@ -4,6 +4,7 @@ import MyUserModel from "@/models/myUserModel.js";
|
|||||||
|
|
||||||
export const useUserStore = defineStore('user', () => {
|
export const useUserStore = defineStore('user', () => {
|
||||||
const user = ref({});
|
const user = ref({});
|
||||||
|
const hasChanged = ref(false);
|
||||||
|
|
||||||
function getCurrentUser() {
|
function getCurrentUser() {
|
||||||
return this.user.value;
|
return this.user.value;
|
||||||
@@ -12,6 +13,7 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
try {
|
try {
|
||||||
const myUser = await client.get("/api/GetMyUser");
|
const myUser = await client.get("/api/GetMyUser");
|
||||||
this.user.value = MyUserModel.createFromApiResult(myUser.data);
|
this.user.value = MyUserModel.createFromApiResult(myUser.data);
|
||||||
|
this.hasChanged = false;
|
||||||
} catch (e){
|
} catch (e){
|
||||||
this.user.value = MyUserModel.getDefaultUser();
|
this.user.value = MyUserModel.getDefaultUser();
|
||||||
console.log("User not logged.")
|
console.log("User not logged.")
|
||||||
@@ -19,34 +21,53 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateCurrentUser(client, myUserModel, profilePicture, bannerPicture, websiteIcon) {
|
async function updateCurrentUser(client, myUserModel, profilePicture, bannerPicture, websiteIcon) {
|
||||||
this.user.value = myUserModel;
|
|
||||||
await client.patch("/api/UpdateMyUser/profile", myUserModel)
|
await client.patch("/api/UpdateMyUser/profile", myUserModel)
|
||||||
|
|
||||||
if (typeof myUserModel.storedDataUrls.profilePictureUrl !== "object") {
|
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}`;
|
const haveNewProfilePicture = profilePicture !== null && profilePicture.size !== 0;
|
||||||
this.user.value.storedDataUrls.profilePictureUrl = await client.post(updateProfilePictureEndpoint, profilePicture, {
|
const updateProfilePictureEndpoint = haveNewProfilePicture ? `/api/UpdateMyUser/profile-picture` : `/api/UpdateMyUser/profile-picture?url=${myUserModel.storedDataUrls.profilePictureUrl}`;
|
||||||
|
const response = await client.post(updateProfilePictureEndpoint, profilePicture, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (haveNewProfilePicture) {
|
||||||
|
this.user.value.storedDataUrls.profilePictureUrl = response.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (typeof myUserModel.storedDataUrls.bannerPictureUrl !== "object") {
|
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}`;
|
const haveNewBannerPicture = bannerPicture !== null && bannerPicture.size !== 0;
|
||||||
this.user.value.storedDataUrls.bannerPictureUrl = await client.post(updateBannerPictureEndpoint, bannerPicture, {
|
|
||||||
|
const updateBannerPictureEndpoint = haveNewBannerPicture ? `/api/UpdateMyUser/banner-picture` : `/api/UpdateMyUser/banner-picture?url=${myUserModel.storedDataUrls.bannerPictureUrl}`;
|
||||||
|
const response = await client.post(updateBannerPictureEndpoint, bannerPicture, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (haveNewBannerPicture) {
|
||||||
|
this.user.value.storedDataUrls.bannerPictureUrl = response.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (typeof myUserModel.storedDataUrls.websiteIconUrl !== "object") {
|
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}`;
|
const haveNewWebsiteIcon = websiteIcon !== null && websiteIcon.size !== 0;
|
||||||
this.user.value.storedDataUrls.websiteIconUrl = await client.post(updateWebsiteIconEndpoint, websiteIcon, {
|
|
||||||
|
const updateWebsiteIconEndpoint = haveNewWebsiteIcon ? `/api/UpdateMyUser/website-icon` : `/api/UpdateMyUser/website-icon?url=${myUserModel.storedDataUrls.websiteIconUrl}`;
|
||||||
|
const response = await client.post(updateWebsiteIconEndpoint, websiteIcon, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/octet-stream',
|
'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 }
|
return { user, getCurrentUser, setCurrentUser, updateCurrentUser }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<!-- <MessageList content-id="00000001-0000-0000-0000-000000000001"></MessageList>-->
|
<!-- <MessageList content-id="00000001-0000-0000-0000-000000000001"></MessageList>-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
|
|
||||||
<PostContentMenu></PostContentMenu>
|
<PostContentMenu v-if="user.id === userStore.getCurrentUser().id"></PostContentMenu>
|
||||||
|
|
||||||
<StripePayment :creator-id="user.id"></StripePayment>
|
<StripePayment :creator-id="user.id"></StripePayment>
|
||||||
|
|
||||||
@@ -57,9 +57,11 @@ import {useClient} from "@/plugins/api.js";
|
|||||||
import {useRoute} from "vue-router";
|
import {useRoute} from "vue-router";
|
||||||
import CreatorBanner from "@/views/main/CreatorBanner.vue";
|
import CreatorBanner from "@/views/main/CreatorBanner.vue";
|
||||||
import StripePayment from "@/views/StripePayment.vue";
|
import StripePayment from "@/views/StripePayment.vue";
|
||||||
|
import {useUserStore} from "@/stores/user.js";
|
||||||
|
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const user = ref(null);
|
const user = ref(null);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
|
|||||||
@@ -104,16 +104,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {ref, onMounted, onBeforeUnmount, onBeforeMount} from "vue";
|
import {ref, onBeforeUnmount, onBeforeMount, watch, reactive} from "vue";
|
||||||
import {eventBus} from '@/eventBus.js';
|
import {eventBus} from '@/eventBus.js';
|
||||||
import {useRouter} from 'vue-router';
|
import {useRouter} from 'vue-router';
|
||||||
import {useUserStore} from "@/stores/user.js";
|
import {useUserStore} from "@/stores/user.js";
|
||||||
|
import MyUserModel from "@/models/myUserModel.js";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const currentUserName = ref("Anonyme");
|
const currentUserName = ref("Anonyme");
|
||||||
const searchQuery = ref("");
|
const searchQuery = ref("");
|
||||||
const showSearch = ref(false);
|
const showSearch = ref(false);
|
||||||
const currentUser = ref(null);
|
let currentUser = reactive(MyUserModel.getDefaultUser());
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const backupProfilePictureUrl = "/images/usersmedia/anonyme/profilepictures/profileAnonymeSquare.png"
|
const backupProfilePictureUrl = "/images/usersmedia/anonyme/profilepictures/profileAnonymeSquare.png"
|
||||||
|
|
||||||
@@ -159,12 +160,22 @@ const logout = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onBeforeMount( () => {
|
onBeforeMount( () => {
|
||||||
currentUser.value = userStore.getCurrentUser();
|
currentUser = userStore.getCurrentUser();
|
||||||
currentUserName.value = currentUser.value.userName;
|
currentUserName.value = currentUser.userName;
|
||||||
|
|
||||||
document.addEventListener('click', handleClickOutside);
|
document.addEventListener('click', handleClickOutside);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Watch the user state to get it again if needed.
|
||||||
|
watch(
|
||||||
|
() => userStore.hasChanged,
|
||||||
|
() => {
|
||||||
|
currentUser = userStore.getCurrentUser();
|
||||||
|
const timestamp = new Date().getTime();
|
||||||
|
currentUser.storedDataUrls.profilePictureUrl = `${currentUser.storedDataUrls.profilePictureUrl}?t=${timestamp}`;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
document.removeEventListener('click', handleClickOutside);
|
document.removeEventListener('click', handleClickOutside);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user