Skip to content

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

mobile: fix link notebooks sheet

Ammar Ahmedcf643fe0b07e
diff --git a/apps/mobile/app/components/sheets/add-notebook/index.tsx b/apps/mobile/app/components/sheets/add-notebook/index.tsx
index 490b62449..89994779d 100644
--- a/apps/mobile/app/components/sheets/add-notebook/index.tsx
+++ b/apps/mobile/app/components/sheets/add-notebook/index.tsx
@@ -39,15 +39,18 @@ import Heading from "../../ui/typography/heading";
import { MoveNotes } from "../move-notes/movenote";
import { eOnNotebookUpdated } from "../../../utils/events";
import { getParentNotebookId } from "../../../utils/notebooks";
+import { useNotebookStore } from "../../../stores/use-notebook-store";
export const AddNotebookSheet = ({
notebook,
parentNotebook,
- close
+ close,
+ showMoveNotesOnComplete
}: {
notebook?: Notebook;
parentNotebook?: Notebook;
- close: ((context?: string | undefined) => void) | undefined;
+ close?: (didAddNotebook: boolean) => void;
+ showMoveNotesOnComplete: boolean;
}) => {
const title = useRef(notebook?.title);
const description = useRef(notebook?.description);
@@ -85,6 +88,7 @@ export const AddNotebookSheet = ({
useMenuStore.getState().setMenuPins();
Navigation.queueRoutesForUpdate();
useRelationStore.getState().update();
+ useNotebookStore.getState().refresh();
const parent =
parentNotebook?.id || (await getParentNotebookId(notebook?.id || id));
@@ -97,10 +101,10 @@ export const AddNotebookSheet = ({
});
}
- if (!notebook) {
+ if (!notebook && showMoveNotesOnComplete) {
MoveNotes.present(await db.notebooks.notebook(id));
} else {
- close?.();
+ close?.(true);
}
};
@@ -169,7 +173,8 @@ AddNotebookSheet.present = (
notebook?: Notebook,
parentNotebook?: Notebook,
context?: string,
- onClose?: () => void
+ onClose?: (didAddNotebook: boolean) => void,
+ showMoveNotesOnComplete = true
) => {
presentSheet({
context: context,
@@ -177,9 +182,12 @@ AddNotebookSheet.present = (
<AddNotebookSheet
notebook={notebook}
parentNotebook={parentNotebook}
- close={close}
+ close={(didAddNotebook: boolean) => {
+ close?.();
+ onClose?.(didAddNotebook);
+ }}
+ showMoveNotesOnComplete={showMoveNotesOnComplete || false}
/>
- ),
- onClose: onClose
+ )
});
};
diff --git a/apps/mobile/app/components/sheets/add-to/index.tsx b/apps/mobile/app/components/sheets/add-to/index.tsx
index e6d851428..935dd1cc1 100644
--- a/apps/mobile/app/components/sheets/add-to/index.tsx
+++ b/apps/mobile/app/components/sheets/add-to/index.tsx
@@ -46,6 +46,7 @@ import { IconButton } from "../../ui/icon-button";
import Paragraph from "../../ui/typography/paragraph";
import { NotebookItem } from "./notebook-item";
import { useNotebookItemSelectionStore } from "./store";
+import { AddNotebookSheet } from "../add-notebook";
async function updateInitialSelectionState(items: string[]) {
const relations = await db.relations
@@ -141,6 +142,11 @@ const MoveNoteSheet = ({
actionSheetRef.current?.hide();
};
+ const hasSelected = () => {
+ const selection = useNotebookItemSelectionStore.getState().selection;
+ return Object.keys(selection).some((key) => selection[key] === "selected");
+ };
+
const renderNotebook = useCallback(
({ index }: { item: boolean; index: number }) => (
<NotebookItem items={notebooks} id={index} index={index} />
@@ -190,18 +196,21 @@ const MoveNoteSheet = ({
columnGap: 10
}}
>
- <IconButton
- name="restore"
- type="secondaryAccented"
- onPress={() => {
- const items = note ? [note.id] : selectedItemsList;
- updateInitialSelectionState(items);
- }}
- style={{
- width: 40,
- height: 40
- }}
- />
+ {hasSelected() ? (
+ <IconButton
+ name="restore"
+ type="secondaryAccented"
+ color={colors.primary.icon}
+ onPress={() => {
+ const items = note ? [note.id] : selectedItemsList;
+ updateInitialSelectionState(items);
+ }}
+ style={{
+ width: 40,
+ height: 40
+ }}
+ />
+ ) : null}
<Button
height={40}
@@ -230,6 +239,36 @@ const MoveNoteSheet = ({
style={{
width: "100%"
}}
+ ListHeaderComponent={
+ <View
+ style={{
+ paddingHorizontal: 12,
+ width: "100%"
+ }}
+ >
+ <Button
+ title="Add new notebook"
+ style={{
+ alignSelf: "flex-start",
+ paddingHorizontal: 12,
+ justifyContent: "space-between"
+ }}
+ onPress={() => {
+ AddNotebookSheet.present(
+ undefined,
+ undefined,
+ "link-notebooks",
+ undefined,
+ false
+ );
+ }}
+ icon="plus"
+ iconPosition="right"
+ type="secondaryAccented"
+ width="100%"
+ />
+ </View>
+ }
estimatedItemSize={50}
renderItem={renderNotebook}
ListEmptyComponent={
@@ -265,7 +304,8 @@ MoveNoteSheet.present = (note?: Note) => {
presentSheet({
component: (ref) => <MoveNoteSheet actionSheetRef={ref} note={note} />,
enableGesturesInScrollView: false,
- noBottomPadding: true
+ noBottomPadding: true,
+ keyboardHandlerDisabled: true
});
};
export default MoveNoteSheet;
diff --git a/apps/mobile/app/components/sheets/add-to/notebook-item.tsx b/apps/mobile/app/components/sheets/add-to/notebook-item.tsx
index e1a3b5d8f..e0250d959 100644
--- a/apps/mobile/app/components/sheets/add-to/notebook-item.tsx
+++ b/apps/mobile/app/components/sheets/add-to/notebook-item.tsx
@@ -226,7 +226,13 @@ export const NotebookItem = ({
testID={notesnook.ids.notebook.menu}
onPress={() => {
if (!item) return;
- AddNotebookSheet.present(undefined, item, "link-notebooks");
+ AddNotebookSheet.present(
+ undefined,
+ item,
+ "link-notebooks",
+ undefined,
+ false
+ );
}}
left={0}
right={0}