Fix loading of page when accessing pages directly
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import {defineStore} from 'pinia'
|
import {defineStore} from 'pinia'
|
||||||
import {useClient} from "@/plugins/api.js";
|
import {useClient} from "@/plugins/api.js";
|
||||||
import {useSessionStorage} from "@vueuse/core";
|
import {useSessionStorage} from "@vueuse/core";
|
||||||
import {ref, watch} from "vue";
|
import {ref} from "vue";
|
||||||
import {useRoute} from "vue-router";
|
|
||||||
|
|
||||||
export const useBrandingStore = defineStore(
|
export const useBrandingStore = defineStore(
|
||||||
'branding',
|
'branding',
|
||||||
@@ -16,29 +15,25 @@ export const useBrandingStore = defineStore(
|
|||||||
{},
|
{},
|
||||||
{writeDefaults: false})
|
{writeDefaults: false})
|
||||||
|
|
||||||
const presentationInfos = ref([])
|
const presentationInfos = ref([])
|
||||||
|
|
||||||
const route = useRoute()
|
async function updateBrand(newBrand) {
|
||||||
watch(
|
loading.value = true
|
||||||
() => route.params.creator,
|
|
||||||
async (newCreator, oldCreator) => {
|
|
||||||
loading.value = true
|
|
||||||
|
|
||||||
if (newCreator !== oldCreator) {
|
if (newBrand !== currentBrand.value) {
|
||||||
if (newCreator !== undefined) {
|
if (newBrand !== undefined) {
|
||||||
value.value = await fetchCreatorData(newCreator)
|
value.value = await fetchCreatorData(newBrand)
|
||||||
currentBrand.value = newCreator
|
currentBrand.value = newBrand
|
||||||
presentationInfos.value = value.value?.presentationInfos
|
presentationInfos.value = value.value?.presentationInfos
|
||||||
} else {
|
} else {
|
||||||
value.value = {}
|
value.value = {}
|
||||||
currentBrand.value = undefined
|
currentBrand.value = undefined
|
||||||
presentationInfos.value = []
|
presentationInfos.value = []
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
|
||||||
const fetchCreatorData = async (creatorAlias) => {
|
const fetchCreatorData = async (creatorAlias) => {
|
||||||
try {
|
try {
|
||||||
@@ -53,7 +48,6 @@ export const useBrandingStore = defineStore(
|
|||||||
return {
|
return {
|
||||||
currentBrand,
|
currentBrand,
|
||||||
value,
|
value,
|
||||||
loading,
|
loading, updateBrand, presentationInfos
|
||||||
presentationInfos
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import {useClient} from '@/plugins/api.js';
|
|
||||||
import {useBrandingStore} from '@/stores/brandingStore.js';
|
import {useBrandingStore} from '@/stores/brandingStore.js';
|
||||||
import DonationButtonBanner from '@/views/creators/DonationButtonBanner.vue';
|
import DonationButtonBanner from '@/views/creators/DonationButtonBanner.vue';
|
||||||
import {onMounted, ref} from 'vue';
|
|
||||||
import CreatorLogo from "@/views/creators/CreatorLogo.vue";
|
import CreatorLogo from "@/views/creators/CreatorLogo.vue";
|
||||||
import NameTitle from "@/views/creators/NameTitle.vue";
|
import NameTitle from "@/views/creators/NameTitle.vue";
|
||||||
import Linkedin from "@/views/svg/Linkedin.vue";
|
import Linkedin from "@/views/svg/Linkedin.vue";
|
||||||
@@ -15,20 +14,7 @@ import Youtube from "@/views/svg/Youtube.vue";
|
|||||||
import Web from "@/views/svg/Web.vue";
|
import Web from "@/views/svg/Web.vue";
|
||||||
|
|
||||||
const brandingStore = useBrandingStore();
|
const brandingStore = useBrandingStore();
|
||||||
const creator = ref(null);
|
|
||||||
const baseURL = window.location.origin;
|
const baseURL = window.location.origin;
|
||||||
const creatorName = window.location.pathname.split('/@').pop();
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
const client = useClient();
|
|
||||||
try {
|
|
||||||
const creatorResponse = await client.get(`/api/creators/@${creatorName}`);
|
|
||||||
creator.value = creatorResponse.data;
|
|
||||||
} catch (error) {
|
|
||||||
creator.value = undefined;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -53,11 +39,11 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<donation-button-banner
|
<donation-button-banner
|
||||||
v-if="brandingStore.value?.acceptDonation && creator"
|
v-if="brandingStore.value?.acceptDonation"
|
||||||
:creator-id="creator.id"
|
:creator-id="brandingStore.value?.id"
|
||||||
:creator-name="creator.name"
|
:creator-name="brandingStore.value?.name"
|
||||||
:on-cancelled-url="baseURL + '/paymentfailed/' + creator.id"
|
:on-cancelled-url="baseURL + '/paymentfailed/' + brandingStore.value?.id"
|
||||||
:on-success-url="baseURL + '/paymentcompleted/' + creator.id"
|
:on-success-url="baseURL + '/paymentcompleted/' + brandingStore.value?.id"
|
||||||
></donation-button-banner>
|
></donation-button-banner>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -22,9 +22,16 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script async setup>
|
<script async setup>
|
||||||
|
import {useBrandingStore} from "@/stores/brandingStore.js";
|
||||||
|
import {onMounted} from "vue";
|
||||||
import Banner from "@/views/creators/Banner.vue";
|
import Banner from "@/views/creators/Banner.vue";
|
||||||
import Footer from "@/views/main/Footer.vue";
|
import Footer from "@/views/main/Footer.vue";
|
||||||
import {useBrandingStore} from "@/stores/brandingStore.js";
|
|
||||||
|
|
||||||
const brandingStore = useBrandingStore()
|
const brandingStore = useBrandingStore();
|
||||||
|
const creatorName = window.location.pathname.split('/@').pop();
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await brandingStore.updateBrand(creatorName);
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user