From 78ce0839d817c96cb3d6d88e080159c4f8700649 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Sat, 23 Dec 2023 03:16:54 +0200 Subject: [PATCH] Add delete for custom templates --- src/pages/Templates.jsx | 46 ++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) 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" > -
+
{defaultTemplates?.map((t, i) => (
{c.title}
- +
+
+
+ +
+