A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: crash when group by none in notebook (fixes streetwriters/notesnook#480)
thecodrrbbfd7a9f7a27
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.jsindex 3195ae3eb..4ee30e8ab 100644--- a/apps/web/src/common/dialogcontroller.js+++ b/apps/web/src/common/dialogcontroller.js@@ -19,6 +19,7 @@ import downloadUpdate from "../commands/download-update";import installUpdate from "../commands/install-update";import { getChangelog } from "../utils/version";import { isDesktop } from "../utils/platform";+import { pluralize } from "../utils/string";function showDialog(dialog) {return new Promise((resolve, reject) => {@@ -257,9 +258,11 @@ export function showExportDialog(noteIds) {return showDialog((Dialogs, perform) => (<Dialogs.ExportDialognoteIds={noteIds}- title={- noteIds.length > 1 ? `Export ${noteIds.length} notes` : "Export note"- }+ title={`Export ${noteIds.length} ${pluralize(+ noteIds.length,+ "note",+ "notes"+ )}`}icon={Icon.Export}onClose={() => perform(false)}onDone={() => perform(true)}diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.jsindex b7a822b79..4b08a577b 100644--- a/apps/web/src/common/index.js+++ b/apps/web/src/common/index.js@@ -151,6 +151,7 @@ export async function restoreBackupFile(backup) {export function getTotalNotes(notebook) {return notebook.topics.reduce((sum, topic) => {+ if (!topic || !topic.notes) return sum;return sum + topic.notes.length;}, 0);}diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.jsindex 01c17dfc6..b997a76c3 100644--- a/apps/web/src/components/notebook/index.js+++ b/apps/web/src/components/notebook/index.js@@ -10,6 +10,7 @@ import { hashNavigate, navigate } from "../../navigation";import IconTag from "../icon-tag";import { showToast } from "../../utils/toast";import { Multiselect } from "../../common/multi-select";+import { pluralize } from "../../utils/string";function Notebook(props) {const { item, index, totalNotes, date } = props;@@ -32,7 +33,7 @@ function Notebook(props) {isCompact ? (<><Text fontSize="subBody" color="fontTertiary">- {totalNotes} {totalNotes > 1 ? "notes" : "note"}+ {pluralize(totalNotes, "note", "notes")}</Text></>) : (@@ -70,9 +71,7 @@ function Notebook(props) {<Text as="span" mx={1}>•</Text>- <Text>- {totalNotes} {totalNotes > 1 ? "notes" : "note"}- </Text>+ <Text>{pluralize(totalNotes, "note", "notes")}</Text></Flex></>)diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.jsindex dec03903a..0c27905b6 100644--- a/apps/web/src/components/topic/index.js+++ b/apps/web/src/components/topic/index.js@@ -7,6 +7,7 @@ import { hashNavigate } from "../../navigation";import { Flex, Text } from "rebass";import * as Icon from "../icons";import { Multiselect } from "../../common/multi-select";+import { pluralize } from "../../utils/string";function Topic({ item, index, onClick }) {const topic = item;@@ -27,7 +28,9 @@ function Topic({ item, index, onClick }) {<Text as="span" mx={1}>•</Text>- <Text variant="subBody">{topic.notes.length} Notes</Text>+ <Text variant="subBody">+ {pluralize(topic.notes.length, "note", "notes")}+ </Text></Flex>}index={index}diff --git a/apps/web/src/utils/string.js b/apps/web/src/utils/string.jsindex 7aba582dd..7849c97f1 100644--- a/apps/web/src/utils/string.js+++ b/apps/web/src/utils/string.js@@ -20,3 +20,13 @@ export function countWords(str) {if (!str.length) return 0;return str.split(/\W+\S/).length;}++/**+ *+ * @param {string} count+ * @param {string} singular+ * @param {string} plural+ */+export function pluralize(count, singular, plural) {+ return !count || count > 1 ? `${count} ${plural}` : `${count} ${singular}`;+}diff --git a/apps/web/src/views/topics.js b/apps/web/src/views/topics.jsindex 00ad02bdc..ef7658db4 100644--- a/apps/web/src/views/topics.js+++ b/apps/web/src/views/topics.js@@ -9,6 +9,7 @@ import { Edit, RemoveShortcutLink, ShortcutLink } from "../components/icons";import { getTotalNotes } from "../common";import { formatDate } from "notes-core/utils/date";import { db } from "../common/db";+import { pluralize } from "../utils/string";function Topics() {const selectedNotebookTopics = useNbStore(@@ -93,8 +94,8 @@ function NotebookHeader({ notebook }) {</Text>)}<Text as="em" variant="subBody" mt={2}>- {topics.length} {topics.length > 1 ? "topics" : "topic"}, {totalNotes}{" "}- {totalNotes > 1 ? "notes" : "note"}+ {pluralize(topics.length, "topic", "topics")},{" "}+ {pluralize(totalNotes, "note", "notes")}</Text></Flex>);