Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add remove from topic menu item (#137)

Muhammad Ali17d76dc9902d
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index 21b0df188..7f7cd94f5 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -28,35 +28,38 @@ function Menu(props) {
>
Properties
</Text>
- {props.menuItems.map(item => (
- <Flex
- key={item.title}
- onClick={e => {
- e.stopPropagation();
- Dropdown.closeLastOpened();
- if (props.closeMenu) {
- props.closeMenu();
- }
- if (item.onClick) {
- item.onClick(props.data);
- }
- }}
- flexDirection="row"
- alignItems="center"
- py={"8px"}
- px={3}
- sx={{
- color: item.color || "fontPrimary",
- ":hover": {
- backgroundColor: "shade"
- }
- }}
- >
- <Text as="span" fontFamily="body" fontSize="menu">
- {item.title}
- </Text>
- </Flex>
- ))}
+ {props.menuItems.map(
+ item =>
+ !item.invisible && (
+ <Flex
+ key={item.title}
+ onClick={e => {
+ e.stopPropagation();
+ Dropdown.closeLastOpened();
+ if (props.closeMenu) {
+ props.closeMenu();
+ }
+ if (item.onClick) {
+ item.onClick(props.data);
+ }
+ }}
+ flexDirection="row"
+ alignItems="center"
+ py={"8px"}
+ px={3}
+ sx={{
+ color: item.color || "fontPrimary",
+ ":hover": {
+ backgroundColor: "shade"
+ }
+ }}
+ >
+ <Text as="span" fontFamily="body" fontSize="menu">
+ {item.title}
+ </Text>
+ </Flex>
+ )
+ )}
</Box>
</Flex>
);
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index 910d20677..d9c66e551 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -12,7 +12,7 @@ import { showPasswordDialog } from "../dialogs/passworddialog";
import { db } from "../../common";
const dropdownRefs = [];
-const menuItems = (note, index) => [
+const menuItems = (note, index, context) => [
{
title: note.notebook ? "Move" : "Add to",
onClick: async () => {
@@ -41,6 +41,25 @@ const menuItems = (note, index) => [
}
}
},
+ {
+ invisible: !context,
+ title: "Remove",
+ onClick: async () => {
+ confirm(
+ Icon.Book,
+ "Remove",
+ "Are you sure you want to Remove this note?"
+ ).then(async res => {
+ if (res) {
+ await db.notebooks
+ .notebook(context.notebook.id)
+ .topics.topic(context.value)
+ .delete(note.id);
+ await store.getState().setSelectedContext(context);
+ }
+ });
+ }
+ },
{
title: "Move to Trash",
color: "red",
@@ -113,7 +132,7 @@ function Note(props) {
}
pinned={props.pinnable && note.pinned}
menuData={note}
- menuItems={menuItems(note, index)}
+ menuItems={menuItems(note, index, props.context)}
dropdownRefs={dropdownRefs}
/>
);
diff --git a/apps/web/src/views/Notes.js b/apps/web/src/views/Notes.js
index 621a171c0..7bbf89cad 100644
--- a/apps/web/src/views/Notes.js
+++ b/apps/web/src/views/Notes.js
@@ -11,6 +11,7 @@ const Notes = props => {
const clearSelectedContext = useNotesStore(
store => store.clearSelectedContext
);
+ const selectedContext = useNotesStore(store => store.selectedContext);
useEffect(() => {
return () => {
clearSelectedContext();
@@ -21,7 +22,12 @@ const Notes = props => {
type="notes"
items={selectedNotes}
item={(index, item) => (
- <Note index={index} pinnable={false} item={item} />
+ <Note
+ index={index}
+ pinnable={false}
+ item={item}
+ context={selectedContext}
+ />
)}
button={{
content: "Make a new note",