From cd5ee8e724934ace83fbe1acc92588b8b5660650 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Sat, 16 May 2020 14:05:06 +0500 Subject: [PATCH] feat: add topic deletion --- apps/web/src/components/menu/index.js | 2 +- apps/web/src/components/note/index.js | 2 +- apps/web/src/components/topic/index.js | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js index 6569b5d21..a0375124f 100644 --- a/apps/web/src/components/menu/index.js +++ b/apps/web/src/components/menu/index.js @@ -33,7 +33,7 @@ function Menu(props) { {props.menuItems.map( (item) => - !item.visible && ( + (item.visible === undefined || item.visible === true) && ( { diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js index 8bccfe942..26f5c00f8 100644 --- a/apps/web/src/components/note/index.js +++ b/apps/web/src/components/note/index.js @@ -48,7 +48,7 @@ function menuItems(note, context) { onlyPro: true, }, { - visible: context ? (context.type === "topic" ? true : false) : false, + visible: context && context.type === "topic", title: "Remove", onClick: async () => { confirm( diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.js index dfbeadba5..b5f14fdae 100644 --- a/apps/web/src/components/topic/index.js +++ b/apps/web/src/components/topic/index.js @@ -1,6 +1,10 @@ import React from "react"; import ListItem from "../list-item"; import { showEditTopicDialog } from "../dialogs/topicdialog"; +import { confirm } from "../dialogs/confirm"; +import * as Icon from "../icons"; +import { db } from "../../common"; +import { store } from "../../stores/notebook-store"; const menuItems = (item) => [ { @@ -8,11 +12,24 @@ const menuItems = (item) => [ onClick: () => { showEditTopicDialog(item); }, - visible: item.title === "General", + visible: item.title !== "General", }, { title: "Delete", + visible: item.title !== "General", color: "red", + onClick: () => { + confirm( + Icon.Trash, + "Delete Topic", + "Are you sure you want to delete this topic?" + ).then(async (res) => { + if (res) { + await db.notebooks.notebook(item.notebookId).topics.delete(item.id); + store.setSelectedNotebookTopics(item.notebookId); + } + }); + }, }, ];