diff --git a/src/pages/Templates.jsx b/src/pages/Templates.jsx index c112540..ebaa6f3 100644 --- a/src/pages/Templates.jsx +++ b/src/pages/Templates.jsx @@ -1,8 +1,10 @@ -import { useEffect, useState } from "react"; +import { useEffect } from "react"; import logo_light from "../assets/logo_light_46.png"; import { Link } from "react-router-dom"; import { Tabs, TabPane } from "@douyinfe/semi-ui"; +import { IconDeleteStroked } from "@douyinfe/semi-icons"; import { db } from "../data/db"; +import { useLiveQuery } from "dexie-react-hooks"; import { calcPath } from "../utils"; function Thumbnail({ diagram, i }) { @@ -158,19 +160,19 @@ function Thumbnail({ diagram, i }) { } export default function Templates() { - const [defaultTemplates, setDefaultTemplates] = useState([]); - const [customTemplates, setCustomTemplates] = useState([]); + const defaultTemplates = useLiveQuery(() => + db.templates.where({ custom: 0 }).toArray() + ); + const customTemplates = useLiveQuery(() => + db.templates.where({ custom: 1 }).toArray() + ); + + const deleteTemplate = async (id) => { + await db.templates.delete(id); + }; useEffect(() => { document.title = "Templates | drawDB"; - const loadTemplates = async () => { - const def = await db.templates.where({ custom: 0 }).toArray(); - setDefaultTemplates(def); - const custom = await db.templates.where({ custom: 1 }).toArray(); - setCustomTemplates(custom); - }; - - loadTemplates(); }, []); return ( @@ -206,7 +208,7 @@ export default function Templates() { tab={Default templates} itemKey="1" > -