feat: add useBoardPosts + useBoardChannels composables, remove useBoard
- useBoardPosts: CRUD with useState('board.posts','board.loading')
- useBoardChannels: fetch + resolveTagChannel + slackUrl helpers
- useBoard.js removed (old suggestions wrapper); only app/pages/board.vue still imports it, will be rewritten in Phase 5
This commit is contained in:
parent
1fc937a26a
commit
78db4be7ba
3 changed files with 87 additions and 6 deletions
54
app/composables/useBoardPosts.js
Normal file
54
app/composables/useBoardPosts.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Board Posts Composable
|
||||
* Shared state + CRUD for board posts.
|
||||
*/
|
||||
export function useBoardPosts() {
|
||||
const posts = useState('board.posts', () => [])
|
||||
const loading = useState('board.loading', () => false)
|
||||
|
||||
async function fetchPosts(params = {}) {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await $fetch('/api/board/posts', { params })
|
||||
posts.value = result || []
|
||||
return posts.value
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createPost(body) {
|
||||
const created = await $fetch('/api/board/posts', {
|
||||
method: 'POST',
|
||||
body,
|
||||
})
|
||||
await fetchPosts()
|
||||
return created
|
||||
}
|
||||
|
||||
async function updatePost(id, body) {
|
||||
const updated = await $fetch(`/api/board/posts/${id}`, {
|
||||
method: 'PATCH',
|
||||
body,
|
||||
})
|
||||
await fetchPosts()
|
||||
return updated
|
||||
}
|
||||
|
||||
async function deletePost(id) {
|
||||
const result = await $fetch(`/api/board/posts/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
await fetchPosts()
|
||||
return result
|
||||
}
|
||||
|
||||
return {
|
||||
posts: readonly(posts),
|
||||
loading: readonly(loading),
|
||||
fetchPosts,
|
||||
createPost,
|
||||
updatePost,
|
||||
deletePost,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue