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
fix topic & notebook adding does not update the screens
ammarahm-ede58d338abed3
diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.jsindex 3ba9f0845..4116326c0 100644--- a/apps/mobile/src/components/AddNotebookDialog/index.js+++ b/apps/mobile/src/components/AddNotebookDialog/index.js@@ -14,8 +14,10 @@ import {notesnook} from '../../../e2e/test.ids';import {Actions} from '../../provider/Actions';import {DDS} from '../../services/DeviceDetection';import {ToastEvent} from '../../services/EventManager';+import Navigation from '../../services/Navigation';import {db} from '../../utils/DB';import {ph, pv, SIZE} from '../../utils/SizeUtils';+import {sleep} from '../../utils/TimeUtils';import {ActionIcon} from '../ActionIcon';import DialogButtons from '../Dialog/dialog-buttons';import DialogHeader from '../Dialog/dialog-header';@@ -135,8 +137,17 @@ export class AddNotebookDialog extends React.Component {let {topics} = this.state;let edit = this.props.toEdit;- if (!this.title || this.title?.trim().length === 0)- return ToastEvent.show('Notebook title is required', 'error', 'local');+ if (!this.title || this.title?.trim().length === 0) {+ ToastEvent.show({+ heading: 'Notebook title is required',+ type: 'error',+ context: 'local',+ });+ this.setState({+ loading: false,+ });+ return;+ }let id = edit && edit.id ? edit.id : null;@@ -191,8 +202,16 @@ export class AddNotebookDialog extends React.Component {id: id,});}+ updateEvent({type: Actions.MENU_PINS});+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Notebooks,+ Navigation.routeNames.Notebook,+ Navigation.routeNames.NotesPage,+ ]);+ this.setState({+ loading: false,+ });this.close();- Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]);};onSubmit = (forward = true) => {@@ -242,13 +261,7 @@ export class AddNotebookDialog extends React.Component {render() {const {colors, toEdit} = this.props;- const {- titleFocused,- descFocused,- topics,- visible,- topicInputFocused,- } = this.state;+ const {topics, visible, topicInputFocused} = this.state;if (!visible) return null;return (<Modal@@ -256,8 +269,9 @@ export class AddNotebookDialog extends React.Component {transparent={true}animatedanimationType={DDS.isTab ? 'fade' : 'slide'}- onShow={() => {+ onShow={async () => {this.topicsToDelete = [];+ await sleep(300);this.titleRef?.focus();}}onRequestClose={this.close}>diff --git a/apps/mobile/src/components/AddTopicDialog/index.js b/apps/mobile/src/components/AddTopicDialog/index.jsindex 1bd58dd98..f8530e29b 100644--- a/apps/mobile/src/components/AddTopicDialog/index.js+++ b/apps/mobile/src/components/AddTopicDialog/index.js@@ -1,21 +1,21 @@-import React, { createRef } from 'react';+import React, {createRef} from 'react';+import { Actions } from '../../provider/Actions';import {eSubscribeEvent,eUnSubscribeEvent,- ToastEvent+ ToastEvent,} from '../../services/EventManager';-import { db } from '../../utils/DB';-import {- eCloseAddTopicDialog,-- eOpenAddTopicDialog-} from '../../utils/Events';+import Navigation from '../../services/Navigation';+import {db} from '../../utils/DB';+import {eCloseAddTopicDialog, eOpenAddTopicDialog} from '../../utils/Events';+import {sleep} from '../../utils/TimeUtils';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 Input from '../Input';-import { Toast } from '../Toast';+import {Toast} from '../Toast';export class AddTopicDialog extends React.Component {constructor(props) {@@ -29,26 +29,37 @@ export class AddTopicDialog extends React.Component {this.title;this.titleRef = createRef();this.notebook = null;+ this.toEdit = null;}addNewTopic = async () => {this.setState({loading: true});- if (!this.title)- return ToastEvent.show('Title is required', 'error', 'local');+ if (!this.title || this.title?.trim() === '') {+ ToastEvent.show({+ heading: 'Topic title is required',+ type: 'error',+ context: 'local',+ });+ this.setState({loading: false});+ return;+ }- if (!this.props.toEdit) {+ if (!this.toEdit) {await db.notebooks.notebook(this.notebook.id).topics.add(this.title);} else {- let topic = this.props.toEdit;+ 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});};componentDidMount() {@@ -60,12 +71,17 @@ export class AddTopicDialog extends React.Component {eUnSubscribeEvent(eCloseAddTopicDialog, this.close);}- open = async (notebookId) => {- let id = notebookId || this.props.notebookID;- this.notebook = await db.notebooks.notebook(id).data;- if (this.props.toEdit) {- this.title = this.props.toEdit.title;+ open = async ({notebookId, toEdit}) => {+ let id = notebookId;+ if (id) {+ this.notebook = await db.notebooks.notebook(id).data;}+ this.toEdit = toEdit;++ if (this.toEdit) {+ this.title = this.toEdit.title;+ }+this.setState({visible: true,});@@ -74,6 +90,7 @@ export class AddTopicDialog extends React.Component {this.props.close();this.title = null;this.notebook = null;+ this.toEdit = null;this.setState({visible: false,});@@ -81,11 +98,11 @@ export class AddTopicDialog extends React.Component {render() {const {visible} = this.state;- const {colors, toEdit} = this.props;if (!visible) return null;return (<BaseDialog- onShow={() => {+ onShow={async () => {+ await sleep(300);this.titleRef.current?.focus();}}statusBarTranslucent={false}@@ -94,8 +111,12 @@ export class AddTopicDialog extends React.Component {<DialogContainer><DialogHeadericon="book-outline"- title={toEdit ? 'Edit Topic' : 'New Topic'}- paragraph={'Add a new topic to ' + this.notebook.title}+ title={this.toEdit ? 'Edit Topic' : 'New Topic'}+ paragraph={+ this.toEdit+ ? 'Edit title of the topic'+ : 'Add a new topic to ' + this.notebook.title+ }/><Input@@ -104,13 +125,13 @@ export class AddTopicDialog extends React.Component {this.title = value;}}blurOnSubmit={false}- defaultValue={toEdit ? toEdit.title : null}+ defaultValue={this.toEdit ? this.toEdit.title : null}placeholder="Enter title of topic"onSubmit={() => this.addNewTopic()}/><DialogButtons- positiveTitle={toEdit ? 'Save' : 'Add'}+ positiveTitle={this.toEdit ? 'Save' : 'Add'}onPressNegative={() => this.close()}onPressPositive={() => this.addNewTopic()}loading={this.state.loading}diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.jsindex 933e10803..e98e09ba2 100644--- a/apps/mobile/src/components/DialogManager/index.js+++ b/apps/mobile/src/components/DialogManager/index.js@@ -24,7 +24,8 @@ import {eShowGetPremium,eThemeUpdated,} from '../../utils/Events';-import { EditorSettings } from '../../views/Editor/EditorSettings';+import { sleep } from '../../utils/TimeUtils';+import {EditorSettings} from '../../views/Editor/EditorSettings';import {ActionSheetComponent} from '../ActionSheetComponent';import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';import {AddNotebookDialog} from '../AddNotebookDialog';@@ -118,13 +119,13 @@ export class DialogManager extends Component {}};- showAddTopic = (notebook) => {- if (notebook) {- this.setState({- item: notebook,- });- }- this.addTopicsDialog.open();+ showAddTopic = () => {+ let item = this.state.item;+ console.log(item);+ this.addTopicsDialog.open({+ notebookId: item?.type !== 'topic' ? item.id : item.notebookId,+ toEdit:item?.type === 'topic' ? item : null,+ });};hideAddTopic = () => {@@ -153,8 +154,6 @@ export class DialogManager extends Component {eSubscribeEvent(eOpenAddNotebookDialog, this.showAddNotebook);eSubscribeEvent(eCloseAddNotebookDialog, this.hideAddNotebook);--eSubscribeEvent(eOpenLoginDialog, this.showLoginDialog);eSubscribeEvent(eCloseLoginDialog, this.hideLoginDialog);@@ -204,7 +203,7 @@ export class DialogManager extends Component {showAddNotebook = (data) => {this.setState({- item: data.item ? data.item : {},+ item: data.item ? data.item : data.type === "notebook" ? data : {},},() => {this.addNotebooksDialog.open();@@ -239,8 +238,8 @@ export class DialogManager extends Component {novault: true,locked: true,deleteNote: true,- title:'Delete note',- description:"Unlock to delete note."+ title: 'Delete note',+ description: 'Unlock to delete note.',});} else {this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));@@ -255,8 +254,8 @@ export class DialogManager extends Component {openVault({item: this.state.item,novault: false,- title:'Create vault',- description:"Set a password to create a vault and lock note."+ title: 'Create vault',+ description: 'Set a password to create a vault and lock note.',});break;}@@ -265,8 +264,8 @@ export class DialogManager extends Component {item: this.state.item,novault: true,locked: true,- title:'Open note',- description:"Unlock note to open in editor"+ title: 'Lock note',+ description: 'Give access to vault to lock this note.',});break;}@@ -276,8 +275,8 @@ export class DialogManager extends Component {novault: true,locked: true,permanant: true,- title:'Unlock note',- description:"Remove note from the vault."+ title: 'Unlock note',+ description: 'Remove note from the vault.',});break;}@@ -351,13 +350,10 @@ export class DialogManager extends Component {/><AddTopicDialogref={(ref) => (this.addTopicsDialog = ref)}- toEdit={item?.type === 'topic' ? item : null}- notebookID={item?.type !== 'topic' ? item.id : item.notebookId}close={() => {- console.log("closing")this.setState({- item:{}- })+ item: {},+ });}}colors={colors}/>