mobile: cleanup and fix errors

This commit is contained in:
Ammar Ahmed
2024-11-08 11:28:47 +05:00
committed by Abdullah Atta
parent ceebda5314
commit 1ad199ce53
12 changed files with 64 additions and 68 deletions

View File

@@ -17,8 +17,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import React, { useEffect, useRef, useState } from "react"; import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { View } from "react-native"; import { View } from "react-native";
import { ScrollView } from "react-native-actions-sheet";
import { db } from "../../common/database/index"; import { db } from "../../common/database/index";
import useTimer from "../../hooks/use-timer"; import useTimer from "../../hooks/use-timer";
import { import {
@@ -26,19 +29,14 @@ import {
presentSheet, presentSheet,
ToastManager ToastManager
} from "../../services/event-manager"; } from "../../services/event-manager";
import { useThemeColors } from "@notesnook/theme";
import { eCloseSheet } from "../../utils/events"; import { eCloseSheet } from "../../utils/events";
import { SIZE } from "../../utils/size"; import { SIZE } from "../../utils/size";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { IconButton } from "../ui/icon-button"; import { IconButton } from "../ui/icon-button";
import Input from "../ui/input"; import Input from "../ui/input";
import { Pressable } from "../ui/pressable"; import { Pressable } from "../ui/pressable";
import Seperator from "../ui/seperator";
import Heading from "../ui/typography/heading"; import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph"; import Paragraph from "../ui/typography/paragraph";
import { useCallback } from "react";
import { ScrollView } from "react-native-actions-sheet";
import { strings } from "@notesnook/intl";
const TwoFactorVerification = ({ onMfaLogin, mfaInfo, onCancel }) => { const TwoFactorVerification = ({ onMfaLogin, mfaInfo, onCancel }) => {
const { colors } = useThemeColors(); const { colors } = useThemeColors();

View File

@@ -33,7 +33,6 @@ import { eScrollEvent } from "../../utils/events";
import { LeftMenus } from "./left-menus"; import { LeftMenus } from "./left-menus";
import { RightMenus } from "./right-menus"; import { RightMenus } from "./right-menus";
import { Title } from "./title"; import { Title } from "./title";
import { useNavigation } from "@react-navigation/native";
type HeaderRightButton = { type HeaderRightButton = {
title: string; title: string;

View File

@@ -17,30 +17,23 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme"; import { useThemeColors } from "@notesnook/theme";
import React from "react"; import React from "react";
import { import { Linking, ScrollView, useWindowDimensions, View } from "react-native";
Linking,
ScrollView,
TouchableOpacity,
useWindowDimensions,
View
} from "react-native";
import { SwiperFlatList } from "react-native-swiper-flatlist"; import { SwiperFlatList } from "react-native-swiper-flatlist";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { getElevationStyle } from "../../utils/elevation";
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets"; import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
import { eSendEvent } from "../../services/event-manager";
import Navigation from "../../services/navigation";
import SettingsService from "../../services/settings"; import SettingsService from "../../services/settings";
import { useSettingStore } from "../../stores/use-setting-store"; import { useSettingStore } from "../../stores/use-setting-store";
import { getElevationStyle } from "../../utils/elevation";
import { eOpenLoginDialog } from "../../utils/events";
import { SIZE } from "../../utils/size"; import { SIZE } from "../../utils/size";
import { AuthMode } from "../auth";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import Heading from "../ui/typography/heading"; import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph"; import Paragraph from "../ui/typography/paragraph";
import Navigation from "../../services/navigation";
import { eOpenLoginDialog } from "../../utils/events";
import { AuthMode } from "../auth";
import { eSendEvent } from "../../services/event-manager";
import { strings } from "@notesnook/intl";
const Intro = ({ navigation }) => { const Intro = ({ navigation }) => {
const { colors } = useThemeColors(); const { colors } = useThemeColors();

View File

@@ -34,12 +34,13 @@ import {
Reminder, Reminder,
Tag, Tag,
TrashItem, TrashItem,
VirtualizedGrouping VirtualizedGrouping,
getSortValue
} from "@notesnook/core"; } from "@notesnook/core";
import { getSortValue } from "@notesnook/core";
import React, { useCallback, useEffect, useRef, useState } from "react"; import React, { useCallback, useEffect, useRef, useState } from "react";
import { View } from "react-native"; import { View } from "react-native";
import { db } from "../../common/database"; import { db } from "../../common/database";
import { useIsCompactModeEnabled } from "../../hooks/use-is-compact-mode-enabled";
import { eSendEvent } from "../../services/event-manager"; import { eSendEvent } from "../../services/event-manager";
import { RouteName } from "../../stores/use-navigation-store"; import { RouteName } from "../../stores/use-navigation-store";
import { eOpenJumpToDialog } from "../../utils/events"; import { eOpenJumpToDialog } from "../../utils/events";
@@ -48,7 +49,6 @@ import { NoteWrapper } from "../list-items/note/wrapper";
import { NotebookWrapper } from "../list-items/notebook/wrapper"; import { NotebookWrapper } from "../list-items/notebook/wrapper";
import ReminderItem from "../list-items/reminder"; import ReminderItem from "../list-items/reminder";
import TagItem from "../list-items/tag"; import TagItem from "../list-items/tag";
import { useIsCompactModeEnabled } from "../../hooks/use-is-compact-mode-enabled";
type ListItemWrapperProps<TItem = Item> = { type ListItemWrapperProps<TItem = Item> = {
group?: GroupingKey; group?: GroupingKey;

View File

@@ -81,7 +81,7 @@ export const AddNotebookSheet = ({
id: notebook?.id id: notebook?.id
}); });
if (parentNotebook) { if (parentNotebook && id) {
await db.relations.add(parentNotebook, { await db.relations.add(parentNotebook, {
type: "notebook", type: "notebook",
id: id id: id
@@ -94,7 +94,8 @@ export const AddNotebookSheet = ({
useNotebookStore.getState().refresh(); useNotebookStore.getState().refresh();
const parent = const parent =
parentNotebook?.id || (await getParentNotebookId(notebook?.id || id)); parentNotebook?.id ||
(await getParentNotebookId(notebook?.id || (id as string)));
eSendEvent(eOnNotebookUpdated, parent); eSendEvent(eOnNotebookUpdated, parent);
if (notebook) { if (notebook) {
@@ -104,7 +105,7 @@ export const AddNotebookSheet = ({
}); });
} }
if (!notebook && showMoveNotesOnComplete) { if (!notebook && showMoveNotesOnComplete && id) {
MoveNotes.present(await db.notebooks.notebook(id)); MoveNotes.present(await db.notebooks.notebook(id));
} else { } else {
close?.(true); close?.(true);

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Note } from "@notesnook/core"; import { Note } from "@notesnook/core";
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme"; import { useThemeColors } from "@notesnook/theme";
import React, { import React, {
RefObject, RefObject,
@@ -49,13 +50,11 @@ import DialogHeader from "../../dialog/dialog-header";
import SheetProvider from "../../sheet-provider"; import SheetProvider from "../../sheet-provider";
import { Button } from "../../ui/button"; import { Button } from "../../ui/button";
import { IconButton } from "../../ui/icon-button"; import { IconButton } from "../../ui/icon-button";
import Input from "../../ui/input";
import Paragraph from "../../ui/typography/paragraph"; import Paragraph from "../../ui/typography/paragraph";
import { AddNotebookSheet } from "../add-notebook";
import { NotebookItem } from "./notebook-item"; import { NotebookItem } from "./notebook-item";
import { useNotebookItemSelectionStore } from "./store"; import { useNotebookItemSelectionStore } from "./store";
import { AddNotebookSheet } from "../add-notebook";
import Input from "../../ui/input";
import { presentDialog } from "../../dialog/functions";
import { strings } from "@notesnook/intl";
async function updateInitialSelectionState(items: string[]) { async function updateInitialSelectionState(items: string[]) {
const relations = await db.relations const relations = await db.relations

View File

@@ -43,7 +43,7 @@ const NewFeature = ({
version version
}: { }: {
features: FeatureType[]; features: FeatureType[];
version?: string | null; version?: string;
}) => { }) => {
const { colors } = useThemeColors(); const { colors } = useThemeColors();
@@ -122,7 +122,7 @@ NewFeature.present = () => {
component: ( component: (
<NewFeature <NewFeature
features={features} features={features}
version={SettingsService.getProperty("version")} version={SettingsService.getProperty("version") || undefined}
/> />
), ),
disableClosing: true disableClosing: true

View File

@@ -16,8 +16,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { VirtualizedGrouping } from "@notesnook/core"; import { Item, ItemReference, VirtualizedGrouping } from "@notesnook/core";
import { Item, ItemReference } from "@notesnook/core"; import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme"; import { useThemeColors } from "@notesnook/theme";
import React, { RefObject, useEffect, useState } from "react"; import React, { RefObject, useEffect, useState } from "react";
import { View } from "react-native"; import { View } from "react-native";
@@ -37,8 +37,6 @@ import SheetProvider from "../../sheet-provider";
import { Button } from "../../ui/button"; import { Button } from "../../ui/button";
import { PressableProps } from "../../ui/pressable"; import { PressableProps } from "../../ui/pressable";
import Paragraph from "../../ui/typography/paragraph"; import Paragraph from "../../ui/typography/paragraph";
import { isStringLiteralOrJsxExpression } from "typescript";
import { strings } from "@notesnook/intl";
type RelationsListProps = { type RelationsListProps = {
actionSheetRef: RefObject<ActionSheetRef>; actionSheetRef: RefObject<ActionSheetRef>;
@@ -125,7 +123,9 @@ export const RelationsList = ({
// width="100%" // width="100%"
type="inverted" type="inverted"
icon="plus" icon="plus"
title={strings.addItem(referenceType)} title={strings.addItem(
referenceType as "notebook" | "tag" | "reminder" | "note"
)}
/> />
</View> </View>
) : ( ) : (

View File

@@ -70,7 +70,6 @@ interface InputProps extends TextInputProps {
}; };
buttons?: React.ReactNode; buttons?: React.ReactNode;
onBlurInput?: () => void; onBlurInput?: () => void;
onPress?: () => void;
height?: number; height?: number;
fontSize?: number; fontSize?: number;
onFocusInput?: () => void; onFocusInput?: () => void;

View File

@@ -17,7 +17,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* eslint-disable no-inner-declarations */ /* eslint-disable no-inner-declarations */
import { VAULT_ERRORS } from "@notesnook/core";
import { import {
Color, Color,
ItemReference, ItemReference,
@@ -25,8 +24,11 @@ import {
Notebook, Notebook,
Reminder, Reminder,
Tag, Tag,
TrashItem TrashItem,
VAULT_ERRORS,
createInternalLink
} from "@notesnook/core"; } from "@notesnook/core";
import { strings } from "@notesnook/intl";
import { DisplayedNotification } from "@notifee/react-native"; import { DisplayedNotification } from "@notifee/react-native";
import Clipboard from "@react-native-clipboard/clipboard"; import Clipboard from "@react-native-clipboard/clipboard";
import React, { useCallback, useEffect, useRef, useState } from "react"; import React, { useCallback, useEffect, useRef, useState } from "react";
@@ -39,8 +41,10 @@ import NoteHistory from "../components/note-history";
import { AddNotebookSheet } from "../components/sheets/add-notebook"; import { AddNotebookSheet } from "../components/sheets/add-notebook";
import MoveNoteSheet from "../components/sheets/add-to"; import MoveNoteSheet from "../components/sheets/add-to";
import ExportNotesSheet from "../components/sheets/export-notes"; import ExportNotesSheet from "../components/sheets/export-notes";
import { MoveNotebookSheet } from "../components/sheets/move-notebook";
import { MoveNotes } from "../components/sheets/move-notes/movenote"; import { MoveNotes } from "../components/sheets/move-notes/movenote";
import PublishNoteSheet from "../components/sheets/publish-note"; import PublishNoteSheet from "../components/sheets/publish-note";
import { ReferencesList } from "../components/sheets/references";
import { RelationsList } from "../components/sheets/relations-list/index"; import { RelationsList } from "../components/sheets/relations-list/index";
import ReminderSheet from "../components/sheets/reminder"; import ReminderSheet from "../components/sheets/reminder";
import { useSideBarDraggingStore } from "../components/side-menu/dragging-store"; import { useSideBarDraggingStore } from "../components/side-menu/dragging-store";
@@ -60,15 +64,10 @@ import { useRelationStore } from "../stores/use-relation-store";
import { useSelectionStore } from "../stores/use-selection-store"; import { useSelectionStore } from "../stores/use-selection-store";
import { useTagStore } from "../stores/use-tag-store"; import { useTagStore } from "../stores/use-tag-store";
import { useUserStore } from "../stores/use-user-store"; import { useUserStore } from "../stores/use-user-store";
import Errors from "../utils/errors";
import { eOpenLoginDialog, eUpdateNoteInEditor } from "../utils/events"; import { eOpenLoginDialog, eUpdateNoteInEditor } from "../utils/events";
import { deleteItems } from "../utils/functions"; import { deleteItems } from "../utils/functions";
import { convertNoteToText } from "../utils/note-to-text"; import { convertNoteToText } from "../utils/note-to-text";
import { sleep } from "../utils/time"; import { sleep } from "../utils/time";
import { ReferencesList } from "../components/sheets/references";
import { createInternalLink } from "@notesnook/core";
import { MoveNotebookSheet } from "../components/sheets/move-notebook";
import { strings } from "@notesnook/intl";
export const useActions = ({ export const useActions = ({
close, close,
@@ -314,7 +313,10 @@ export const useActions = ({
Navigation.queueRoutesForUpdate(); Navigation.queueRoutesForUpdate();
useSelectionStore.getState().setSelectionMode(undefined); useSelectionStore.getState().setSelectionMode(undefined);
ToastManager.show({ ToastManager.show({
heading: strings.actions.deleted[item.itemType](1), heading:
strings.actions.deleted[
item.itemType as keyof typeof strings.actions.deleted
](1),
type: "success", type: "success",
context: "local" context: "local"
}); });
@@ -955,7 +957,9 @@ export const useActions = ({
id: "trash", id: "trash",
title: title:
item.type !== "notebook" && item.type !== "note" item.type !== "notebook" && item.type !== "note"
? strings.doActions.delete[item.type](1) ? strings.doActions.delete[
item.type as keyof typeof strings.doActions.delete
](1)
: strings.moveToTrash(), : strings.moveToTrash(),
icon: "delete-outline", icon: "delete-outline",
type: "error", type: "error",

View File

@@ -17,8 +17,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { strings } from "@notesnook/intl";
import React from "react"; import React from "react";
import { Linking, Platform, View } from "react-native"; import { Linking, Platform, View } from "react-native";
import Config from "react-native-config";
import { Button } from "../../components/ui/button"; import { Button } from "../../components/ui/button";
import { usePricing } from "../../hooks/use-pricing"; import { usePricing } from "../../hooks/use-pricing";
import { import {
@@ -28,14 +30,9 @@ import {
} from "../../services/event-manager"; } from "../../services/event-manager";
import PremiumService from "../../services/premium"; import PremiumService from "../../services/premium";
import { useUserStore } from "../../stores/use-user-store"; import { useUserStore } from "../../stores/use-user-store";
import { import { SUBSCRIPTION_STATUS } from "../../utils/constants";
SUBSCRIPTION_PROVIDER,
SUBSCRIPTION_STATUS
} from "../../utils/constants";
import { eOpenPremiumDialog } from "../../utils/events"; import { eOpenPremiumDialog } from "../../utils/events";
import { SIZE } from "../../utils/size"; import { SIZE } from "../../utils/size";
import Config from "react-native-config";
import { strings } from "@notesnook/intl";
export const Subscription = () => { export const Subscription = () => {
const user = useUserStore((state) => state.user); const user = useUserStore((state) => state.user);
const monthlyPlan = usePricing("monthly"); const monthlyPlan = usePricing("monthly");

View File

@@ -24,18 +24,18 @@ import { actionErrors } from "../generated/action-errors";
import { actionConfirmations } from "../generated/action-confirmations"; import { actionConfirmations } from "../generated/action-confirmations";
const SEARCH_IN_ROUTE_STRINGS = { const SEARCH_IN_ROUTE_STRINGS = {
Notes: () => t`Type a keyword to search in Notes`, Notes: () => t`Search in in Notes`,
Notebooks: () => t`Type a keyword to search in Notebooks`, Notebooks: () => t`Search in in Notebooks`,
Notebook: () => t`Type a keyword to search in Notebook`, Notebook: () => t`Search in in Notebook`,
Favorites: () => t`Type a keyword to search in Favorites`, Favorites: () => t`Search in in Favorites`,
Reminders: () => t`Type a keyword to search in Reminders`, Reminders: () => t`Search in in Reminders`,
Trash: () => t`Type a keyword to search in Trash`, Trash: () => t`Search in in Trash`,
Settings: () => t`Type a keyword to search in Settings`, Settings: () => t`Search in in Settings`,
Tags: () => t`Type a keyword to search in Tags`, Tags: () => t`Search in in Tags`,
Editor: () => t`Type a keyword to search in Editor`, Editor: () => t`Search in in Editor`,
Home: () => t`Type a keyword to search in Home`, Home: () => t`Search in in Home`,
Search: () => t`Type a keyword to search in Search`, Search: () => t`Search in in Search`,
Monographs: () => t`Type a keyword to search in Monographs` Monographs: () => t`Search in in Monographs`
}; };
export const strings = { export const strings = {
@@ -1474,8 +1474,14 @@ For example:
Search: () => t`Search`, Search: () => t`Search`,
Monographs: () => t`Monographs` Monographs: () => t`Monographs`
}, },
searchInRoute: (routeName: keyof typeof SEARCH_IN_ROUTE_STRINGS) => { searchInRoute: (
return SEARCH_IN_ROUTE_STRINGS[routeName](); routeName: keyof typeof SEARCH_IN_ROUTE_STRINGS | ({} & string)
) => {
return (
SEARCH_IN_ROUTE_STRINGS[
routeName as keyof typeof SEARCH_IN_ROUTE_STRINGS
]() || t`Search in ${routeName}`
);
}, },
logoutConfirmation: () => logoutConfirmation: () =>
t`Are you sure you want to logout and clear all data stored on THIS DEVICE?`, t`Are you sure you want to logout and clear all data stored on THIS DEVICE?`,