diff --git a/app/composables/useBoard.js b/app/composables/useBoard.js deleted file mode 100644 index 9e1fc47..0000000 --- a/app/composables/useBoard.js +++ /dev/null @@ -1,6 +0,0 @@ -export const useBoard = () => { - const getSuggestions = (params = {}) => - $fetch('/api/board/suggestions', { params }) - - return { getSuggestions } -} diff --git a/app/composables/useBoardChannels.js b/app/composables/useBoardChannels.js new file mode 100644 index 0000000..c64d103 --- /dev/null +++ b/app/composables/useBoardChannels.js @@ -0,0 +1,33 @@ +/** + * Board Channels Composable + * Shared state + helpers for mapping board tags to Slack channels. + */ +export function useBoardChannels() { + const channels = useState('board.channels', () => []) + + async function fetchChannels() { + const result = await $fetch('/api/board/channels') + channels.value = result || [] + return channels.value + } + + function resolveTagChannel(tagSlugs = []) { + if (!tagSlugs?.length) return null + return ( + channels.value.find((channel) => + (channel.tagSlugs || []).some((slug) => tagSlugs.includes(slug)) + ) || null + ) + } + + function slackUrl(channelId) { + return `https://gammaspace.slack.com/archives/${channelId}` + } + + return { + channels: readonly(channels), + fetchChannels, + resolveTagChannel, + slackUrl, + } +} diff --git a/app/composables/useBoardPosts.js b/app/composables/useBoardPosts.js new file mode 100644 index 0000000..e8a7087 --- /dev/null +++ b/app/composables/useBoardPosts.js @@ -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, + } +}