Skip to content

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

feat: improve multi select

thecodrr35cf111b3994
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
index 3de7b6927..2095ba7a8 100644
--- a/apps/web/src/common/dialogcontroller.js
+++ b/apps/web/src/common/dialogcontroller.js
@@ -121,21 +121,37 @@ export function confirm(
));
}
-export function showMultiDeleteConfirmation(type) {
- let noun = type === "note" ? "notes" : "notebooks";
-
+export function showMultiDeleteConfirmation(length, permanentDelete) {
return confirm(Icon.Trash, {
- title: `Delete these ${noun}?`,
+ title: `Delete ${length} items?`,
message: (
<Text as="span">
- These {type}s will be{" "}
+ These items will be{" "}
<Text as="span" color="primary">
kept in your Trash for 7 days
</Text>{" "}
after which they will be permanently removed.
</Text>
),
- yesText: `Delete these ${type}s`,
+ yesText: `Delete selected`,
+ noText: "Cancel",
+ });
+}
+
+export function showMultiPermanentDeleteConfirmation(length) {
+ return confirm(Icon.Trash, {
+ title: `Permanently delete ${length} items?`,
+ message: (
+ <Text as="span">
+ These items will be{" "}
+ <Text as="span" color="primary">
+ permanently deleted
+ </Text>
+ {". "}
+ This action is IRREVERSIBLE.
+ </Text>
+ ),
+ yesText: `Permanently delete selected`,
noText: "Cancel",
});
}
diff --git a/apps/web/src/common/selectionoptions.js b/apps/web/src/common/selectionoptions.js
index 19a972e3b..86f66487f 100644
--- a/apps/web/src/common/selectionoptions.js
+++ b/apps/web/src/common/selectionoptions.js
@@ -3,20 +3,26 @@ import { store as selectionStore } from "../stores/selection-store";
import { store as notesStore } from "../stores/note-store";
import { store as nbStore } from "../stores/notebook-store";
import { store as editorStore } from "../stores/editor-store";
+import { store as appStore } from "../stores/app-store";
import { store as trashStore } from "../stores/trash-store";
import { db } from "./db";
import { showMoveNoteDialog } from "../common/dialog-controller";
-import { showMultiDeleteConfirmation } from "../common/dialog-controller";
+import {
+ showMultiDeleteConfirmation,
+ showMultiPermanentDeleteConfirmation,
+} from "../common/dialog-controller";
import { showExportDialog } from "../common/dialog-controller";
import { showToast } from "../utils/toast";
-function createOption(key, icon, onClick) {
+function createOption(key, title, icon, onClick) {
return {
key,
icon,
+ title,
onClick: async () => {
await onClick.call(this, selectionStore.get());
selectionStore.toggleSelectionMode(false);
+ appStore.setProcessingStatus();
},
};
}
@@ -27,11 +33,20 @@ function createOptions(options = []) {
const DeleteOption = createOption(
"deleteOption",
+ "Delete",
Icon.Trash,
async function (state) {
const item = state.selectedItems[0];
- if (!(await showMultiDeleteConfirmation(item.itemType))) return;
+ const confirmDialog = item.dateDeleted
+ ? showMultiPermanentDeleteConfirmation
+ : showMultiDeleteConfirmation;
+ if (!(await confirmDialog(state.selectedItems.length))) return;
+
+ const statusText = `${
+ item.dateDeleted ? `Permanently deleting` : `Deleting`
+ } ${state.selectedItems.length} items...`;
+ appStore.setProcessingStatus(statusText);
var isAnyNoteOpened = false;
const items = state.selectedItems.map((item) => {
@@ -44,6 +59,7 @@ const DeleteOption = createOption(
// we are in trash
await db.trash.delete(...items);
trashStore.refresh();
+ showToast("success", `${items.length} items permanently deleted!`);
return;
}
@@ -53,22 +69,26 @@ const DeleteOption = createOption(
if (item.type === "note") {
await db.notes.delete(...items);
- notesStore.refresh();
} else if (item.type === "notebook") {
await db.notebooks.delete(...items);
- nbStore.refresh();
} else if (item.type === "topic") {
await db.notebooks.notebook(item.notebookId).topics.delete(...items);
nbStore.setSelectedNotebook(item.notebookId);
}
+ appStore.refresh();
showToast("success", `${items.length} ${item.type}s moved to trash!`);
}
);
const UnfavoriteOption = createOption(
"unfavoriteOption",
+ "Unfavorite",
Icon.Star,
function (state) {
+ appStore.setProcessingStatus(
+ `Unfavoriting ${state.selectedItems.length} notes...`
+ );
+
// we know only notes can be favorited
state.selectedItems.forEach(async (item) => {
if (!item.favorite) return;
@@ -80,8 +100,13 @@ const UnfavoriteOption = createOption(
const AddToNotebookOption = createOption(
"atnOption",
+ "Add to notebook(s)",
Icon.AddToNotebook,
async function (state) {
+ appStore.setProcessingStatus(
+ `Adding ${state.selectedItems.length} notes to notebooks...`
+ );
+
const items = state.selectedItems.map((item) => item.id);
await showMoveNoteDialog(items);
showToast("success", `${items.length} notes moved!`);
@@ -90,8 +115,13 @@ const AddToNotebookOption = createOption(
const ExportOption = createOption(
"exportOption",
+ "Export",
Icon.Export,
async function (state) {
+ appStore.setProcessingStatus(
+ `Exporting ${state.selectedItems.length} notes...`
+ );
+
const items = state.selectedItems.map((item) => item.id);
if (await showExportDialog(items)) {
await showToast("success", `${items.length} notes exported!`);
@@ -101,11 +131,16 @@ const ExportOption = createOption(
const RestoreOption = createOption(
"restoreOption",
+ "Restore",
Icon.Restore,
async function (state) {
+ appStore.setProcessingStatus(
+ `Restoring ${state.selectedItems.length} items...`
+ );
+
const items = state.selectedItems.map((item) => item.id);
await db.trash.restore(...items);
- trashStore.refresh();
+ appStore.refresh();
showToast("success", `${items.length} items restored!`);
}
);
diff --git a/apps/web/src/components/cached-router/index.js b/apps/web/src/components/cached-router/index.js
index 4d7e3f77e..e2797c65d 100644
--- a/apps/web/src/components/cached-router/index.js
+++ b/apps/web/src/components/cached-router/index.js
@@ -12,6 +12,7 @@ function CachedRouter() {
useEffect(() => {
if (!RouteResult) return;
NavigationEvents.publish("onNavigate", RouteResult);
+ window.currentViewType = RouteResult.type;
const key = RouteResult.key || "general";
diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.js
index 012f05611..9a3968a2a 100644
--- a/apps/web/src/components/list-container/index.js
+++ b/apps/web/src/components/list-container/index.js
@@ -26,7 +26,9 @@ function ListContainer(props) {
const listRef = useRef();
useEffect(() => {
- if (shouldSelectAll) setSelectedItems(props.items);
+ if (!props.items.length) return;
+ if (shouldSelectAll)
+ setSelectedItems(props.items.filter((item) => item.type !== "header"));
}, [shouldSelectAll, setSelectedItems, props.items]);
useEffect(() => {
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index fb3cf1255..fce8c451d 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -6,6 +6,7 @@ import {
useStore as useSelectionStore,
} from "../../stores/selection-store";
import { useOpenContextMenu } from "../../utils/useContextMenu";
+import { SELECTION_OPTIONS_MAP } from "../../common";
function selectMenuItem(isSelected, toggleSelection) {
return {
@@ -85,10 +86,28 @@ function ListItem(props) {
const menuItems = useMemo(() => {
let items = props.menu?.items;
if (!items) return [];
+
+ if (isSelectionMode) {
+ const options = SELECTION_OPTIONS_MAP[window.currentViewType];
+ items = options.map((option) => {
+ return {
+ key: option.key,
+ title: () => option.title,
+ icon: option.icon,
+ onClick: option.onClick,
+ };
+ });
+ }
if (props.selectable)
items = [selectMenuItem(isSelected, toggleSelection), ...items];
return items;
- }, [props.menu?.items, isSelected, toggleSelection, props.selectable]);
+ }, [
+ props.menu?.items,
+ isSelected,
+ isSelectionMode,
+ toggleSelection,
+ props.selectable,
+ ]);
useEffect(() => {
if (!isSelectionMode && isSelected) toggleSelection();
diff --git a/apps/web/src/components/route-container/index.js b/apps/web/src/components/route-container/index.js
index 79d147863..69404f019 100644
--- a/apps/web/src/components/route-container/index.js
+++ b/apps/web/src/components/route-container/index.js
@@ -1,5 +1,5 @@
import React from "react";
-import { Box, Flex, Text } from "rebass";
+import { Flex, Text } from "rebass";
import * as Icon from "../icons";
import { useStore } from "../../stores/app-store";
import { useStore as useSelectionStore } from "../../stores/selection-store";
@@ -25,6 +25,11 @@ function Header(props) {
const toggleSideMenu = useStore((store) => store.toggleSideMenu);
const isMobile = useMobile();
const isSelectionMode = useSelectionStore((store) => store.isSelectionMode);
+ const selectAll = useSelectionStore((store) => store.selectAll);
+ const shouldSelectAll = useSelectionStore((store) => store.shouldSelectAll);
+ const toggleSelectionMode = useSelectionStore(
+ (store) => store.toggleSelectionMode
+ );
if (!title && !subtitle) return null;
return (
@@ -100,6 +105,24 @@ function Header(props) {
{subtitle}
</Text>
)}
+ {isSelectionMode && (
+ <Flex
+ mb={2}
+ sx={{
+ cursor: "pointer",
+ }}
+ alignItems="center"
+ onClick={() => {
+ if (shouldSelectAll) toggleSelectionMode(false);
+ else selectAll();
+ }}
+ >
+ <Icon.Select size={16} sx={{ mr: 1 }} />
+ <Text variant="body">
+ {shouldSelectAll ? "Unselect all" : "Select all"}
+ </Text>
+ </Flex>
+ )}
</Flex>
);
}
@@ -113,14 +136,13 @@ function SelectionOptions(props) {
return (
<Flex>
{options.map((option) => (
- <Box
+ <option.icon
+ title={option.title}
+ size={20}
key={option.key}
onClick={option.onClick}
- mx={2}
- sx={{ cursor: "pointer" }}
- >
- <option.icon size={20} />
- </Box>
+ sx={{ cursor: "pointer", mx: 2 }}
+ />
))}
</Flex>
);
diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.js
index 82a8a225d..ae336a2dd 100644
--- a/apps/web/src/components/status-bar/index.js
+++ b/apps/web/src/components/status-bar/index.js
@@ -14,6 +14,7 @@ function StatusBar() {
const lastSynced = useAppStore((state) => state.lastSynced);
const isLoggedIn = useUserStore((state) => state.isLoggedIn);
const isSyncing = useAppStore((state) => state.isSyncing);
+ const processingStatus = useAppStore((state) => state.processingStatus);
return (
<Flex
@@ -74,6 +75,14 @@ function StatusBar() {
</Text>
</Button>
)}
+ {processingStatus && (
+ <Flex ml={1} alignItems="center" justifyContent="center">
+ <Icon.Loading size={12} />
+ <Text variant="subBody" ml={1}>
+ {processingStatus}
+ </Text>
+ </Flex>
+ )}
</Flex>
<EditorFooter />
</Flex>
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 1ad05afb8..fa8268986 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -17,6 +17,7 @@ class AppStore extends BaseStore {
isFocusMode = false;
isEditorOpen = false;
isVaultCreated = false;
+ processingStatus = undefined;
colors = [];
globalMenu = { items: [], data: {} };
reminders = [];
@@ -66,6 +67,10 @@ class AppStore extends BaseStore {
this.set((state) => (state.isVaultCreated = toggleState));
};
+ setProcessingStatus = (status) => {
+ this.set((state) => (state.processingStatus = status));
+ };
+
/**
*
* @param {"backup"|"signup"|"email"|"recoverykey"} type
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 8d6f36eae..af6f8f9fe 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -9190,9 +9190,21 @@ normalize-url@^4.1.0:
resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz"
integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==
+notes-core@../notes-core:
+ version "6.7.2"
+ dependencies:
+ "@stablelib/blake2s" "^1.0.1"
+ fast-sort "^2.0.1"
+ lean-he "^2.1.2"
+ no-internet "^1.5.2"
+ qclone "^1.0.4"
+ quill-delta-to-html "^0.12.0"
+ showdown "https://github.com/thecodrr/showdown"
+ spark-md5 "^3.0.1"
+
"notes-core@git+https://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:[email protected]/streetwriters/notesnook-core.git":
- version "6.7.1"
- resolved "git+https://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:[email protected]/streetwriters/notesnook-core.git#1f2014ac9717a7bf8a0dab41199f71671247af07"
+ version "6.7.2"
+ resolved "git+https://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:[email protected]/streetwriters/notesnook-core.git#9e4c529dd23fdcba51048fca349229c0a13cbb0b"
dependencies:
"@stablelib/blake2s" "^1.0.1"
fast-sort "^2.0.1"