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
minor refactoring
ammarahm-edceb9d5209298
diff --git a/apps/mobile/src/components/listitems/notebook/wrapper.js b/apps/mobile/src/components/listitems/notebook/wrapper.jsindex dc3cdacc6..4bda578dc 100644--- a/apps/mobile/src/components/listitems/notebook/wrapper.js+++ b/apps/mobile/src/components/listitems/notebook/wrapper.js@@ -72,7 +72,7 @@ export const NotebookWrapper = React.memo(<SelectionWrapperpinned={item.pinned}index={index}- onPress={openNotebookTopic}+ onPress={() => openNotebookTopic(item)}height={item.type === 'topic' ? 80 : 110}item={item}>diff --git a/apps/mobile/src/screens/editor/EditorHeader.js b/apps/mobile/src/screens/editor/EditorHeader.jsindex 18b5dbcdb..53291d672 100644--- a/apps/mobile/src/screens/editor/EditorHeader.js+++ b/apps/mobile/src/screens/editor/EditorHeader.js@@ -100,6 +100,7 @@ const EditorHeader = () => {}, 1);keyboardListener.current?.remove();await clearEditor();+ BackHandler.removeEventListener('hardwareBackPress', _onHardwareBackPress);}closing.current = false;}, 1);diff --git a/apps/mobile/src/screens/notes/colored.tsx b/apps/mobile/src/screens/notes/colored.tsxindex 7adda64ef..d5ae6a959 100644--- a/apps/mobile/src/screens/notes/colored.tsx+++ b/apps/mobile/src/screens/notes/colored.tsx@@ -1,7 +1,7 @@import { groupArray } from 'notes-core/utils/grouping';import React from 'react';import NotesPage, { PLACEHOLDER_DATA } from '.';-import Navigation, { NavigationProps } from '../../services/navigation';+import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';import { db } from '../../utils/database';import { ColorType, TagType } from '../../utils/types';import { getAlias, openEditor, toCamelCase } from './common';@@ -20,8 +20,8 @@ export const ColoredNotes = ({ navigation, route }: NavigationProps<'ColoredNote);};-ColoredNotes.get = (id: string, grouped = true) => {- let notes = db.notes?.colored(id) || [];+ColoredNotes.get = (params: NotesScreenParams, grouped = true) => {+ let notes = db.notes?.colored(params.item.id) || [];return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;};diff --git a/apps/mobile/src/screens/notes/common.ts b/apps/mobile/src/screens/notes/common.tsindex cf36527ab..a106146f6 100644--- a/apps/mobile/src/screens/notes/common.ts+++ b/apps/mobile/src/screens/notes/common.ts@@ -57,7 +57,9 @@ export const setOnFirstSave = (export function isSynced(params: NotesScreenParams) {if (params.item.type === 'topic') {+ console.log(params.item.type);let topic = db.notebooks?.notebook(params.item.notebookId)?.topics.topic(params.item.id);+ console.log(topic?.synced(), 'sycned');return !topic ? true : topic?.synced();}return true;diff --git a/apps/mobile/src/screens/notes/index.tsx b/apps/mobile/src/screens/notes/index.tsxindex e6b986141..b82171123 100644--- a/apps/mobile/src/screens/notes/index.tsx+++ b/apps/mobile/src/screens/notes/index.tsx@@ -5,7 +5,7 @@ import List from '../../components/list';import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';import SearchService from '../../services/search';-import useNavigationStore, { HeaderRightButton } from '../../stores/use-navigation-store';+import useNavigationStore, { HeaderRightButton, RouteName } from '../../stores/use-navigation-store';import { useNoteStore } from '../../stores/use-notes-store';import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';import { NoteType } from '../../utils/types';@@ -40,8 +40,8 @@ export const MONOGRAPH_PLACEHOLDER_DATA = {buttonIcon: 'information-outline'};-export interface RouteProps<T extends string> extends NavigationProps<T> {- get: (id: string, grouped?: boolean) => NoteType[];+export interface RouteProps<T extends RouteName> extends NavigationProps<T> {+ get: (params: NotesScreenParams, grouped?: boolean) => NoteType[];placeholderData: any;onPressFloatingButton: () => void;focusControl?: boolean;@@ -59,12 +59,13 @@ const NotesPage = ({canGoBack,rightButtons}: RouteProps<'NotesPage' | 'TaggedNotes' | 'Monographs' | 'ColoredNotes' | 'TopicNotes'>) => {- const [notes, setNotes] = useState<NoteType[]>(get(route.params?.item?.id));const params = useRef<NotesScreenParams>(route?.params);- const [warning, setWarning] = useState(!isSynced(params.current));+ const [notes, setNotes] = useState<NoteType[]>(get(route.params, true));+ const [warning, setWarning] = useState(!isSynced(route.params));const loading = useNoteStore(state => state.loading);const alias = getAlias(params.current);const isMonograph = route.name === 'Monographs';+ console.log(warning, 'isWarning', isSynced(route.params));const isFocused = useNavigationFocus(navigation, {onFocus: prev => {@@ -110,11 +111,11 @@ const NotesPage = ({params.current.title = params.current.title || params.current.item.title;const { item } = params.current;try {- let notes = get(item.id) as NoteType[];+ let notes = get(params.current, true) as NoteType[];if ((item.type === 'tag' || item.type === 'color') && (!notes || notes.length === 0)) {return Navigation.goBack();}- if (item.type === 'topic') setWarning(isSynced(params.current));+ if (item.type === 'topic') setWarning(!isSynced(params.current));setNotes(notes);syncWithNavigation();} catch (e) {}@@ -134,7 +135,7 @@ const NotesPage = ({type: 'notes',title: item.type === 'tag' ? '#' + alias : toCamelCase(item.title),get: () => {- return get(item.id, false);+ return get(params.current, false);}});};diff --git a/apps/mobile/src/screens/notes/monographs.tsx b/apps/mobile/src/screens/notes/monographs.tsxindex 2d7a88fcc..c5d76b6cb 100644--- a/apps/mobile/src/screens/notes/monographs.tsx+++ b/apps/mobile/src/screens/notes/monographs.tsx@@ -1,7 +1,7 @@import { groupArray } from 'notes-core/utils/grouping';import React from 'react';import NotesPage, { PLACEHOLDER_DATA } from '.';-import Navigation, { NavigationProps } from '../../services/navigation';+import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';import { db } from '../../utils/database';import { MonographType } from '../../utils/types';import { openMonographsWebpage } from './common';@@ -20,7 +20,7 @@ export const Monographs = ({ navigation, route }: NavigationProps<'Monographs'>));};-Monographs.get = (id: string, grouped = true) => {+Monographs.get = (params: NotesScreenParams, grouped = true) => {let notes = db.monographs?.all || [];return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;};diff --git a/apps/mobile/src/screens/notes/tagged.tsx b/apps/mobile/src/screens/notes/tagged.tsxindex 68f382fc7..9086e8919 100644--- a/apps/mobile/src/screens/notes/tagged.tsx+++ b/apps/mobile/src/screens/notes/tagged.tsx@@ -1,7 +1,7 @@import { groupArray } from 'notes-core/utils/grouping';import React from 'react';import NotesPage, { PLACEHOLDER_DATA } from '.';-import Navigation, { NavigationProps } from '../../services/navigation';+import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';import { db } from '../../utils/database';import { TagType } from '../../utils/types';import { getAlias, openEditor } from './common';@@ -20,8 +20,8 @@ export const TaggedNotes = ({ navigation, route }: NavigationProps<'TaggedNotes');};-TaggedNotes.get = (id: string, grouped = true) => {- let notes = db.notes?.tagged(id) || [];+TaggedNotes.get = (params: NotesScreenParams, grouped = true) => {+ let notes = db.notes?.tagged(params.item.id) || [];return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;};diff --git a/apps/mobile/src/screens/notes/topicnotes.tsx b/apps/mobile/src/screens/notes/topicnotes.tsxindex c060409d8..54dc6a3b9 100644--- a/apps/mobile/src/screens/notes/topicnotes.tsx+++ b/apps/mobile/src/screens/notes/topicnotes.tsx@@ -46,8 +46,10 @@ export const TopicNotes = ({ navigation, route }: NavigationProps<'TopicNotes'>));};-TopicNotes.get = (id: string, grouped = true) => {- let notes = db.notes?.tagged(id) || [];+TopicNotes.get = (params: NotesScreenParams, grouped = true) => {+ //@ts-ignore+ const { id, notebookId } = params.item;+ let notes = db.notebooks?.notebook(notebookId)?.topics.topic(id)?.all || [];return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;};diff --git a/apps/mobile/src/services/navigation.ts b/apps/mobile/src/services/navigation.tsindex 67c02b9e5..46da6ae54 100755--- a/apps/mobile/src/services/navigation.ts+++ b/apps/mobile/src/services/navigation.ts@@ -122,7 +122,7 @@ function queueRoutesForUpdate(...routes: Route[]) {}function navigate<T extends RouteName>(screen: CurrentScreen, params: RouteParams[T]) {- useNavigationStore.getState().update(screen, params.canGoBack);+ useNavigationStore.getState().update(screen, params?.canGoBack);if (screen.name === 'Notebook') routeUpdateFunctions['Notebook'](params);if (screen.name.endsWith('Notes')) routeUpdateFunctions[screen.name](params);//@ts-ignorediff --git a/apps/mobile/src/stores/useNavigationStore.ts b/apps/mobile/src/stores/useNavigationStore.tsindex 89cffeb0d..9cbc35ebd 100644--- a/apps/mobile/src/stores/useNavigationStore.ts+++ b/apps/mobile/src/stores/useNavigationStore.ts@@ -36,6 +36,7 @@ export type HeaderRightButton = {interface NavigationStore extends State {currentScreen: CurrentScreen;+ currentScreenRaw: CurrentScreen;canGoBack: boolean | undefined;update: (currentScreen: CurrentScreen,@@ -52,23 +53,13 @@ const useNavigationStore = create<NavigationStore>((set, get) => ({title: 'Notes',type: 'notes'},+ currentScreenRaw: { name: 'notes' },canGoBack: false,update: (currentScreen, canGoBack, headerRightButtons) => {//@ts-ignoreconst color = COLORS_NOTE[currentScreen.title?.toLowerCase()];- if (- currentScreen.name === get().currentScreen.name &&- !currentScreen.id &&- get().currentScreen.id?.endsWith('_navigation')- )- return;+ if (JSON.stringify(currentScreen) === JSON.stringify(get().currentScreenRaw)) return;- if (- currentScreen.name === get().currentScreen.name &&- currentScreen.id === get().currentScreen.id- )- return;- console.log('UPDATING STATE', currentScreen.name, canGoBack);set({currentScreen: {name: currentScreen.name,@@ -78,6 +69,7 @@ const useNavigationStore = create<NavigationStore>((set, get) => ({color: color,notebookId: currentScreen.notebookId},+ currentScreenRaw: currentScreen,canGoBack,headerRightButtons: headerRightButtons});