wip: implement add bookmark

This commit is contained in:
2025-05-07 23:09:14 +01:00
parent 9f00c9bb29
commit d3638ffc80
16 changed files with 409 additions and 38 deletions

View File

@@ -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 }