Skip to content

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

mobile: make adding notebook a dialog

Ammar Ahmed2dde6b6150be
diff --git a/apps/mobile/app/components/attachments/actions.tsx b/apps/mobile/app/components/attachments/actions.tsx
index 39f6bb26a..6c9afd3da 100644
--- a/apps/mobile/app/components/attachments/actions.tsx
+++ b/apps/mobile/app/components/attachments/actions.tsx
@@ -167,6 +167,7 @@ const Actions = ({
setAttachments();
eSendEvent(eDBItemUpdate, attachment.id);
}
+ return true;
},
positiveText: strings.rename()
});
diff --git a/apps/mobile/app/components/dialog/dialog-buttons.js b/apps/mobile/app/components/dialog/dialog-buttons.tsx
similarity index 92%
rename from apps/mobile/app/components/dialog/dialog-buttons.js
rename to apps/mobile/app/components/dialog/dialog-buttons.tsx
index b60b6e167..fd055abfd 100644
--- a/apps/mobile/app/components/dialog/dialog-buttons.js
+++ b/apps/mobile/app/components/dialog/dialog-buttons.tsx
@@ -26,7 +26,7 @@ import { notesnook } from "../../../e2e/test.ids";
import { getColorLinearShade } from "../../utils/colors";
import { AppFontSize } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
-import { Button } from "../ui/button";
+import { Button, ButtonProps } from "../ui/button";
import Paragraph from "../ui/typography/paragraph";
const DialogButtons = ({
@@ -37,6 +37,14 @@ const DialogButtons = ({
loading,
doneText,
positiveType
+}: {
+ onPressPositive?: () => void;
+ onPressNegative: () => void;
+ positiveTitle: string;
+ negativeTitle?: string;
+ loading?: boolean;
+ doneText?: string;
+ positiveType?: ButtonProps["type"];
}) => {
const { colors, isDark } = useThemeColors();
diff --git a/apps/mobile/app/components/dialog/functions.ts b/apps/mobile/app/components/dialog/functions.ts
index a662de6a4..af6afd5e3 100644
--- a/apps/mobile/app/components/dialog/functions.ts
+++ b/apps/mobile/app/components/dialog/functions.ts
@@ -17,15 +17,17 @@ 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 { KeyboardTypeOptions } from "react-native";
import { eSendEvent } from "../../services/event-manager";
import { eCloseSimpleDialog, eOpenSimpleDialog } from "../../utils/events";
+import { ButtonProps } from "../ui/button";
-type DialogInfo = {
+export type DialogInfo = {
title?: string;
paragraph?: string;
- positiveText?: string;
- negativeText?: string;
- positivePress?: (...args: any[]) => void;
+ positiveText: string;
+ negativeText: string;
+ positivePress?: (...args: any[]) => Promise<any>;
onClose?: () => void;
positiveType?:
| "transparent"
@@ -44,16 +46,18 @@ type DialogInfo = {
// eslint-disable-next-line @typescript-eslint/ban-types
context: "global" | "local" | (string & {});
secureTextEntry?: boolean;
- keyboardType?: string;
+ keyboardType?: KeyboardTypeOptions;
check?: {
info: string;
- type?: string;
+ type?: ButtonProps["type"];
defaultValue?: boolean;
};
notice: {
text: string;
type: "alert" | "information";
};
+ disableBackdropClosing: boolean;
+ component: JSX.Element | ((close?: () => void) => JSX.Element);
};
export function presentDialog(data: Partial<DialogInfo>): void {
diff --git a/apps/mobile/app/components/dialog/index.js b/apps/mobile/app/components/dialog/index.tsx
similarity index 52%
rename from apps/mobile/app/components/dialog/index.js
rename to apps/mobile/app/components/dialog/index.tsx
index 3f7cfae2a..1ccfbdeef 100644
--- a/apps/mobile/app/components/dialog/index.js
+++ b/apps/mobile/app/components/dialog/index.tsx
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import React, { useCallback, useEffect, useRef, useState } from "react";
-import { View } from "react-native";
+import { TextInput, View, ViewStyle } from "react-native";
import { DDS } from "../../services/device-detection";
import {
eSubscribeEvent,
@@ -40,42 +40,26 @@ import Seperator from "../ui/seperator";
import BaseDialog from "./base-dialog";
import DialogButtons from "./dialog-buttons";
import DialogHeader from "./dialog-header";
+import { DialogInfo } from "./functions";
-export const Dialog = ({ context = "global" }) => {
+export const Dialog = ({ context = "global" }: { context?: string }) => {
const { colors } = useThemeColors();
- const [visible, setVisible] = useState(false);
- const [checked, setChecked] = useState(false);
- const [loading, setLoading] = useState(false);
- const values = useRef({
+ const [visible, setVisible] = useState<boolean>();
+ const [checked, setChecked] = useState<boolean>();
+ const [loading, setLoading] = useState<boolean>();
+ const values = useRef<{
+ inputValue?: string;
+ }>({
inputValue: undefined
});
- const inputRef = useRef();
- const [dialogInfo, setDialogInfo] = useState({
- title: "",
- paragraph: "",
- positiveText: strings.done(),
- negativeText: strings.cancel(),
- positivePress: () => {},
- onClose: () => {},
- positiveType: "transparent",
- icon: null,
- paragraphColor: colors.primary.paragraph,
- input: false,
- inputPlaceholder: "Enter some text",
- defaultValue: "",
- disableBackdropClosing: false,
- check: {
- info: "Check",
- type: "transparent",
- defaultValue: false
- }
- });
+ const inputRef = useRef<TextInput>(null);
+ const [dialogInfo, setDialogInfo] = useState<DialogInfo>();
const onPressPositive = async () => {
- if (dialogInfo.positivePress) {
+ if (dialogInfo?.positivePress) {
inputRef.current?.blur();
setLoading(true);
- let result;
+ let result = false;
try {
result = await dialogInfo.positivePress(
values.current.inputValue || dialogInfo.defaultValue,
@@ -97,7 +81,7 @@ export const Dialog = ({ context = "global" }) => {
};
const show = useCallback(
- (data) => {
+ (data: DialogInfo) => {
if (!data.context) data.context = "global";
if (data.context !== context) return;
setDialogInfo(data);
@@ -108,6 +92,14 @@ export const Dialog = ({ context = "global" }) => {
[context]
);
+ const hide = React.useCallback(() => {
+ setChecked(false);
+ values.current.inputValue = undefined;
+ setVisible(false);
+ setDialogInfo(undefined);
+ dialogInfo?.onClose?.();
+ }, [dialogInfo]);
+
useEffect(() => {
eSubscribeEvent(eOpenSimpleDialog, show);
eSubscribeEvent(eCloseSimpleDialog, hide);
@@ -118,21 +110,14 @@ export const Dialog = ({ context = "global" }) => {
};
}, [hide, show]);
- const hide = React.useCallback(() => {
- setChecked(false);
- values.current.inputValue = undefined;
- setVisible(false);
- dialogInfo.onClose?.();
- }, [dialogInfo]);
-
const onNegativePress = async () => {
- if (dialogInfo.onClose) {
+ if (dialogInfo?.onClose) {
await dialogInfo.onClose();
}
hide();
};
- const style = {
+ const style: ViewStyle = {
...getElevationStyle(5),
width: DDS.isTab ? 400 : "85%",
maxHeight: 450,
@@ -143,7 +128,7 @@ export const Dialog = ({ context = "global" }) => {
overflow: "hidden"
};
- return visible ? (
+ return visible && dialogInfo ? (
<BaseDialog
statusBarTranslucent={false}
bounce={!dialogInfo.input}
@@ -160,89 +145,99 @@ export const Dialog = ({ context = "global" }) => {
visible={true}
onRequestClose={hide}
>
- <View style={style}>
- <DialogHeader
- title={dialogInfo.title}
- icon={dialogInfo.icon}
- paragraph={dialogInfo.paragraph}
- paragraphColor={dialogInfo.paragraphColor}
- padding={12}
- style={{
- minHeight: 0
- }}
- />
- <Seperator half />
-
- {dialogInfo.input ? (
- <View
+ {typeof dialogInfo.component === "function"
+ ? dialogInfo.component(() => hide())
+ : dialogInfo.component}
+
+ {dialogInfo.component ? null : (
+ <View style={style}>
+ <DialogHeader
+ title={dialogInfo.title}
+ icon={dialogInfo.icon}
+ paragraph={dialogInfo.paragraph}
+ paragraphColor={dialogInfo.paragraphColor}
+ padding={12}
style={{
- paddingHorizontal: DefaultAppStyles.GAP
+ minHeight: 0
}}
- >
- <Input
- fwdRef={inputRef}
- autoCapitalize="none"
- onChangeText={(value) => {
- values.current.inputValue = value;
- }}
- testID="input-value"
- secureTextEntry={dialogInfo.secureTextEntry}
- //defaultValue={dialogInfo.defaultValue}
- onSubmit={onPressPositive}
- returnKeyLabel="Done"
- returnKeyType="done"
- keyboardType={dialogInfo.keyboardType || "default"}
- placeholder={dialogInfo.inputPlaceholder}
- />
- </View>
- ) : null}
-
- {dialogInfo?.notice ? (
- <View
- style={{
- paddingHorizontal: DefaultAppStyles.GAP
- }}
- >
- <Notice
- type={dialogInfo.notice.type || "information"}
- text={dialogInfo.notice.text}
- />
- </View>
- ) : null}
-
- {dialogInfo.check ? (
- <>
- <Button
- onPress={() => {
- setChecked(!checked);
+ />
+ <Seperator half />
+
+ {dialogInfo.input ? (
+ <View
+ style={{
+ paddingHorizontal: DefaultAppStyles.GAP
}}
- icon={
- checked
- ? "check-circle-outline"
- : "checkbox-blank-circle-outline"
- }
- iconColor={checked ? colors.secondary.icon : colors.primary.icon}
+ >
+ <Input
+ fwdRef={inputRef}
+ autoCapitalize="none"
+ onChangeText={(value) => {
+ values.current.inputValue = value;
+ }}
+ testID="input-value"
+ secureTextEntry={dialogInfo.secureTextEntry}
+ //defaultValue={dialogInfo.defaultValue}
+ onSubmit={() => {
+ onPressPositive();
+ }}
+ returnKeyLabel="Done"
+ returnKeyType="done"
+ keyboardType={dialogInfo.keyboardType || "default"}
+ placeholder={dialogInfo.inputPlaceholder}
+ />
+ </View>
+ ) : null}
+
+ {dialogInfo?.notice ? (
+ <View
style={{
- justifyContent: "flex-start"
+ paddingHorizontal: DefaultAppStyles.GAP
}}
- height={35}
- iconSize={20}
- width="100%"
- title={dialogInfo.check.info}
- type={checked ? dialogInfo.check.type || "plain" : "plain"}
- />
- </>
- ) : null}
-
- <DialogButtons
- onPressNegative={onNegativePress}
- onPressPositive={dialogInfo.positivePress && onPressPositive}
- loading={loading}
- positiveTitle={dialogInfo.positiveText}
- negativeTitle={dialogInfo.negativeText}
- positiveType={dialogInfo.positiveType}
- />
- </View>
+ >
+ <Notice
+ type={dialogInfo.notice.type || "information"}
+ text={dialogInfo.notice.text}
+ />
+ </View>
+ ) : null}
+
+ {dialogInfo.check ? (
+ <>
+ <Button
+ onPress={() => {
+ setChecked(!checked);
+ }}
+ icon={
+ checked
+ ? "check-circle-outline"
+ : "checkbox-blank-circle-outline"
+ }
+ iconColor={
+ checked ? colors.secondary.icon : colors.primary.icon
+ }
+ style={{
+ justifyContent: "flex-start"
+ }}
+ height={35}
+ iconSize={20}
+ width="100%"
+ title={dialogInfo.check.info}
+ type={checked ? dialogInfo.check.type || "plain" : "plain"}
+ />
+ </>
+ ) : null}
+
+ <DialogButtons
+ onPressNegative={onNegativePress}
+ onPressPositive={dialogInfo.positivePress && onPressPositive}
+ loading={loading}
+ positiveTitle={dialogInfo.positiveText}
+ negativeTitle={dialogInfo.negativeText}
+ positiveType={dialogInfo.positiveType}
+ />
+ </View>
+ )}
<Toast context="local" />
</BaseDialog>
) : null;
diff --git a/apps/mobile/app/components/properties/tags.js b/apps/mobile/app/components/properties/tags.js
index 06082c2ad..2d8ed73b7 100644
--- a/apps/mobile/app/components/properties/tags.js
+++ b/apps/mobile/app/components/properties/tags.js
@@ -24,11 +24,11 @@ import { TaggedNotes } from "../../screens/notes/tagged";
import { useThemeColors } from "@notesnook/theme";
import { AppFontSize } from "../../utils/size";
import { sleep } from "../../utils/time";
-import ManageTagsSheet from "../sheets/manage-tags";
import { Button } from "../ui/button";
import { ColorTags } from "./color-tags";
import { strings } from "@notesnook/intl";
import { DefaultAppStyles } from "../../utils/styles";
+import ManageTags from "../../screens/manage-tags";
export const Tags = ({ item, close }) => {
const { colors } = useThemeColors();
@@ -47,7 +47,8 @@ export const Tags = ({ item, close }) => {
>
<Button
onPress={async () => {
- ManageTagsSheet.present([item.id]);
+ ManageTags.present([item.id]);
+ close();
}}
buttonType={{
text: colors.primary.accent
diff --git a/apps/mobile/app/components/selection-header/index.tsx b/apps/mobile/app/components/selection-header/index.tsx
index 19a65f961..7233a3536 100644
--- a/apps/mobile/app/components/selection-header/index.tsx
+++ b/apps/mobile/app/components/selection-header/index.tsx
@@ -42,10 +42,11 @@ import { DefaultAppStyles } from "../../utils/styles";
import { sleep } from "../../utils/time";
import { presentDialog } from "../dialog/functions";
import ExportNotesSheet from "../sheets/export-notes";
-import ManageTagsSheet from "../sheets/manage-tags";
+
import { MoveNotebook } from "../../screens/move-notebook";
import { IconButton } from "../ui/icon-button";
import NativeTooltip from "../../utils/tooltip";
+import ManageTags from "../../screens/manage-tags";
export const SelectionHeader = React.memo(
({
@@ -209,7 +210,7 @@ export const SelectionHeader = React.memo(
{
title: strings.manageTags(),
onPress: async () => {
- ManageTagsSheet.present(selectedItemsList);
+ ManageTags.present(selectedItemsList);
},
visible: type === "note",
icon: "pound"
diff --git a/apps/mobile/app/components/sheets/add-notebook/index.tsx b/apps/mobile/app/components/sheets/add-notebook/index.tsx
index 84b00de74..3bcaa170d 100644
--- a/apps/mobile/app/components/sheets/add-notebook/index.tsx
+++ b/apps/mobile/app/components/sheets/add-notebook/index.tsx
@@ -24,23 +24,22 @@ import { TextInput, View } from "react-native";
import { notesnook } from "../../../../e2e/test.ids";
import { db } from "../../../common/database";
import { DDS } from "../../../services/device-detection";
-import {
- ToastManager,
- eSendEvent,
- presentSheet
-} from "../../../services/event-manager";
+import { ToastManager, eSendEvent } 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 { eOnNotebookUpdated } from "../../../utils/events";
import { getParentNotebookId } from "../../../utils/notebooks";
-import { AppFontSize } from "../../../utils/size";
-import { Button } from "../../ui/button";
import Input from "../../ui/input";
-import Seperator from "../../ui/seperator";
-import Heading from "../../ui/typography/heading";
-import { DefaultAppStyles } from "../../../utils/styles";
+import { useSettingStore } from "../../../stores/use-setting-store";
+import DialogHeader from "../../dialog/dialog-header";
+import DialogButtons from "../../dialog/dialog-buttons";
+import { presentDialog } from "../../dialog/functions";
+import { getElevationStyle } from "../../../utils/elevation";
+import { defaultBorderRadius } from "../../../utils/size";
+import { useThemeColors } from "@notesnook/theme";
+import { getContainerBorder } from "../../../utils/colors";
export const AddNotebookSheet = ({
notebook,
@@ -55,6 +54,7 @@ export const AddNotebookSheet = ({
showMoveNotesOnComplete: boolean;
defaultTitle?: string;
}) => {
+ const { colors } = useThemeColors();
const title = useRef(notebook?.title || defaultTitle);
const description = useRef(notebook?.description);
const titleInput = useRef<TextInput>(null);
@@ -124,57 +124,66 @@ export const AddNotebookSheet = ({
return (
<View
style={{
- maxHeight: DDS.isTab ? "90%" : "97%",
- borderRadius: DDS.isTab ? 5 : 0,
- paddingHorizontal: DefaultAppStyles.GAP
+ ...getElevationStyle(5),
+ width: DDS.isTab ? 400 : "85%",
+ maxHeight: 450,
+ borderRadius: defaultBorderRadius,
+ backgroundColor: colors.primary.background,
+ paddingTop: 12,
+ ...getContainerBorder(colors.primary.border, 0.5),
+ overflow: "hidden"
}}
>
- <Heading size={AppFontSize.lg}>
- {notebook ? strings.editNotebook() : strings.newNotebook()}
- </Heading>
-
- <Seperator />
-
- <Input
- fwdRef={titleInput}
- testID={notesnook.ids.dialogs.notebook.inputs.title}
- onChangeText={(value) => {
- title.current = value;
- }}
- onLayout={() => {
- setImmediate(() => {
- titleInput?.current?.focus();
- });
- }}
- placeholder={strings.enterNotebookTitle()}
- onSubmit={() => {
- descriptionInput.current?.focus();
- }}
- returnKeyLabel="Next"
- returnKeyType="next"
- defaultValue={notebook ? notebook.title : title.current}
- />
-
- <Input
- fwdRef={descriptionInput}
- testID={notesnook.ids.dialogs.notebook.inputs.description}
- onChangeText={(value) => {
- description.current = value;
- }}
- placeholder={strings.enterNotebookDescription()}
- returnKeyLabel={strings.next()}
- returnKeyType="next"
- defaultValue={notebook ? notebook.description : ""}
- />
-
- <Button
- title={notebook ? strings.save() : strings.add()}
- type="accent"
+ <View
style={{
- paddingHorizontal: DefaultAppStyles.GAP * 2,
- width: "100%"
+ paddingHorizontal: 12
+ }}
+ >
+ <DialogHeader
+ title={notebook ? strings.editNotebook() : strings.newNotebook()}
+ />
+
+ <Input
+ fwdRef={titleInput}
+ testID={notesnook.ids.dialogs.notebook.inputs.title}
+ onChangeText={(value) => {
+ title.current = value;
+ }}
+ onLayout={() => {
+ setTimeout(() => {
+ titleInput?.current?.focus();
+ }, 300);
+ }}
+ placeholder={strings.enterNotebookTitle()}
+ onSubmit={() => {
+ descriptionInput.current?.focus();
+ }}
+ returnKeyLabel="Next"
+ returnKeyType="next"
+ defaultValue={notebook ? notebook.title : title.current}
+ />
+
+ <Input
+ fwdRef={descriptionInput}
+ testID={notesnook.ids.dialogs.notebook.inputs.description}
+ onChangeText={(value) => {
+ description.current = value;
+ }}
+ placeholder={strings.enterNotebookDescription()}
+ returnKeyLabel={strings.next()}
+ returnKeyType="next"
+ defaultValue={notebook ? notebook.description : ""}
+ />
+ </View>
+ <DialogButtons
+ onPressNegative={() => {
+ title.current = undefined;
+ close?.(false);
+ useSettingStore.getState().setSheetKeyboardHandler(true);
}}
- onPress={onSaveChanges}
+ positiveTitle={notebook ? strings.save() : strings.add()}
+ negativeTitle={strings.cancel()}
+ onPressPositive={onSaveChanges}
/>
</View>
);
@@ -188,9 +197,9 @@ AddNotebookSheet.present = (
showMoveNotesOnComplete = true,
defaultTitle?: string
) => {
- presentSheet({
+ presentDialog({
context: context,
- component: (ref, close) => (
+ component: (close) => (
<AddNotebookSheet
notebook={notebook}
parentNotebook={parentNotebook}
diff --git a/apps/mobile/app/components/ui/input/index.tsx b/apps/mobile/app/components/ui/input/index.tsx
index 5339bea35..8fe50b85c 100644
--- a/apps/mobile/app/components/ui/input/index.tsx
+++ b/apps/mobile/app/components/ui/input/index.tsx
@@ -321,6 +321,9 @@ const Input = ({
bottom={10}
onPress={button.onPress}
color={button.color}
+ style={{
+ marginRight: -8
+ }}
/>
)}
diff --git a/apps/mobile/app/navigation/navigation-stack.tsx b/apps/mobile/app/navigation/navigation-stack.tsx
index 4f7f8f1bc..efe14356d 100644
--- a/apps/mobile/app/navigation/navigation-stack.tsx
+++ b/apps/mobile/app/navigation/navigation-stack.tsx
@@ -247,6 +247,7 @@ let LinkNotebooks: any = null;
let MoveNotebook: any = null;
let MoveNotes: any = null;
let Settings: any = null;
+let ManageTags: any = null;
export const RootNavigation = () => {
const introCompleted = useSettingStore(
@@ -326,6 +327,15 @@ export const RootNavigation = () => {
return Settings;
}}
/>
+
+ <RootStack.Screen
+ name="ManageTags"
+ getComponent={() => {
+ ManageTags =
+ ManageTags || require("../screens/manage-tags").default;
+ return ManageTags;
+ }}
+ />
</RootStack.Navigator>
</NavigationContainer>
);
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
index 779801fcd..33d66ae8c 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
+++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
@@ -41,7 +41,6 @@ import { AuthMode } from "../../../components/auth/common";
import EditorTabs from "../../../components/sheets/editor-tabs";
import { Issue } from "../../../components/sheets/github/issue";
import LinkNote from "../../../components/sheets/link-note";
-import ManageTagsSheet from "../../../components/sheets/manage-tags";
import { RelationsList } from "../../../components/sheets/relations-list";
import ReminderSheet from "../../../components/sheets/reminder";
import TableOfContents from "../../../components/sheets/toc";
@@ -80,6 +79,7 @@ import { useTabStore } from "./use-tab-store";
import { editorState, openInternalLink } from "./utils";
import { Properties } from "../../../components/properties";
import { sleep } from "../../../utils/time";
+import ManageTags from "../../manage-tags";
const publishNote = async () => {
const user = useUserStore.getState().user;
@@ -449,7 +449,7 @@ export const useEditorEvents = (
});
return;
}
- ManageTagsSheet.present([noteId]);
+ ManageTags.present([noteId]);
break;
case EditorEvents.tag:
if (editorMessage.value) {
diff --git a/apps/mobile/app/components/sheets/manage-tags/index.tsx b/apps/mobile/app/screens/manage-tags/index.tsx
similarity index 66%
rename from apps/mobile/app/components/sheets/manage-tags/index.tsx
rename to apps/mobile/app/screens/manage-tags/index.tsx
index c7016371b..ffcd993e7 100644
--- a/apps/mobile/app/components/sheets/manage-tags/index.tsx
+++ b/apps/mobile/app/screens/manage-tags/index.tsx
@@ -29,27 +29,30 @@ import React, {
useRef,
useState
} from "react";
+import { SafeAreaView } from "react-native-safe-area-context";
import { TextInput, View, useWindowDimensions } from "react-native";
import { ActionSheetRef } from "react-native-actions-sheet";
import { FlashList } from "react-native-actions-sheet/dist/src/views/FlashList";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
-import { db } from "../../../common/database";
-import { useDBItem } from "../../../hooks/use-db-item";
-import { ToastManager, presentSheet } from "../../../services/event-manager";
-import Navigation from "../../../services/navigation";
+import { db } from "../../common/database";
+import { useDBItem } from "../../hooks/use-db-item";
+import { ToastManager } from "../../services/event-manager";
+import Navigation, { NavigationProps } from "../../services/navigation";
import {
ItemSelection,
createItemSelectionStore
-} from "../../../stores/item-selection-store";
-import { useRelationStore } from "../../../stores/use-relation-store";
-import { useTagStore } from "../../../stores/use-tag-store";
-import { defaultBorderRadius, AppFontSize } from "../../../utils/size";
-import Input from "../../ui/input";
-import { Pressable } from "../../ui/pressable";
-import Heading from "../../ui/typography/heading";
-import Paragraph from "../../ui/typography/paragraph";
+} from "../../stores/item-selection-store";
+import { useRelationStore } from "../../stores/use-relation-store";
+import { useTagStore } from "../../stores/use-tag-store";
+import { defaultBorderRadius, AppFontSize } from "../../utils/size";
+import Input from "../../components/ui/input";
+import { Pressable } from "../../components/ui/pressable";
+import Heading from "../../components/ui/typography/heading";
+import Paragraph from "../../components/ui/typography/paragraph";
import { strings } from "@notesnook/intl";
-import { DefaultAppStyles } from "../../../utils/styles";
+import { DefaultAppStyles } from "../../utils/styles";
+import { Header } from "../../components/header";
+import { useNavigationFocus } from "../../hooks/use-navigation-focus";
async function updateInitialSelectionState(items: string[]) {
const relations = await db.relations
@@ -85,16 +88,14 @@ async function updateInitialSelectionState(items: string[]) {
const useTagItemSelection = createItemSelectionStore(true);
-const ManageTagsSheet = (props: {
- ids?: string[];
- actionSheetRef: RefObject<ActionSheetRef>;
-}) => {
+const ManageTags = (props: NavigationProps<"ManageTags">) => {
const { colors } = useThemeColors();
- const ids = useMemo(() => props.ids || [], [props.ids]);
+ const ids = props.route.params.ids || [];
const [tags, setTags] = useState<VirtualizedGrouping<Tag>>();
const [query, setQuery] = useState<string>();
const inputRef = useRef<TextInput>(null);
const [focus, setFocus] = useState(false);
+ useNavigationFocus(props.navigation, { focusOnInit: true });
const [queryExists, setQueryExists] = useState(false);
const dimensions = useWindowDimensions();
const refreshSelection = useCallback(() => {
@@ -239,112 +240,117 @@ const ManageTagsSheet = (props: {
);
return (
- <View
+ <SafeAreaView
style={{
width: "100%",
alignSelf: "center",
- paddingHorizontal: DefaultAppStyles.GAP,
- maxHeight: dimensions.height * 0.85
+ backgroundColor: colors.primary.background,
+ gap: DefaultAppStyles.GAP_VERTICAL
}}
>
- <Input
- button={{
- icon: "magnify",
- color: colors.primary.accent,
- size: AppFontSize.lg,
- onPress: () => {}
- }}
- testID="tag-input"
- fwdRef={inputRef}
- autoCapitalize="none"
- onChangeText={(v) => {
- setQuery(sanitizeTag(v));
- checkQueryExists(sanitizeTag(v));
- }}
- onFocusInput={() => {
- setFocus(true);
- }}
- onBlurInput={() => {
- setFocus(false);
- }}
- onSubmit={() => {
- onSubmit();
+ <Header title={strings.manageTags()} canGoBack />
+ <View
+ style={{
+ paddingHorizontal: DefaultAppStyles.GAP
}}
- placeholder={strings.searchForTags()}
- />
+ >
+ <Input
+ button={{
+ icon: "magnify",
+ color: colors.primary.accent,
+ size: AppFontSize.lg,
+ onPress: () => {}
+ }}
+ testID="tag-input"
+ fwdRef={inputRef}
+ autoCapitalize="none"
+ onChangeText={(v) => {
+ setQuery(sanitizeTag(v));
+ checkQueryExists(sanitizeTag(v));
+ }}
+ onFocusInput={() => {
+ setFocus(true);
+ }}
+ onBlurInput={() => {
+ setFocus(false);
+ }}
+ onSubmit={() => {
+ onSubmit();
+ }}
+ placeholder={strings.searchForTags()}
+ />
+
+ {query && !queryExists ? (
+ <Pressable
+ key={"query_item"}
+ style={{
+ flexDirection: "row",
+ justifyContent: "space-between",
+ paddingHorizontal: DefaultAppStyles.GAP,
+ paddingVertical: DefaultAppStyles.GAP_VERTICAL
+ }}
+ onPress={onSubmit}
+ type="selected"
+ >
+ <Heading size={AppFontSize.sm} color={colors.selected.heading}>
+ {strings.add()} {'"' + "#" + query + '"'}
+ </Heading>
+ <Icon
+ name="plus"
+ color={colors.selected.icon}
+ size={AppFontSize.lg}
+ />
+ </Pressable>
+ ) : null}
- {query && !queryExists ? (
- <Pressable
- key={"query_item"}
+ <View
style={{
- flexDirection: "row",
- marginVertical: 5,
- justifyContent: "space-between",
- padding: DefaultAppStyles.GAP
+ width: "100%",
+ flexGrow: 1,
+ height: "100%"
}}
- onPress={onSubmit}
- type="selected"
>
- <Heading size={AppFontSize.sm} color={colors.selected.heading}>
- {strings.add()} {'"' + "#" + query + '"'}
- </Heading>
- <Icon
- name="plus"
- color={colors.selected.icon}
- size={AppFontSize.lg}
- />
- </Pressable>
- ) : null}
-
- <View
- style={{
- width: "100%",
- flexGrow: 1,
- height: "100%"
- }}
- >
- <FlashList
- data={tags?.placeholders}
- keyboardShouldPersistTaps
- keyboardDismissMode="interactive"
- estimatedItemSize={50}
- renderItem={renderTag}
- ListEmptyComponent={
- <View
- style={{
- width: "100%",
- height: 200,
- justifyContent: "center",
- alignItems: "center"
- }}
- >
- <Heading size={50} color={colors.secondary.heading}>
- #
- </Heading>
- <Paragraph
- textBreakStrategy="balanced"
- color={colors.secondary.paragraph}
+ <FlashList
+ data={tags?.placeholders}
+ keyboardShouldPersistTaps
+ keyboardDismissMode="interactive"
+ estimatedItemSize={50}
+ renderItem={renderTag}
+ ListEmptyComponent={
+ <View
+ style={{
+ width: "100%",
+ height: 200,
+ justifyContent: "center",
+ alignItems: "center"
+ }}
>
- {strings.emptyPlaceholders("tag")}
- </Paragraph>
- </View>
- }
- ListFooterComponent={<View style={{ height: 50 }} />}
- />
+ <Heading size={50} color={colors.secondary.heading}>
+ #
+ </Heading>
+ <Paragraph
+ textBreakStrategy="balanced"
+ color={colors.secondary.paragraph}
+ >
+ {strings.emptyPlaceholders("tag")}
+ </Paragraph>
+ </View>
+ }
+ ListFooterComponent={<View style={{ height: 50 }} />}
+ />
+ </View>
</View>
- </View>
+ </SafeAreaView>
);
};
-ManageTagsSheet.present = (ids?: string[]) => {
- presentSheet({
- component: (ref) => {
- return <ManageTagsSheet actionSheetRef={ref} ids={ids} />;
- }
+ManageTags.present = (ids?: string[]) => {
+ Navigation.push("ManageTags", {
+ ids: ids
});
};
-export default ManageTagsSheet;
+export default ManageTags;
const TagItem = ({
id,
diff --git a/apps/mobile/app/services/navigation.ts b/apps/mobile/app/services/navigation.ts
index f26035f38..d740030be 100755
--- a/apps/mobile/app/services/navigation.ts
+++ b/apps/mobile/app/services/navigation.ts
@@ -68,7 +68,8 @@ const routeNames = {
MoveNotebook: "MoveNotebook",
LinkNotebooks: "LinkNotebooks",
MoveNotes: "MoveNotes",
- Archive: "Archive"
+ Archive: "Archive",
+ ManageTags: "ManageTags"
};
export type NavigationProps<T extends RouteName> = NativeStackScreenProps<
diff --git a/apps/mobile/app/stores/use-navigation-store.ts b/apps/mobile/app/stores/use-navigation-store.ts
index 2b4c37cf0..3cb39312d 100644
--- a/apps/mobile/app/stores/use-navigation-store.ts
+++ b/apps/mobile/app/stores/use-navigation-store.ts
@@ -91,6 +91,9 @@ export interface RouteParams extends ParamListBase {
MoveNotes: {
notebook: Notebook;
};
+ ManageTags: {
+ ids?: string[];
+ };
}
export type RouteName = keyof RouteParams;