Skip to content

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

fix: crash when opening context menu in trash

thecodrrb4d7cef9852e
diff --git a/apps/web/src/components/trash-item/index.js b/apps/web/src/components/trash-item/index.js
index 2f678a42d..062f0a682 100644
--- a/apps/web/src/components/trash-item/index.js
+++ b/apps/web/src/components/trash-item/index.js
@@ -9,52 +9,6 @@ import { toTitleCase } from "../../utils/string";
import { showToast } from "../../utils/toast";
import { showPermanentDeleteToast } from "../../common/toasts";
-function menuItems(item, index) {
- return [
- {
- title: "Restore",
- onClick: () => {
- store.restore(item.id, index);
- showToast(
- "success",
- `${
- item.itemType === "note" ? "Note" : "Notebook"
- } restored successfully!`
- );
- },
- },
- {
- title: "Delete",
- color: "red",
- onClick: () => {
- confirm(Icon.Trash, {
- title: `Permanently Delete ${toTitleCase(item.itemType)}`,
- subtitle: `Are you sure you want to permanently delete this ${item.itemType}?`,
- yesText: `Delete ${item.itemType}`,
- noText: "Cancel",
- message: (
- <>
- This action is{" "}
- <Text as="span" color="error">
- IRREVERSIBLE
- </Text>
- . You will{" "}
- <Text as="span" color="primary">
- not be able to recover this {item.itemType}.
- </Text>
- </>
- ),
- }).then(async (res) => {
- if (res) {
- await store.delete(item.id);
- showPermanentDeleteToast(item, index);
- }
- });
- },
- },
- ];
-}
-
function TrashItem({ item, index }) {
return (
<ListItem
@@ -63,7 +17,7 @@ function TrashItem({ item, index }) {
title={item.title}
body={item.headline || item.description}
index={index}
- info={
+ footer={
<Flex variant="rowCenter">
<TimeAgo datetime={item.dateDeleted || item.dateCreated} />
<Text as="span" mx={1}>
@@ -72,8 +26,52 @@ function TrashItem({ item, index }) {
<Text color="primary">{toTitleCase(item.itemType)}</Text>
</Flex>
}
- menuItems={menuItems(item, index)}
+ menu={{ items: menuItems, extraData: { item } }}
/>
);
}
export default TrashItem;
+
+const menuItems = [
+ {
+ title: () => "Restore",
+ onClick: ({ item }) => {
+ store.restore(item.id);
+ showToast(
+ "success",
+ `${
+ item.itemType === "note" ? "Note" : "Notebook"
+ } restored successfully!`
+ );
+ },
+ },
+ {
+ title: () => "Delete",
+ color: "red",
+ onClick: ({ item }) => {
+ confirm(Icon.Trash, {
+ title: `Permanently Delete ${toTitleCase(item.itemType)}`,
+ subtitle: `Are you sure you want to permanently delete this ${item.itemType}?`,
+ yesText: `Delete ${item.itemType}`,
+ noText: "Cancel",
+ message: (
+ <>
+ This action is{" "}
+ <Text as="span" color="error">
+ IRREVERSIBLE
+ </Text>
+ . You will{" "}
+ <Text as="span" color="primary">
+ not be able to recover this {item.itemType}.
+ </Text>
+ </>
+ ),
+ }).then(async (res) => {
+ if (res) {
+ await store.delete(item.id);
+ showPermanentDeleteToast(item);
+ }
+ });
+ },
+ },
+];