34 lines
799 B
TypeScript
34 lines
799 B
TypeScript
|
|
import { onBeforeMount, ref } from 'vue'
|
||
|
|
import type { Ref } from 'vue';
|
||
|
|
import { useRoute } from 'vue-router';
|
||
|
|
|
||
|
|
import {
|
||
|
|
activist,
|
||
|
|
type Sticker as StickerType,
|
||
|
|
useStickersStore,
|
||
|
|
} from '@/stores/stickersStore'
|
||
|
|
|
||
|
|
|
||
|
|
export function useSticker() {
|
||
|
|
let sticker: Ref<StickerType> = ref<StickerType>(activist);
|
||
|
|
const route = useRoute();
|
||
|
|
if (!("uuid" in route.params)) {
|
||
|
|
return sticker;
|
||
|
|
}
|
||
|
|
const uuid = ref<string>(route.params.uuid as string);
|
||
|
|
const stickersStore = useStickersStore();
|
||
|
|
const { getSticker } = stickersStore;
|
||
|
|
|
||
|
|
onBeforeMount(async () => {
|
||
|
|
await stickersStore.fetch(uuid.value);
|
||
|
|
let sticker2 = getSticker(uuid.value);
|
||
|
|
if (!sticker2) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
sticker.value = sticker2;
|
||
|
|
stickersStore.activeSticker = uuid.value
|
||
|
|
});
|
||
|
|
|
||
|
|
return sticker;
|
||
|
|
}
|