implement bookmark tagging

This commit is contained in:
2025-05-21 13:18:16 +01:00
parent f048dee6e2
commit b0d458e5ca
20 changed files with 826 additions and 362 deletions

View File

@@ -18,13 +18,16 @@ class BadRequestError extends Error {
}
class InternalError extends Error {}
class UnauthenticatedError extends Error {}
class NotFoundError extends Error {}
interface ErrorBody {
code: string
message?: string
}
type QueryKey = ["bookmarks", ...ReadonlyArray<unknown>] | ["bookmarks", string, ...ReadonlyArray<unknown>]
type QueryKey =
| ["bookmarks" | "tags", ...ReadonlyArray<unknown>]
| ["bookmarks" | "tags", string, ...ReadonlyArray<unknown>]
async function fetchApi(route: string, init?: RequestInit): Promise<Response> {
const response = await fetch(`${import.meta.env.VITE_API_URL}/api${route}`, {
@@ -42,6 +45,8 @@ async function fetchApi(route: string, init?: RequestInit): Promise<Response> {
case 401: {
throw new UnauthenticatedError()
}
case 404:
throw new NotFoundError()
default:
throw new InternalError()
}
@@ -50,8 +55,8 @@ async function fetchApi(route: string, init?: RequestInit): Promise<Response> {
function useAuthenticatedQuery<TData>(queryKey: QueryKey, fn: () => Promise<TData>) {
const query = useQuery({
queryKey,
queryFn: () => fn(),
retry: (_, error) => !(error instanceof UnauthenticatedError),
queryFn: fn,
retry: false,
})
const navigate = useNavigate()
@@ -76,6 +81,7 @@ export {
BadRequestError,
InternalError,
UnauthenticatedError,
NotFoundError,
fetchApi,
useAuthenticatedQuery,
mutationOptions,