wip: implement add bookmark
This commit is contained in:
@@ -27,4 +27,32 @@ function useDeleteBookmark() {
|
||||
})
|
||||
}
|
||||
|
||||
export { useDeleteBookmark }
|
||||
function useCreateBookmark() {
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ url, force = false }: { url: string; force?: boolean }) =>
|
||||
fetchApi("/bookmarks", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
url,
|
||||
force,
|
||||
kind: "link",
|
||||
tags: [],
|
||||
}),
|
||||
}).then((res) => (res.status === 204 ? Promise.resolve() : res.json())),
|
||||
onError: (error) => {
|
||||
if (error instanceof UnauthenticatedError) {
|
||||
navigate({ to: "/login", replace: true })
|
||||
}
|
||||
},
|
||||
onSuccess: (bookmark: Bookmark | undefined) => {
|
||||
if (bookmark) {
|
||||
queryClient.setQueryData(["bookmarks"], (bookmarks: Bookmark[]) => [bookmark, ...bookmarks])
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export { useDeleteBookmark, useCreateBookmark }
|
||||
|
Reference in New Issue
Block a user