fix(board): handle submit errors + tolerate tag fetch failure

This commit is contained in:
Jennie Robinson Faber 2026-04-14 17:14:22 +01:00
parent c06cdd71fd
commit 5bdc3244bd

View file

@ -93,6 +93,7 @@ definePageMeta({ middleware: ['members-auth'] })
const { memberData } = useAuth() const { memberData } = useAuth()
const { posts, loading, fetchPosts, createPost, updatePost, deletePost } = useBoardPosts() const { posts, loading, fetchPosts, createPost, updatePost, deletePost } = useBoardPosts()
const { channels, fetchChannels } = useBoardChannels() const { channels, fetchChannels } = useBoardChannels()
const toast = useToast()
const cooperativeTags = ref([]) const cooperativeTags = ref([])
const showTagsDrawer = ref(false) const showTagsDrawer = ref(false)
@ -150,12 +151,20 @@ const handleDelete = async (post) => {
} }
const handleSubmit = async (body) => { const handleSubmit = async (body) => {
if (editingPost.value) { try {
await updatePost(editingPost.value._id, body) if (editingPost.value) {
} else { await updatePost(editingPost.value._id, body)
await createPost(body) } else {
await createPost(body)
}
closeForm()
} catch (err) {
toast.add({
title: editingPost.value ? 'Failed to update post' : 'Failed to create post',
description: err?.data?.message || err?.message || 'Please try again.',
color: 'red',
})
} }
closeForm()
} }
const loadTags = async () => { const loadTags = async () => {
@ -174,7 +183,7 @@ useHead({
}) })
onMounted(async () => { onMounted(async () => {
await Promise.all([loadTags(), fetchPosts(), fetchChannels()]) await Promise.allSettled([loadTags(), fetchPosts(), fetchChannels()])
}) })
</script> </script>