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: multi select causing crash
thecodrr0040fd565062
diff --git a/apps/web/src/common/selectionoptions.js b/apps/web/src/common/selectionoptions.jsindex d25b8d7c3..05a20a5c7 100644--- a/apps/web/src/common/selectionoptions.js+++ b/apps/web/src/common/selectionoptions.js@@ -8,8 +8,9 @@ import { db } from "./index";import { showMoveNoteDialog } from "../components/dialogs/movenotedialog";import { confirm } from "../components/dialogs/confirm";-function createOption(icon, onClick) {+function createOption(key, icon, onClick) {return {+ key,icon,onClick: async () => {await onClick.call(this, selectionStore);@@ -22,7 +23,9 @@ function createOptions(options = []) {return [...options, DeleteOption];}-const DeleteOption = createOption(Icon.Trash, async function (state) {+const DeleteOption = createOption("deleteOption", Icon.Trash, async function (+ state+) {if (!(await confirm(Icon.Trash, "Delete", "Are you sure you want to proceed?")))@@ -52,7 +55,9 @@ const DeleteOption = createOption(Icon.Trash, async function (state) {}});-const FavoriteOption = createOption(Icon.Star, function (state) {+const FavoriteOption = createOption("favoriteOption", Icon.Star, function (+ state+) {// we know only notes can be favoritedstate.selectedItems.forEach(async (item) => {if (item.favorite) return;@@ -61,7 +66,9 @@ const FavoriteOption = createOption(Icon.Star, function (state) {notesStore.refresh();});-const UnfavoriteOption = createOption(Icon.Star, function (state) {+const UnfavoriteOption = createOption("unfavoriteOption", Icon.Star, function (+ state+) {// we know only notes can be favoritedstate.selectedItems.forEach(async (item) => {if (!item.favorite) return;@@ -70,19 +77,27 @@ const UnfavoriteOption = createOption(Icon.Star, function (state) {notesStore.setContext({ type: "favorites" });});-const AddToNotebookOption = createOption(Icon.Plus, async function (state) {- const items = state.selectedItems.map((item) => item.id);- if (await showMoveNoteDialog(items)) {- //TODO show proper snack- console.log("Notes moved successfully!");+const AddToNotebookOption = createOption(+ "atnOption",+ Icon.Plus,+ async function (state) {+ const items = state.selectedItems.map((item) => item.id);+ if (await showMoveNoteDialog(items)) {+ //TODO show proper snack+ console.log("Notes moved successfully!");+ }}-});+);-const RestoreOption = createOption(Icon.Restore, async function (state) {- const items = state.selectedItems.map((item) => item.id);- await db.trash.restore(...items);- trashStore.refresh();-});+const RestoreOption = createOption(+ "restoreOption",+ Icon.Restore,+ async function (state) {+ const items = state.selectedItems.map((item) => item.id);+ await db.trash.restore(...items);+ trashStore.refresh();+ }+);const NotesOptions = createOptions([AddToNotebookOption, FavoriteOption]);const NotebooksOptions = createOptions();diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.jsindex 1a2533c3b..729dd820a 100644--- a/apps/web/src/components/list-container/index.js+++ b/apps/web/src/components/list-container/index.js@@ -15,6 +15,7 @@ function ListContainer(props) {useEffect(() => {if (shouldSelectAll) setSelectedItems(props.items);}, [shouldSelectAll, setSelectedItems, props.items]);+useEffect(() => {if (props.noSearch) return;setSearchContext({diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.jsindex 2c0e55749..786a9db4c 100644--- a/apps/web/src/components/list-item/index.js+++ b/apps/web/src/components/list-item/index.js@@ -4,7 +4,7 @@ import { Flex, Box, Text } from "rebass";import * as Icon from "../icons";import Menu from "../menu";import {- store as appStore,+ store as selectionStore,useStore as useSelectionStore,} from "../../stores/selection-store";import useContextMenu from "../../utils/useContextMenu";@@ -13,9 +13,9 @@ function selectMenuItem(isSelected, toggleSelection) {return {title: isSelected ? "Unselect" : "Select",onClick: () => {- const appState = appStore;- if (!appState.isSelectionMode) {- appState.enterSelectionMode();+ const selectionState = selectionStore.get();+ if (!selectionState.isSelectionMode) {+ selectionState.toggleSelectionMode();toggleSelection();} else {toggleSelection();diff --git a/apps/web/src/navigation/route.js b/apps/web/src/navigation/route.jsindex 8f1342dae..82ba5c1d1 100644--- a/apps/web/src/navigation/route.js+++ b/apps/web/src/navigation/route.js@@ -3,12 +3,16 @@ import { Box, Flex, Heading, Text } from "rebass";import * as Icon from "../components/icons";import ThemeProvider from "../components/theme-provider";import { useStore } from "../stores/app-store";+import { useStore as useSelectionStore } from "../stores/selection-store";function Route(props) {const toggleSideMenu = useStore((store) => store.toggleSideMenu);- const isSelectionMode = useStore((store) => store.isSelectionMode);- const exitSelectionMode = useStore((store) => store.exitSelectionMode);- const selectAll = useStore((store) => store.selectAll);+ const isSelectionMode = useSelectionStore((store) => store.isSelectionMode);+ const toggleSelectionMode = useSelectionStore(+ (store) => store.toggleSelectionMode+ );+ const selectAll = useSelectionStore((store) => store.selectAll);+ const shouldSelectAll = useSelectionStore((store) => store.shouldSelectAll);const navigator = props.params.navigator || props.navigator;return (<ThemeProvider>@@ -48,7 +52,7 @@ function Route(props) {<Flex>{props.route.options.map((option) => (<Box- key={option.icon.name}+ key={option.key}onClick={option.onClick}mx={2}sx={{ cursor: "pointer" }}@@ -72,21 +76,21 @@ function Route(props) {</Text>)}{isSelectionMode && (- <Flex alignItems="center" mb={2} sx={{ cursor: "pointer" }}>- <Text- variant="title"- color="primary"- onClick={() => selectAll()}- >- Select all- </Text>- <Text- ml={2}- variant="title"- color="primary"- onClick={() => exitSelectionMode()}- >- Unselect+ <Flex+ alignItems="center"+ mb={2}+ sx={{ cursor: "pointer" }}+ onClick={() => {+ if (shouldSelectAll) {+ toggleSelectionMode(false);+ } else {+ selectAll();+ }+ }}+ >+ {shouldSelectAll ? <Icon.Check /> : <Icon.CircleEmpty />}+ <Text ml={1} variant="title" color="primary">+ {shouldSelectAll ? "Unselect" : "Select all"}</Text></Flex>)}diff --git a/apps/web/src/stores/selection-store.js b/apps/web/src/stores/selection-store.jsindex 4bedaef05..476cf7576 100644--- a/apps/web/src/stores/selection-store.js+++ b/apps/web/src/stores/selection-store.js@@ -30,14 +30,14 @@ class SelectionStore extends BaseStore {}};- setSelectedItems(items) {+ setSelectedItems = (items) => {this.set((state) => (state.selectedItems = items));- }+ };- selectAll() {+ selectAll = () => {if (!this.get().isSelectionMode) return;this.set((state) => (state.shouldSelectAll = true));- }+ };}/**