Skip to content

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

web: use correct plural/singular form in toasts

Abdullah Atta5e886dc7b5e9
diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.ts
index 00014a878..ddbcfc539 100644
--- a/apps/web/src/common/multi-select.ts
+++ b/apps/web/src/common/multi-select.ts
@@ -24,8 +24,8 @@ import { store as attachmentStore } from "../stores/attachment-store";
import { db } from "./db";
import { showToast } from "../utils/toast";
import Vault from "./vault";
-import { showItemDeletedToast } from "./toasts";
import { TaskManager } from "./task-manager";
+import { pluralize } from "../utils/string";
type Item = {
id: string;
@@ -56,13 +56,16 @@ async function moveNotesToTrash(notes: Item[], confirm = true) {
id: "deleteNotes",
action: async (report) => {
report({
- text: `Deleting ${items.length} notes...`
+ text: `Deleting ${pluralize(items.length, "note", "notes")}...`
});
await noteStore.delete(...items);
}
});
- showToast("success", `${items.length} notes moved to trash`);
+ showToast(
+ "success",
+ `${pluralize(items.length, "note", "notes")} moved to trash`
+ );
}
async function moveNotebooksToTrash(notebooks: Item[]) {
@@ -79,17 +82,20 @@ async function moveNotebooksToTrash(notebooks: Item[]) {
id: "deleteNotebooks",
action: async (report) => {
report({
- text: `Deleting ${notebooks.length} notebooks...`
+ text: `Deleting ${pluralize(
+ notebooks.length,
+ "notebook",
+ "notebooks"
+ )}...`
});
await notebookStore.delete(...notebooks.map((i) => i.id));
}
});
- if (isMultiselect) {
- showToast("success", `${notebooks.length} notebooks moved to trash`);
- } else {
- showItemDeletedToast(item);
- }
+ showToast(
+ "success",
+ `${pluralize(notebooks.length, "notebook", "notebooks")} moved to trash`
+ );
}
async function deleteTopics(notebookId: string, topics: Item[]) {
@@ -98,7 +104,7 @@ async function deleteTopics(notebookId: string, topics: Item[]) {
id: "deleteTopics",
action: async (report) => {
report({
- text: `Deleting ${topics.length} topics...`
+ text: `Deleting ${pluralize(topics.length, "topic", "topics")}...`
});
await db.notebooks
?.notebook(notebookId)
@@ -107,7 +113,10 @@ async function deleteTopics(notebookId: string, topics: Item[]) {
noteStore.refresh();
}
});
- showToast("success", `${topics.length} topics deleted`);
+ showToast(
+ "success",
+ `${pluralize(topics.length, "topic", "topics")} deleted`
+ );
}
async function deleteAttachments(attachments: Item[]) {
@@ -125,7 +134,11 @@ async function deleteAttachments(attachments: Item[]) {
for (let i = 0; i < attachments.length; ++i) {
const attachment = attachments[i];
report({
- text: `Deleting ${attachments.length} attachments...`,
+ text: `Deleting ${pluralize(
+ attachments.length,
+ "attachment",
+ "attachments"
+ )}...`,
current: i,
total: attachments.length
});
@@ -133,7 +146,10 @@ async function deleteAttachments(attachments: Item[]) {
}
}
});
- showToast("success", `${attachments.length} attachments deleted`);
+ showToast(
+ "success",
+ `${pluralize(attachments.length, "attachment", "attachments")} deleted`
+ );
}
export const Multiselect = {
diff --git a/apps/web/src/components/tag/index.js b/apps/web/src/components/tag/index.js
index 2a768509b..ddac2299a 100644
--- a/apps/web/src/components/tag/index.js
+++ b/apps/web/src/components/tag/index.js
@@ -26,6 +26,7 @@ import { store as editorStore } from "../../stores/editor-store";
import { db } from "../../common/db";
import * as Icon from "../icons";
import { showToast } from "../../utils/toast";
+import { pluralize } from "../../utils/string";
const menuItems = [
{
@@ -55,7 +56,7 @@ const menuItems = [
await editorStore.clearSession();
await db.tags.remove(tag.id);
}
- showToast("success", `${items.length} tags deleted`);
+ showToast("success", `${pluralize(items.length, "tag", "tags")} deleted`);
tagStore.refresh();
},
multiSelect: true
diff --git a/apps/web/src/components/trash-item/index.js b/apps/web/src/components/trash-item/index.js
index 1ba392fa5..d3cbbb6f3 100644
--- a/apps/web/src/components/trash-item/index.js
+++ b/apps/web/src/components/trash-item/index.js
@@ -23,7 +23,7 @@ import * as Icon from "../icons";
import { store } from "../../stores/trash-store";
import { Flex, Text } from "@theme-ui/components";
import TimeAgo from "../time-ago";
-import { toTitleCase } from "../../utils/string";
+import { pluralize, toTitleCase } from "../../utils/string";
import { showUndoableToast } from "../../common/toasts";
import { showToast } from "../../utils/toast";
@@ -57,7 +57,10 @@ const menuItems = [
icon: Icon.Restore,
onClick: ({ items }) => {
store.restore(items.map((i) => i.id));
- showToast("success", `${items.length} items restored`);
+ showToast(
+ "success",
+ `${pluralize(items.length, "item", "items")} restored`
+ );
},
multiSelect: true
},
@@ -71,7 +74,7 @@ const menuItems = [
if (!(await showMultiPermanentDeleteConfirmation(items.length))) return;
const ids = items.map((i) => i.id);
showUndoableToast(
- `${items.length} items permanently deleted`,
+ `${pluralize(items.length, "item", "items")} permanently deleted`,
() => store.delete(ids),
() => store.delete(ids, true),
() => store.refresh()