Skip to content

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

mobile: remove action strip

ammarahm-ed3bca1ca7953f
diff --git a/apps/mobile/app/components/list-items/selection-wrapper/action-strip.js b/apps/mobile/app/components/list-items/selection-wrapper/action-strip.js
deleted file mode 100644
index 790f17603..000000000
--- a/apps/mobile/app/components/list-items/selection-wrapper/action-strip.js
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-import Clipboard from "@react-native-clipboard/clipboard";
-import React, { useEffect, useState } from "react";
-import { View } from "react-native";
-import Animated, { SlideInUp, SlideOutDown } from "react-native-reanimated";
-import { db } from "../../../common/database";
-import { openVault, ToastEvent } from "../../../services/event-manager";
-import Navigation from "../../../services/navigation";
-import { useMenuStore } from "../../../stores/use-menu-store";
-import { useNotebookStore } from "../../../stores/use-notebook-store";
-import { useRelationStore } from "../../../stores/use-relation-store";
-import { useSelectionStore } from "../../../stores/use-selection-store";
-import { useThemeStore } from "../../../stores/use-theme-store";
-import { useTrashStore } from "../../../stores/use-trash-store";
-import { dWidth, getElevation, toTXT } from "../../../utils";
-import { deleteItems } from "../../../utils/functions";
-import { presentDialog } from "../../dialog/functions";
-import { Button } from "../../ui/button";
-import { IconButton } from "../../ui/icon-button";
-
-export const ActionStrip = ({ note, setActionStrip }) => {
- const colors = useThemeStore((state) => state.colors);
- const selectionMode = useSelectionStore((state) => state.selectionMode);
- const setNotebooks = useNotebookStore((state) => state.setNotebooks);
- const setMenuPins = useMenuStore((state) => state.setMenuPins);
- const setSelectedItem = useSelectionStore((state) => state.setSelectedItem);
- const setSelectionMode = useSelectionStore((state) => state.setSelectionMode);
-
- const [isPinnedToMenu, setIsPinnedToMenu] = useState(false);
- const [width, setWidth] = useState(dWidth - 16);
- useEffect(() => {
- if (note.type === "note") return;
- setIsPinnedToMenu(db.shortcuts.exists(note.id));
- }, [note.id, note.type]);
-
- const updateNotes = () => {
- Navigation.queueRoutesForUpdate(
- "Notes",
- "Favorites",
- "ColoredNotes",
- "TaggedNotes",
- "TopicNotes"
- );
- };
-
- const actions = [
- {
- title: "Pin " + note.type,
- icon: note.pinned ? "pin-off" : "pin",
- visible: note.type === "note" || note.type === "notebook",
- onPress: async () => {
- if (!note.id) return;
-
- if (note.type === "note") {
- await db.notes.note(note.id).pin();
- } else {
- await db.notebooks.notebook(note.id).pin();
- setNotebooks();
- }
- updateNotes();
- setActionStrip(false);
- }
- },
- {
- title: "Add to favorites",
- icon: note.favorite ? "star-off" : "star",
- onPress: async () => {
- if (!note.id) return;
- if (note.type === "note") {
- await db.notes.note(note.id).favorite();
- } else {
- await db.notebooks.notebook(note.id).favorite();
- }
- updateNotes();
- setActionStrip(false);
- },
- visible: note.type === "note",
- color: !note.favorite ? "orange" : null
- },
-
- {
- title: isPinnedToMenu
- ? "Remove Shortcut from Menu"
- : "Add Shortcut to Menu",
- icon: isPinnedToMenu ? "link-variant-remove" : "link-variant",
- onPress: async () => {
- try {
- if (isPinnedToMenu) {
- await db.shortcuts.remove(note.id);
- ToastEvent.show({
- heading: "Shortcut removed from menu",
- type: "success"
- });
- } else {
- if (note.type === "topic") {
- await db.shortcuts.add({
- item: {
- type: "topic",
- id: note.id,
- notebookId: note.notebookId
- }
- });
- } else {
- await db.shortcuts.add({
- item: {
- type: "notebook",
- id: note.id
- }
- });
- }
- ToastEvent.show({
- heading: "Shortcut added to menu",
- type: "success"
- });
- }
- setIsPinnedToMenu(db.shortcuts.exists(note.id));
- setMenuPins();
-
- setActionStrip(false);
- } catch (e) {
- console.error(e);
- }
- },
- visible: note.type !== "note" && note.type !== "reminder"
- },
- {
- title: "Copy Note",
- icon: "content-copy",
- visible: note.type === "note",
- onPress: async () => {
- if (note.locked) {
- openVault({
- copyNote: true,
- novault: true,
- locked: true,
- item: note,
- title: "Copy note",
- description: "Unlock note to copy to clipboard."
- });
- } else {
- let text = await toTXT(note);
- text = `${note.title}\n \n ${text}`;
- Clipboard.setString(text);
- ToastEvent.show({
- heading: "Note copied to clipboard",
- type: "success"
- });
- }
- setActionStrip(false);
- }
- },
- {
- title: "Restore " + note.itemType,
- icon: "delete-restore",
- onPress: async () => {
- await db.trash.restore(note.id);
- Navigation.queueRoutesForUpdate(
- "Notes",
- "Favorites",
- "ColoredNotes",
- "TaggedNotes",
- "TopicNotes",
- "Trash",
- "Notebooks"
- );
-
- ToastEvent.show({
- heading:
- note.type === "note"
- ? "Note restored from trash"
- : "Notebook restored from trash",
- type: "success"
- });
-
- setActionStrip(false);
- },
- visible: note.type === "trash"
- },
- {
- title: "Delete" + note.itemType,
- icon: "delete",
- visible: note.type === "trash",
- onPress: () => {
- presentDialog({
- title: "Permanent delete",
- paragraph: `Are you sure you want to delete this ${note.itemType} permanantly from trash?`,
- positiveText: "Delete",
- negativeText: "Cancel",
- positivePress: async () => {
- await db.trash.delete(note.id);
- useTrashStore.getState().setTrash();
- useSelectionStore.getState().setSelectionMode(false);
- ToastEvent.show({
- heading: "Permanantly deleted items",
- type: "success",
- context: "local"
- });
- },
- positiveType: "errorShade"
- });
- setActionStrip(false);
- }
- },
- {
- title: "Delete" + note.type,
- icon: "delete",
- visible: note.type !== "trash",
- onPress: async () => {
- if (note.type === "reminder") {
- presentDialog({
- title: `Delete ${note.type}`,
- paragraph: "This reminder will be removed",
- positivePress: async () => {
- const routes = [];
- await db.reminders.remove(note.id);
- routes.push("Reminders");
- Navigation.queueRoutesForUpdate(...routes);
- useRelationStore.getState().update();
- },
- positiveText: "Delete",
- positiveType: "errorShade"
- });
- return;
- }
- try {
- await deleteItems(note);
- } catch (e) {
- console.error(e);
- }
- setActionStrip(false);
- }
- },
- {
- title: "Close",
- icon: "close",
- onPress: () => setActionStrip(false),
- color: colors.light,
- bg: colors.red,
- visible: true
- }
- ];
-
- return (
- <Animated.View
- onLayout={(event) => {
- setWidth(event.nativeEvent.layout.width);
- }}
- entering={SlideInUp.springify().mass(0.4)}
- exiting={SlideOutDown}
- style={{
- position: "absolute",
- zIndex: 999,
- width: "102%",
- height: "100%",
- flexDirection: "row",
- justifyContent: "flex-end",
- alignItems: "center"
- }}
- >
- <Button
- type="accent"
- title="Select"
- icon="check"
- tooltipText="Select Item"
- onPress={() => {
- if (!selectionMode) {
- setSelectionMode(true);
- }
- setSelectedItem(note);
- setActionStrip(false);
- }}
- style={{
- borderRadius: 100,
- paddingHorizontal: 12,
- ...getElevation(5)
- }}
- height={30}
- />
- {actions.map((item) =>
- item.visible ? (
- <View
- key={item.icon}
- style={{
- width: width / 1.4 / actions.length,
- height: width / 1.4 / actions.length,
- backgroundColor: item.bg || colors.nav,
- borderRadius: 100,
- justifyContent: "center",
- alignItems: "center",
- ...getElevation(5),
- marginLeft: 15
- }}
- >
- <IconButton
- color={item.color || colors.heading}
- onPress={item.onPress}
- tooltipText={item.title}
- top={60}
- bottom={60}
- name={item.icon}
- size={width / 2.8 / actions.length}
- />
- </View>
- ) : null
- )}
- </Animated.View>
- );
-};
diff --git a/apps/mobile/app/components/list-items/selection-wrapper/index.js b/apps/mobile/app/components/list-items/selection-wrapper/index.js
index 832ea5e89..978254655 100644
--- a/apps/mobile/app/components/list-items/selection-wrapper/index.js
+++ b/apps/mobile/app/components/list-items/selection-wrapper/index.js
@@ -17,19 +17,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import React, { useEffect, useState } from "react";
-import {
- eSubscribeEvent,
- eUnSubscribeEvent
-} from "../../../services/event-manager";
+import React, { useRef } from "react";
+import { useSelectionStore } from "../../../stores/use-selection-store";
import { useSettingStore } from "../../../stores/use-setting-store";
import { useThemeStore } from "../../../stores/use-theme-store";
-import { history } from "../../../utils";
import { PressableButton } from "../../ui/pressable";
-import { ActionStrip } from "./action-strip";
import { Filler } from "./back-fill";
import { SelectionIcon } from "./selection";
-import { useRef } from "react";
const SelectionWrapper = ({
children,
@@ -42,7 +36,6 @@ const SelectionWrapper = ({
}) => {
const itemId = useRef(item.id);
const colors = useThemeStore((state) => state.colors);
- const [actionStrip, setActionStrip] = useState(false);
const notebooksListMode = useSettingStore(
(state) => state.settings.notebooksListMode
);
@@ -56,35 +49,18 @@ const SelectionWrapper = ({
if (item.id !== itemId.current) {
itemId.current = item.id;
- if (actionStrip) {
- setActionStrip(false);
- }
}
const _onLongPress = () => {
- if (history.selectedItemsList.length > 0) return;
- setActionStrip(!actionStrip);
+ if (!useSelectionStore.getState().selectionMode) {
+ useSelectionStore.getState().setSelectionMode(true);
+ }
+ useSelectionStore.getState().setSelectedItem(item);
};
const _onPress = async () => {
- if (actionStrip) {
- setActionStrip(false);
- return;
- }
await onPress();
};
-
- const closeStrip = () => {
- setActionStrip(false);
- };
-
- useEffect(() => {
- eSubscribeEvent("navigate", closeStrip);
-
- return () => {
- eUnSubscribeEvent("navigate", closeStrip);
- };
- }, []);
return (
<PressableButton
customColor={isSheet ? colors.transGray : "transparent"}
@@ -111,15 +87,10 @@ const SelectionWrapper = ({
) : null}
<SelectionIcon
compactMode={compactMode}
- setActionStrip={setActionStrip}
item={item}
onLongPress={onLongPress}
/>
{children}
-
- {actionStrip ? (
- <ActionStrip note={item} setActionStrip={setActionStrip} />
- ) : null}
</PressableButton>
);
};
diff --git a/apps/mobile/app/components/list-items/selection-wrapper/selection.js b/apps/mobile/app/components/list-items/selection-wrapper/selection.js
index 09dcc2874..6328cd1ad 100644
--- a/apps/mobile/app/components/list-items/selection-wrapper/selection.js
+++ b/apps/mobile/app/components/list-items/selection-wrapper/selection.js
@@ -24,7 +24,7 @@ import { useSelectionStore } from "../../../stores/use-selection-store";
import { useThemeStore } from "../../../stores/use-theme-store";
import { SIZE } from "../../../utils/size";
-export const SelectionIcon = ({ setActionStrip, item }) => {
+export const SelectionIcon = ({ item }) => {
const colors = useThemeStore((state) => state.colors);
const selectionMode = useSelectionStore((state) => state.selectionMode);
@@ -35,7 +35,6 @@ export const SelectionIcon = ({ setActionStrip, item }) => {
useEffect(() => {
if (selectionMode) {
- setActionStrip(false);
let exists = selectedItemsList.filter(
(o) => o.dateCreated === item.dateCreated
);
@@ -50,16 +49,9 @@ export const SelectionIcon = ({ setActionStrip, item }) => {
}
}
}
- }, [
- selectedItemsList,
- item.id,
- selectionMode,
- setActionStrip,
- item.dateCreated,
- selected
- ]);
+ }, [selectedItemsList, item.id, selectionMode, item.dateCreated, selected]);
- return selectionMode && selected ? (
+ return selectionMode ? (
<View
style={{
width: 40,
@@ -73,11 +65,13 @@ export const SelectionIcon = ({ setActionStrip, item }) => {
}}
pointerEvents="none"
>
- <Icon
- size={SIZE.xl}
- color={selected ? colors.accent : colors.icon}
- name="check"
- />
+ {selected ? (
+ <Icon
+ size={SIZE.xl}
+ color={selected ? colors.accent : colors.icon}
+ name={"check"}
+ />
+ ) : null}
</View>
) : null;
};