refactor(board): accept refresh params in useBoardPosts mutators
This commit is contained in:
parent
61d33f5db3
commit
698f786951
2 changed files with 7 additions and 8 deletions
|
|
@ -17,29 +17,29 @@ export function useBoardPosts() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createPost(body) {
|
async function createPost(body, refreshParams = {}) {
|
||||||
const created = await $fetch('/api/board/posts', {
|
const created = await $fetch('/api/board/posts', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body,
|
body,
|
||||||
})
|
})
|
||||||
await fetchPosts()
|
await fetchPosts(refreshParams)
|
||||||
return created
|
return created
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updatePost(id, body) {
|
async function updatePost(id, body, refreshParams = {}) {
|
||||||
const updated = await $fetch(`/api/board/posts/${id}`, {
|
const updated = await $fetch(`/api/board/posts/${id}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body,
|
body,
|
||||||
})
|
})
|
||||||
await fetchPosts()
|
await fetchPosts(refreshParams)
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deletePost(id) {
|
async function deletePost(id, refreshParams = {}) {
|
||||||
const result = await $fetch(`/api/board/posts/${id}`, {
|
const result = await $fetch(`/api/board/posts/${id}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
})
|
})
|
||||||
await fetchPosts()
|
await fetchPosts(refreshParams)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -441,8 +441,7 @@ const postExcerpt = (post) => {
|
||||||
const handleDeletePost = async (post) => {
|
const handleDeletePost = async (post) => {
|
||||||
if (!window.confirm(`Delete "${post.title}"?`)) return;
|
if (!window.confirm(`Delete "${post.title}"?`)) return;
|
||||||
try {
|
try {
|
||||||
await deletePost(post._id);
|
await deletePost(post._id, { author: memberId.value });
|
||||||
await fetchPosts({ author: memberId.value });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Delete post error:", error);
|
console.error("Delete post error:", error);
|
||||||
toast.add({
|
toast.add({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue