implement nav chrome for bookmark previewer

This commit is contained in:
2025-05-14 18:27:41 +01:00
parent c73082b9c9
commit 37cdf30159
14 changed files with 260 additions and 134 deletions

View File

@@ -1,7 +1,15 @@
import type { Bookmark } from "@markone/core/bookmark"
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { useNavigate } from "@tanstack/react-router"
import { UnauthenticatedError, fetchApi } from "~/api"
import { UnauthenticatedError, fetchApi, useAuthenticatedQuery } from "~/api"
function useBookmark(id: string) {
return useAuthenticatedQuery(["bookmarks", id], () =>
fetchApi(`/bookmarks/${id}`, {
headers: { Accept: "application/json" },
}).then((res): Promise<Bookmark> => res.json()),
)
}
function useDeleteBookmark() {
const navigate = useNavigate()
@@ -9,7 +17,7 @@ function useDeleteBookmark() {
return useMutation({
mutationFn: ({ bookmark }: { bookmark: Bookmark }) =>
fetchApi(`/bookmark/${bookmark.id}`, {
fetchApi(`/bookmarks/${bookmark.id}`, {
method: "DELETE",
}),
onError: (error) => {
@@ -53,4 +61,4 @@ function useCreateBookmark() {
})
}
export { useDeleteBookmark, useCreateBookmark }
export { useBookmark, useDeleteBookmark, useCreateBookmark }