diff --git a/frontend/src/stores/postModal.js b/frontend/src/stores/postModal.js new file mode 100644 index 0000000..64fd1c9 --- /dev/null +++ b/frontend/src/stores/postModal.js @@ -0,0 +1,39 @@ +import { defineStore } from 'pinia' +import { ref, computed } from 'vue' +import { usePostsStore } from './posts.js' + +export const usePostModalStore = defineStore('postModal', () => { + const postsStore = usePostsStore() + + // Feed-shape on open; upgraded to detail shape (full description + + // uncapped thumbnails) once getPostFull resolves. + const currentPost = ref(null) + const detailLoaded = ref(false) + const error = ref(null) + const isOpen = computed(() => currentPost.value !== null) + + async function open (post) { + currentPost.value = post + detailLoaded.value = false + error.value = null + try { + const detail = await postsStore.getPostFull(post.id) + if (currentPost.value?.id === post.id) { + currentPost.value = detail + detailLoaded.value = true + } + } catch (e) { + // Keep feed-shape data; PostModal can still render title + truncated + // description + the up-to-6 feed thumbnails. Just surface the error. + error.value = e.message + } + } + + function close () { + currentPost.value = null + detailLoaded.value = false + error.value = null + } + + return { currentPost, detailLoaded, error, isOpen, open, close } +})