From ca393b19432997e8076fb4d77ee82bf33755d251 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Fri, 15 Apr 2022 23:09:24 +0500 Subject: [PATCH] fix: crash on notebooks & other related views (fixes streetwriters/notesnook#504, streetwriters/notesnook#512, streetwriters/notesnook#513) --- apps/web/src/components/dialogs/move-note-dialog.js | 7 ++++--- apps/web/src/components/topic/index.js | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/dialogs/move-note-dialog.js b/apps/web/src/components/dialogs/move-note-dialog.js index fe15e1a52..17bdae8a2 100644 --- a/apps/web/src/components/dialogs/move-note-dialog.js +++ b/apps/web/src/components/dialogs/move-note-dialog.js @@ -9,6 +9,7 @@ import { store as notestore } from "../../stores/note-store"; import { useStore, store } from "../../stores/notebook-store"; import { getTotalNotes } from "../../common"; import Accordion from "../accordion"; +import { pluralize } from "../../utils/string"; function MoveDialog({ onClose, noteIds }) { const [selected, setSelected] = useState([]); @@ -139,7 +140,7 @@ function MoveDialog({ onClose, noteIds }) { indent={1} icon={Icon.Topic} title={topic.title} - totalNotes={topic.notes.length} + totalNotes={topic.notes?.length || 0} action={ isSelected && hasNotes ? ( topic.notes.indexOf(id) > -1); + return noteIds.some((id) => topic.notes && topic.notes.indexOf(id) > -1); } function FilteredList({ @@ -292,7 +293,7 @@ function Item(props) { > {title} - {totalNotes + " notes"} + {pluralize(totalNotes, "note", "notes")} {action} diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.js index 0c27905b6..9af6537c0 100644 --- a/apps/web/src/components/topic/index.js +++ b/apps/web/src/components/topic/index.js @@ -1,7 +1,6 @@ import React from "react"; import ListItem from "../list-item"; import { db } from "../../common/db"; -import { store } from "../../stores/notebook-store"; import { store as appStore } from "../../stores/app-store"; import { hashNavigate } from "../../navigation"; import { Flex, Text } from "rebass"; @@ -29,7 +28,7 @@ function Topic({ item, index, onClick }) { • - {pluralize(topic.notes.length, "note", "notes")} + {pluralize(topic.notes?.length || 0, "note", "notes")} }