feat(postmodal-store): Pinia store driving the app-level PostModal — open(post) fetches full detail via posts store; close() clears
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
Reference in New Issue
Block a user