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
simplify navigation
ammarahm-edfbaad666e96a
diff --git a/apps/mobile/src/components/header/title.js b/apps/mobile/src/components/header/title.jsindex 64c2a8500..d27313248 100644--- a/apps/mobile/src/components/header/title.js+++ b/apps/mobile/src/components/header/title.js@@ -1,6 +1,7 @@import React, { useEffect, useState } from 'react';import { View } from 'react-native';import Animated, { Layout } from 'react-native-reanimated';+import Notebook from '../../screens/notebook';import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';import Navigation from '../../services/navigation';import useNavigationStore from '../../stores/use-navigation-store';@@ -60,17 +61,7 @@ export const Title = () => {function navigateToNotebook() {if (!isTopic) return;- Navigation.navigate(- {- name: 'Notebook',- id: isTopic.id,- type: isTopic.type- },- {- notebook: isTopic,- title: isTopic.title- }- );+ Notebook.navigate(notebook, true);}return (diff --git a/apps/mobile/src/components/listitems/note/index.js b/apps/mobile/src/components/listitems/note/index.jsindex 7fb3e8db3..45e852ee9 100644--- a/apps/mobile/src/components/listitems/note/index.js+++ b/apps/mobile/src/components/listitems/note/index.js@@ -3,81 +3,62 @@ import React from 'react';import { View } from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import { notesnook } from '../../../../e2e/test.ids';-import { useThemeStore } from '../../../stores/use-theme-store';+import { TaggedNotes } from '../../../screens/notes/tagged';+import { TopicNotes } from '../../../screens/notes/topic-notes';import { useSettingStore } from '../../../stores/use-setting-store';-import { eSendEvent } from '../../../services/event-manager';-import Navigation from '../../../services/navigation';+import { useThemeStore } from '../../../stores/use-theme-store';import { COLORS_NOTE } from '../../../utils/color-scheme';import { db } from '../../../utils/database';-import { refreshNotesPage } from '../../../utils/events';import { SIZE } from '../../../utils/size';-import { IconButton } from '../../ui/icon-button';+import { Properties } from '../../properties';import { Button } from '../../ui/button';+import { IconButton } from '../../ui/icon-button';import { TimeSince } from '../../ui/time-since';-import { Properties } from '../../properties';import Heading from '../../ui/typography/heading';import Paragraph from '../../ui/typography/paragraph';const navigateToTopic = topic => {- Navigation.navigate(- {- name: 'NotesPage',- title: topic.title,- id: topic.id,- type: topic.type- },- { ...topic, menu: false, get: 'topics' }- );+ TopicNotes.navigate(topic, true);};function navigateToTag(item) {const tag = db.tags.tag(item.id);if (!tag) return;- Navigation.navigate(- {- name: 'NotesPage',- title: '#' + tag.title,- id: tag.id,- type: tag.type- },- {- ...tag,- type: 'tag',- get: 'tagged'- }- );+ TaggedNotes.navigate(tag, true);}const showActionSheet = item => {Properties.present(item);};-const NoteItem = ({ item, isTrash, tags, dateBy = 'dateCreated', noOpen = false }) => {- const colors = useThemeStore(state => state.colors);- const notesListMode = useSettingStore(state => state.settings.notesListMode);- const compactMode = notesListMode === 'compact';- const attachmentCount = db.attachments?.ofNote(item.id, 'all')?.length || 0;+function getNotebook(item) {+ const isTrash = item.type === 'trash';+ if (isTrash || !item.notebooks || item.notebooks.length < 1) return [];+ let item_notebook = item.notebooks?.slice(0, 1)[0];+ let notebook = db.notebooks.notebook(item_notebook.id);- function getNotebook() {- if (isTrash || !item.notebooks || item.notebooks.length < 1) return [];- let item_notebook = item.notebooks?.slice(0, 1)[0];- let notebook = db.notebooks.notebook(item_notebook.id);+ if (!notebook) return [];+ let topic = notebook.topics.topic(item_notebook.topics[0])?._topic;- if (!notebook) return [];- let topic = notebook.topics.topic(item_notebook.topics[0])?._topic;+ if (!topic) return [];- if (!topic) return [];+ notebook = notebook.data;- notebook = notebook.data;+ return [+ {+ title: `${notebook?.title} › ${topic?.title}`,+ notebook: notebook,+ topic: topic+ }+ ];+}- return [- {- title: `${notebook?.title} › ${topic?.title}`,- notebook: notebook,- topic: topic- }- ];- }+const NoteItem = ({ item, isTrash, tags, dateBy = 'dateCreated', noOpen = false }) => {+ const colors = useThemeStore(state => state.colors);+ const notesListMode = useSettingStore(state => state.settings.notesListMode);+ const compactMode = notesListMode === 'compact';+ const attachmentCount = db.attachments?.ofNote(item.id, 'all')?.length || 0;+ const notebooks = React.useMemo(() => getNotebook(item), [item]);return (<>@@ -97,7 +78,7 @@ const NoteItem = ({ item, isTrash, tags, dateBy = 'dateCreated', noOpen = falsemarginBottom: 2.5}}>- {getNotebook().map(_item => (+ {notebooks.map(_item => (<Buttontitle={_item.title}key={_item}diff --git a/apps/mobile/src/components/listitems/notebook/index.js b/apps/mobile/src/components/listitems/notebook/index.jsindex e2e196ea4..0e75461d9 100644--- a/apps/mobile/src/components/listitems/notebook/index.js+++ b/apps/mobile/src/components/listitems/notebook/index.js@@ -2,41 +2,32 @@ import React from 'react';import { View } from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import { notesnook } from '../../../../e2e/test.ids';-import { useThemeStore } from '../../../stores/use-theme-store';+import { TopicNotes } from '../../../screens/notes/topic-notes';import { useSettingStore } from '../../../stores/use-setting-store';-import { eSendEvent } from '../../../services/event-manager';-import Navigation from '../../../services/navigation';+import { useThemeStore } from '../../../stores/use-theme-store';import { getTotalNotes, history } from '../../../utils';-import { refreshNotesPage } from '../../../utils/events';import { SIZE } from '../../../utils/size';-import { IconButton } from '../../ui/icon-button';-import { Button } from '../../ui/button';import { Properties } from '../../properties';+import { Button } from '../../ui/button';+import { IconButton } from '../../ui/icon-button';import Heading from '../../ui/typography/heading';import Paragraph from '../../ui/typography/paragraph';+const showActionSheet = item => {+ Properties.present(item);+};++const navigateToTopic = topic => {+ if (history.selectedItemsList.length > 0) return;+ TopicNotes.navigate(topic, true);+};+export const NotebookItem = ({ item, isTopic = false, notebookID, isTrash, dateBy }) => {const colors = useThemeStore(state => state.colors);const notebooksListMode = useSettingStore(state => state.settings.notebooksListMode);const compactMode = notebooksListMode === 'compact';const topics = item.topics?.slice(0, 3) || [];const totalNotes = getTotalNotes(item);- const showActionSheet = () => {- Properties.present(item);- };-- const navigateToTopic = topic => {- if (history.selectedItemsList.length > 0) return;- Navigation.navigate(- {- name: 'NotesPage',- title: topic.title,- id: topic.id,- type: topic.type- },- { ...topic, menu: false, get: 'topics' }- );- };return (<>@@ -190,7 +181,7 @@ export const NotebookItem = ({ item, isTopic = false, notebookID, isTrash, dateBname="dots-horizontal"testID={notesnook.ids.notebook.menu}size={SIZE.xl}- onPress={showActionSheet}+ onPress={() => showActionSheet(item)}customStyle={{justifyContent: 'center',height: 35,diff --git a/apps/mobile/src/components/listitems/notebook/wrapper.js b/apps/mobile/src/components/listitems/notebook/wrapper.jsindex 0787bdca9..dc3cdacc6 100644--- a/apps/mobile/src/components/listitems/notebook/wrapper.js+++ b/apps/mobile/src/components/listitems/notebook/wrapper.js@@ -11,67 +11,68 @@ import { db } from '../../../utils/database';import { presentDialog } from '../../dialog/functions';import SelectionWrapper from '../selection-wrapper';+export const openNotebookTopic = item => {+ const isTrash = item.type === 'trash';+ if (history.selectedItemsList.length > 0 && history.selectionMode) {+ useSelectionStore.getState().setSelectedItem(item);+ return;+ } else {+ history.selectedItemsList = [];+ }++ if (isTrash) {+ presentDialog({+ title: `Restore ${item.itemType}`,+ paragraph: `Restore or delete ${item.itemType} forever`,+ positiveText: 'Restore',+ negativeText: 'Delete',+ positivePress: async () => {+ await db.trash.restore(item.id);+ Navigation.queueRoutesForUpdate(+ 'Tags',+ 'Notes',+ 'Notebooks',+ 'Favorites',+ 'Trash',+ 'TaggedNotes',+ 'ColoredNotes',+ 'TopicNotes'+ );+ useSelectionStore.getState().setSelectionMode(false);+ ToastEvent.show({+ heading: 'Restore successful',+ type: 'success'+ });+ },+ onClose: async () => {+ await db.trash.delete(item.id);+ useTrashStore.getState().setTrash();+ useSelectionStore.getState().setSelectionMode(false);+ ToastEvent.show({+ heading: 'Permanantly deleted items',+ type: 'success',+ context: 'local'+ });+ }+ });+ return;+ }+ if (item.type === 'topic') {+ TopicNotes.navigate(item, true);+ } else {+ Notebook.navigate(item, true);+ }+};+export const NotebookWrapper = React.memo(({ item, index, dateBy }) => {const isTrash = item.type === 'trash';- const setSelectedItem = useSelectionStore(state => state.setSelectedItem);-- const onPress = () => {- if (history.selectedItemsList.length > 0 && history.selectionMode) {- setSelectedItem(item);- return;- } else {- history.selectedItemsList = [];- }- if (isTrash) {- presentDialog({- title: `Restore ${item.itemType}`,- paragraph: `Restore or delete ${item.itemType} forever`,- positiveText: 'Restore',- negativeText: 'Delete',- positivePress: async () => {- await db.trash.restore(item.id);- Navigation.queueRoutesForUpdate(- 'Tags',- 'Notes',- 'Notebooks',- 'Favorites',- 'Trash',- 'TaggedNotes',- 'ColoredNotes',- 'TopicNotes'- );- useSelectionStore.getState().setSelectionMode(false);- ToastEvent.show({- heading: 'Restore successful',- type: 'success'- });- },- onClose: async () => {- await db.trash.delete(item.id);- useTrashStore.getState().setTrash();- useSelectionStore.getState().setSelectionMode(false);- ToastEvent.show({- heading: 'Permanantly deleted items',- type: 'success',- context: 'local'- });- }- });- return;- }- if (item.type === 'topic') {- TopicNotes.navigate(item, true);- } else {- Notebook.navigate(item, true);- }- };return (<SelectionWrapperpinned={item.pinned}index={index}- onPress={onPress}+ onPress={openNotebookTopic}height={item.type === 'topic' ? 80 : 110}item={item}>diff --git a/apps/mobile/src/components/properties/notebooks.js b/apps/mobile/src/components/properties/notebooks.jsindex 351a6f8fb..7c45b98be 100644--- a/apps/mobile/src/components/properties/notebooks.js+++ b/apps/mobile/src/components/properties/notebooks.js@@ -10,6 +10,8 @@ import { SIZE } from '../../utils/size';import { Button } from '../ui/button';import { PressableButton } from '../ui/pressable';import Heading from '../ui/typography/heading';+import { TopicNotes } from '../../screens/notes/topic-notes';+import Notebook from '../../screens/notebook';export default function Notebooks({ note, close }) {const colors = useThemeStore(state => state.colors);@@ -44,31 +46,13 @@ export default function Notebooks({ note, close }) {const navigateNotebook = id => {let item = db.notebooks.notebook(id)?.data;if (!item) return;- let params = {- menu: false,- notebook: item,- title: item.title- };- let currentScreen = {- name: 'Notebook',- title: item.title,- id: item.id,- type: item.type- };- Navigation.navigate(currentScreen, params);+ Notebook.navigate(item, true);};const navigateTopic = (id, notebookId) => {let item = db.notebooks.notebook(notebookId)?.topics?.topic(id)?._topic;if (!item) return;- let params = { ...item, menu: false };- let currentScreen = {- name: 'NotesPage',- title: item.title,- id: item.id,- type: item.type- };- Navigation.navigate(currentScreen, params);+ TopicNotes.navigate(item, true);};return !note.notebooks || note.notebooks.length === 0 ? null : (diff --git a/apps/mobile/src/components/properties/tags.js b/apps/mobile/src/components/properties/tags.jsindex 348bcb6f1..1bc52ef3a 100644--- a/apps/mobile/src/components/properties/tags.js+++ b/apps/mobile/src/components/properties/tags.js@@ -8,6 +8,7 @@ import { eOpenTagsDialog, refreshNotesPage } from '../../utils/events';import { SIZE } from '../../utils/size';import { sleep } from '../../utils/time';import { Button } from '../ui/button';+import { TaggedNotes } from '../../screens/notes/tagged';export const Tags = ({ item, close }) => {const colors = useThemeStore(state => state.colors);@@ -59,20 +60,7 @@ const TagItem = ({ tag, close }) => {const onPress = async () => {let tags = db.tags.all;let _tag = tags.find(t => t.title === tag);- let params = {- ..._tag,- type: 'tag',- get: 'tagged'- };- Navigation.navigate(- {- name: 'NotesPage',- title: '#' + _tag.title,- id: _tag.id,- type: _tag.type- },- params- );+ TaggedNotes.navigate(_tag, true);await sleep(300);close();};diff --git a/apps/mobile/src/components/properties/topics.js b/apps/mobile/src/components/properties/topics.jsindex 4c3f24f24..55bec4526 100644--- a/apps/mobile/src/components/properties/topics.js+++ b/apps/mobile/src/components/properties/topics.js@@ -1,20 +1,13 @@import React from 'react';import { View } from 'react-native';-import Navigation from '../../services/navigation';+import { TopicNotes } from '../../screens/notes/topic-notes';import { SIZE } from '../../utils/size';import { Button } from '../ui/button';export const Topics = ({ item, close }) => {const open = topic => {close();- let params = { ...topic, menu: false, get: 'topics' };- let currentScreen = {- name: 'NotesPage',- title: topic.title,- id: topic.id,- type: topic.type- };- Navigation.navigate(currentScreen, params);+ TopicNotes.navigate(topic, true);};const renderItem = topic => (diff --git a/apps/mobile/src/components/sidemenu/colorsection.js b/apps/mobile/src/components/sidemenu/colorsection.jsindex 1c130f477..1da326076 100644--- a/apps/mobile/src/components/sidemenu/colorsection.js+++ b/apps/mobile/src/components/sidemenu/colorsection.js@@ -12,6 +12,7 @@ import { presentDialog } from '../dialog/functions';import { PressableButton } from '../ui/pressable';import Heading from '../ui/typography/heading';import Paragraph from '../ui/typography/paragraph';+import { ColoredNotes } from '../../screens/notes/colored';export const ColorSection = React.memo(() => {@@ -61,21 +62,7 @@ const ColorItem = React.memo(}, [headerTextState]);const onPress = item => {- let params = {- ...item,- type: 'color',- menu: true,- get: 'colored'- };- Navigation.navigate(- {- name: 'NotesPage',- title: alias.slice(0, 1).toUpperCase() + alias.slice(1),- id: item.id,- type: 'color'- },- params- );+ ColoredNotes.navigate(item, false);setImmediate(() => {Navigation.closeDrawer();diff --git a/apps/mobile/src/components/sidemenu/menuitem.js b/apps/mobile/src/components/sidemenu/menuitem.jsindex aff8df38a..a5cfc2701 100644--- a/apps/mobile/src/components/sidemenu/menuitem.js+++ b/apps/mobile/src/components/sidemenu/menuitem.js@@ -24,7 +24,7 @@ export const MenuItem = React.memo(if (item.func) {item.func();} else {- Navigation.navigate({ name: item.name }, { menu: true });+ Navigation.navigate({ name: item.name }, { canGoBack: false });}if (item.close) {setImmediate(() => {