You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-09-16 08:56:40 +02:00
More clean up
This commit is contained in:
@@ -7,7 +7,6 @@ import { Folder } from 'lib/models/folder.js'
|
||||
import { BaseModel } from 'lib/base-model.js'
|
||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||
import { reg } from 'lib/registry.js';
|
||||
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
||||
import { dialogs } from 'lib/dialogs.js';
|
||||
import { _ } from 'lib/locale.js';
|
||||
@@ -79,7 +78,11 @@ class FolderScreenComponent extends BaseScreenComponent {
|
||||
folder: folder,
|
||||
});
|
||||
|
||||
await NotesScreenUtils.openNoteList(folder.id);
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Notes',
|
||||
folderId: folder.id,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@@ -15,7 +15,6 @@ import marked from 'lib/marked.js';
|
||||
import { reg } from 'lib/registry.js';
|
||||
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
||||
import { dialogs } from 'lib/dialogs.js';
|
||||
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||
import { globalStyle } from 'lib/components/global-style.js';
|
||||
import DialogBox from 'react-native-dialogbox';
|
||||
|
||||
@@ -223,7 +222,12 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
let folderId = note.parent_id;
|
||||
|
||||
await Note.delete(note.id);
|
||||
await NotesScreenUtils.openNoteList(folderId);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Notes',
|
||||
folderId: folderId,
|
||||
});
|
||||
|
||||
reg.scheduleSync();
|
||||
}
|
||||
|
@@ -1,46 +0,0 @@
|
||||
import { Note } from 'lib/models/note.js'
|
||||
import { Folder } from 'lib/models/folder.js'
|
||||
import { Log } from 'lib/log.js'
|
||||
|
||||
class NotesScreenUtils {
|
||||
|
||||
static openNoteList(folderId) {
|
||||
const state = this.store.getState();
|
||||
|
||||
let options = {
|
||||
orderBy: state.notesOrder.orderBy,
|
||||
orderByDir: state.notesOrder.orderByDir,
|
||||
};
|
||||
|
||||
return Note.previews(folderId, options).then((notes) => {
|
||||
this.dispatch({
|
||||
type: 'NOTES_UPDATE_ALL',
|
||||
notes: notes,
|
||||
});
|
||||
|
||||
this.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Notes',
|
||||
folderId: folderId,
|
||||
});
|
||||
}).catch((error) => {
|
||||
Log.warn('Cannot load notes from ' + folderId, error);
|
||||
});
|
||||
}
|
||||
|
||||
static async openDefaultNoteList() {
|
||||
const selectedFolder = await Folder.defaultFolder();
|
||||
|
||||
if (selectedFolder) {
|
||||
this.openNoteList(selectedFolder.id);
|
||||
} else {
|
||||
this.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Welcome',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { NotesScreenUtils }
|
@@ -1,15 +1,16 @@
|
||||
import React, { Component } from 'react';
|
||||
import { View, Button, Picker } from 'react-native';
|
||||
import { connect } from 'react-redux'
|
||||
import { reg } from 'lib/registry.js';
|
||||
import { Log } from 'lib/log.js'
|
||||
import { NoteList } from 'lib/components/note-list.js'
|
||||
import { Folder } from 'lib/models/folder.js'
|
||||
import { Note } from 'lib/models/note.js'
|
||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||
import { MenuOption, Text } from 'react-native-popup-menu';
|
||||
import { _ } from 'lib/locale.js';
|
||||
import { ActionButton } from 'lib/components/action-button.js';
|
||||
import { dialogs } from 'lib/dialogs.js';
|
||||
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||
import DialogBox from 'react-native-dialogbox';
|
||||
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
||||
|
||||
@@ -19,12 +20,55 @@ class NotesScreenComponent extends BaseScreenComponent {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.refreshNotes();
|
||||
}
|
||||
|
||||
async componentWillReceiveProps(newProps) {
|
||||
if (newProps.notesOrder.orderBy != this.props.notesOrder.orderBy ||
|
||||
newProps.notesOrder.orderByDir != this.props.notesOrder.orderByDir ||
|
||||
newProps.selectedFolderId != this.props.selectedFolderId) {
|
||||
await this.refreshNotes(newProps);
|
||||
}
|
||||
}
|
||||
|
||||
async refreshNotes(props = null) {
|
||||
if (props === null) props = this.props;
|
||||
|
||||
let options = {
|
||||
orderBy: props.notesOrder.orderBy,
|
||||
orderByDir: props.notesOrder.orderByDir,
|
||||
};
|
||||
|
||||
const source = JSON.stringify({
|
||||
options: options,
|
||||
selectedFolderId: props.selectedFolderId,
|
||||
});
|
||||
|
||||
let folder = Folder.byId(props.folders, props.selectedFolderId);
|
||||
|
||||
if (source == props.notesSource) return;
|
||||
|
||||
const notes = await Note.previews(props.selectedFolderId, options);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'NOTES_UPDATE_ALL',
|
||||
notes: notes,
|
||||
notesSource: source,
|
||||
});
|
||||
}
|
||||
|
||||
deleteFolder_onPress(folderId) {
|
||||
dialogs.confirm(this, _('Delete notebook?')).then((ok) => {
|
||||
if (!ok) return;
|
||||
|
||||
Folder.delete(folderId).then(() => {
|
||||
return NotesScreenUtils.openDefaultNoteList();
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Welcome',
|
||||
});
|
||||
|
||||
reg.scheduleSync();
|
||||
}).catch((error) => {
|
||||
alert(error.message);
|
||||
});
|
||||
@@ -52,8 +96,11 @@ class NotesScreenComponent extends BaseScreenComponent {
|
||||
let folder = Folder.byId(this.props.folders, this.props.selectedFolderId);
|
||||
|
||||
if (!folder) {
|
||||
NotesScreenUtils.openDefaultNoteList();
|
||||
return null;
|
||||
return (
|
||||
<View style={this.styles().screen}>
|
||||
<ScreenHeader title={title} menuOptions={this.menuOptions()} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
let title = folder ? folder.title : null;
|
||||
@@ -76,6 +123,9 @@ const NotesScreen = connect(
|
||||
return {
|
||||
folders: state.folders,
|
||||
selectedFolderId: state.selectedFolderId,
|
||||
notes: state.notes,
|
||||
notesOrder: state.notesOrder,
|
||||
notesSource: state.notesSource,
|
||||
};
|
||||
}
|
||||
)(NotesScreenComponent)
|
||||
|
@@ -6,7 +6,6 @@ import { Log } from 'lib/log.js';
|
||||
import { Note } from 'lib/models/note.js';
|
||||
import { Setting } from 'lib/models/setting.js';
|
||||
import { FoldersScreenUtils } from 'lib/components/screens/folders-utils.js'
|
||||
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||
import { Synchronizer } from 'lib/synchronizer.js';
|
||||
import { reg } from 'lib/registry.js';
|
||||
import { _ } from 'lib/locale.js';
|
||||
@@ -67,7 +66,11 @@ class SideMenuContentComponent extends Component {
|
||||
folder_press(folder) {
|
||||
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
|
||||
|
||||
NotesScreenUtils.openNoteList(folder.id);
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Notes',
|
||||
folderId: folder.id,
|
||||
});
|
||||
}
|
||||
|
||||
async synchronize_press() {
|
||||
|
@@ -17,7 +17,6 @@ import { BaseModel } from 'lib/base-model.js'
|
||||
import { JoplinDatabase } from 'lib/joplin-database.js'
|
||||
import { Database } from 'lib/database.js'
|
||||
import { NotesScreen } from 'lib/components/screens/notes.js'
|
||||
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||
import { NoteScreen } from 'lib/components/screens/note.js'
|
||||
import { ConfigScreen } from 'lib/components/screens/config.js'
|
||||
import { FolderScreen } from 'lib/components/screens/folder.js'
|
||||
@@ -38,6 +37,7 @@ import { PoorManIntervals } from 'lib/poor-man-intervals.js';
|
||||
|
||||
let defaultState = {
|
||||
notes: [],
|
||||
notesSource: '',
|
||||
folders: [],
|
||||
selectedNoteId: null,
|
||||
selectedItemType: 'note',
|
||||
@@ -179,6 +179,7 @@ const reducer = (state = defaultState, action) => {
|
||||
|
||||
newState = Object.assign({}, state);
|
||||
newState.notes = action.notes;
|
||||
newState.notesSource = action.notesSource;
|
||||
break;
|
||||
|
||||
// Insert the note into the note list if it's new, or
|
||||
@@ -362,8 +363,6 @@ async function initialize(dispatch, backButtonHandler) {
|
||||
|
||||
reg.dispatch = dispatch;
|
||||
BaseModel.dispatch = dispatch;
|
||||
NotesScreenUtils.dispatch = dispatch;
|
||||
NotesScreenUtils.store = store;
|
||||
FoldersScreenUtils.dispatch = dispatch;
|
||||
BaseModel.db_ = db;
|
||||
|
||||
@@ -407,15 +406,19 @@ async function initialize(dispatch, backButtonHandler) {
|
||||
let folderId = Setting.value('activeFolderId');
|
||||
let folder = await Folder.load(folderId);
|
||||
|
||||
// dispatch({
|
||||
// type: 'Navigation/NAVIGATE',
|
||||
// routeName: 'Config',
|
||||
// });
|
||||
if (!folder) folder = await Folder.defaultFolder();
|
||||
|
||||
if (folder) {
|
||||
await NotesScreenUtils.openNoteList(folderId);
|
||||
if (!folder) {
|
||||
dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Welcome',
|
||||
});
|
||||
} else {
|
||||
await NotesScreenUtils.openDefaultNoteList();
|
||||
dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Notes',
|
||||
folderId: folder.id,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
reg.logger().error('Initialization error:', error);
|
||||
|
Reference in New Issue
Block a user