import { useCallback, useState } from "react"; import useSWR, { useSWRConfig } from "swr"; import type { Template, TemplateMeta, TemplateImage, BaseTemplate, } from "./types"; import { ApiError, fetchApi } from "@/api"; import { promiseOrThrow } from "@/lib/errors"; function useTemplates() { return useSWR( "/templates", async (): Promise => fetchApi("/templates").then((res) => res.json()), ); } function useTemplate(name: string) { return useSWR( ["/templates", name], async (): Promise