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
handle a possible error
ammarahm-eda72026c10ba9
diff --git a/apps/mobile/src/components/AddTopicDialog/index.js b/apps/mobile/src/components/AddTopicDialog/index.jsindex 18dc32092..8af16c86f 100644--- a/apps/mobile/src/components/AddTopicDialog/index.js+++ b/apps/mobile/src/components/AddTopicDialog/index.js@@ -1,5 +1,5 @@import React, {createRef} from 'react';-import { Actions } from '../../provider/Actions';+import {Actions} from '../../provider/Actions';import {eSubscribeEvent,eUnSubscribeEvent,@@ -13,7 +13,7 @@ import BaseDialog from '../Dialog/base-dialog';import DialogButtons from '../Dialog/dialog-buttons';import DialogContainer from '../Dialog/dialog-container';import DialogHeader from '../Dialog/dialog-header';-import { updateEvent } from '../DialogManager/recievers';+import {updateEvent} from '../DialogManager/recievers';import Input from '../Input';import {Toast} from '../Toast';@@ -33,33 +33,35 @@ export class AddTopicDialog extends React.Component {}addNewTopic = async () => {- this.setState({loading: true});- if (!this.title || this.title?.trim() === '') {- ToastEvent.show({- heading: 'Topic title is required',- type: 'error',- context: 'local',- });- this.setState({loading: false});- return;- }+ try {+ this.setState({loading: true});+ if (!this.title || this.title?.trim() === '') {+ ToastEvent.show({+ heading: 'Topic title is required',+ type: 'error',+ context: 'local',+ });+ this.setState({loading: false});+ return;+ }- if (!this.toEdit) {- await db.notebooks.notebook(this.notebook.id).topics.add(this.title);- } else {- let topic = this.toEdit;- topic.title = this.title;+ if (!this.toEdit) {+ await db.notebooks.notebook(this.notebook.id).topics.add(this.title);+ } else {+ let topic = this.toEdit;+ topic.title = this.title;- await db.notebooks.notebook(topic.notebookId).topics.add(topic);- }- this.setState({loading: false});- this.close();- Navigation.setRoutesToUpdate([- Navigation.routeNames.Notebooks,- Navigation.routeNames.Notebook,- Navigation.routeNames.NotesPage,- ]);- updateEvent({type:Actions.MENU_PINS});+ await db.notebooks.notebook(topic.notebookId).topics.add(topic);+ }+ this.setState({loading: false});+ this.close();+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Notebooks,+ Navigation.routeNames.Notebook,+ Navigation.routeNames.NotesPage,+ ]);+ updateEvent({type: Actions.MENU_PINS});+ } catch (e) {}};componentDidMount() {@@ -121,7 +123,7 @@ export class AddTopicDialog extends React.Component {<InputfwdRef={this.titleRef}- onChangeText={(value) => {+ onChangeText={value => {this.title = value;}}blurOnSubmit={false}diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.jsindex 245155a7f..b1fddf6fd 100644--- a/apps/mobile/src/views/Notebook/index.js+++ b/apps/mobile/src/views/Notebook/index.js@@ -1,27 +1,27 @@-import React, { useEffect, useState } from 'react';-import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';-import { ContainerTopSection } from '../../components/Container/ContainerTopSection';-import { Header } from '../../components/Header';+import React, {useEffect, useState} from 'react';+import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';+import {ContainerTopSection} from '../../components/Container/ContainerTopSection';+import {Header} from '../../components/Header';import SelectionHeader from '../../components/SelectionHeader';import SimpleList from '../../components/SimpleList';import {eSendEvent,eSubscribeEvent,- eUnSubscribeEvent+ eUnSubscribeEvent,} from '../../services/EventManager';import Navigation from '../../services/Navigation';import SearchService from '../../services/SearchService';-import { InteractionManager } from '../../utils';-import { db } from '../../utils/DB';+import {InteractionManager} from '../../utils';+import {db} from '../../utils/DB';import {eOnNewTopicAdded,eOpenAddNotebookDialog,eOpenAddTopicDialog,- eScrollEvent+ eScrollEvent,} from '../../utils/Events';export const Notebook = ({route, navigation}) => {- const [topics, setTopics] = useState(route.params.notebook.topics);+ const [topics, setTopics] = useState(route.params.notebook?.topics);const [loading, setLoading] = useState(true);let params = route.params;let pageIsLoaded = false;@@ -29,34 +29,38 @@ export const Notebook = ({route, navigation}) => {const runAfterInteractions = (time = 400) => {InteractionManager.runAfterInteractions(() => {- let notebook = db.notebooks.notebook(params?.notebook?.id)?.data;- if (notebook) {- params.notebook = notebook;- }- params.title = params.notebook.title;- setTopics(notebook.topics);- setTimeout(() => {- if (loading) {- setLoading(false);+ try {+ let notebook = db.notebooks.notebook(params?.notebook?.id)?.data;+ if (notebook) {+ params.notebook = notebook;}- }, 10);- Navigation.routeNeedsUpdate('Notebook', () => {- onLoad();- });- eSendEvent(eScrollEvent, {name: params.title, type: 'in'});- if (params.menu) {- navigation.setOptions({- animationEnabled: true,- gestureEnabled: false,- });- } else {- navigation.setOptions({- animationEnabled: true,- gestureEnabled: Platform.OS === 'ios',+ params.title = params.notebook.title;+ if (notebook) {+ setTopics(notebook.topics);+ }+ setTimeout(() => {+ if (loading) {+ setLoading(false);+ }+ }, 10);+ Navigation.routeNeedsUpdate('Notebook', () => {+ onLoad();});- }- updateSearch();- ranAfterInteractions = false;+ eSendEvent(eScrollEvent, {name: params.title, type: 'in'});+ if (params.menu) {+ navigation.setOptions({+ animationEnabled: true,+ gestureEnabled: false,+ });+ } else {+ navigation.setOptions({+ animationEnabled: true,+ gestureEnabled: Platform.OS === 'ios',+ });+ }+ updateSearch();+ ranAfterInteractions = false;+ } catch (e) {}}, time);};const onLoad = data => {@@ -128,9 +132,8 @@ export const Notebook = ({route, navigation}) => {return (<>- <SelectionHeader screen="Notebook" />+ <SelectionHeader screen="Notebook" /><ContainerTopSection>-<Headertitle={params.title}isBack={!params.menu}diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.jsindex 4a89660ca..08f723594 100644--- a/apps/mobile/src/views/Notes/index.js+++ b/apps/mobile/src/views/Notes/index.js@@ -48,7 +48,7 @@ export const Notes = ({route, navigation}) => {} else {_notes = db.notebooks.notebook(params.notebookId)- .topics.topic(params.id).all;+ ?.topics.topic(params.id)?.all}if ((params.type === 'tag' || params.type === 'color') &&