1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
Laurent Cozic 2017-05-24 20:11:37 +00:00
parent c5584d70a6
commit 276ac0e180
6 changed files with 96 additions and 42 deletions

View File

@ -6,28 +6,12 @@ import { ItemListComponent } from 'src/components/item-list.js';
import { Note } from 'src/models/note.js';
import { Folder } from 'src/models/folder.js';
import { _ } from 'src/locale.js';
import { NoteFolderService } from 'src/services/note-folder-service.js';
class FolderListComponent extends ItemListComponent {
listView_itemPress = (folderId) => {
Folder.load(folderId).then((folder) => {
Log.info('Current folder', folder);
Note.previews(folderId).then((notes) => {
this.props.dispatch({
type: 'NOTES_UPDATE_ALL',
notes: notes,
});
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Notes',
folderId: folderId,
});
}).catch((error) => {
Log.warn('Cannot load notes', error);
});
});
NoteFolderService.openNoteList(folderId);
}
}

View File

@ -25,7 +25,7 @@ class ScreenHeaderComponent extends Component {
// Note: this is hardcoded for now because navigation.state doesn't tell whether
// it's possible to go back or not. Maybe it's possible to get this information
// from somewhere else.
return this.props.navState.routeName != 'Folders';
return this.props.navState.routeName != 'Notes';
}
sideMenuButton_press = () => {

View File

@ -0,0 +1,31 @@
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'src/log.js'
import { Folder } from 'src/models/folder.js'
import { ScreenHeader } from 'src/components/screen-header.js';
import { NoteFolderService } from 'src/services/note-folder-service.js';
class LoadingScreenComponent extends React.Component {
static navigationOptions = (options) => {
return { header: null };
}
render() {
return (
<View style={{flex: 1}}>
<Text>Loading...</Text>
</View>
);
}
}
const LoadingScreen = connect(
(state) => {
return {};
}
)(LoadingScreenComponent)
export { LoadingScreen };

View File

@ -1,6 +1,8 @@
import { connect } from 'react-redux'
import { Button } from 'react-native';
import { Log } from 'src/log.js';
import { Note } from 'src/models/note.js';
import { NoteFolderService } from 'src/services/note-folder-service.js';
const React = require('react');
const {
@ -40,15 +42,11 @@ const styles = StyleSheet.create({
class SideMenuContentComponent extends Component {
folder_press(folder) {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Notes',
folderId: folder.id,
});
this.props.dispatch({
type: 'SIDE_MENU_CLOSE',
});
NoteFolderService.openNoteList(folder.id);
}
render() {

View File

@ -18,12 +18,13 @@ import { NoteScreen } from 'src/components/screens/note.js'
import { FolderScreen } from 'src/components/screens/folder.js'
import { FoldersScreen } from 'src/components/screens/folders.js'
import { LoginScreen } from 'src/components/screens/login.js'
import { LoadingScreen } from 'src/components/screens/loading.js'
import { Setting } from 'src/models/setting.js'
import { Synchronizer } from 'src/synchronizer.js'
import { MenuContext } from 'react-native-popup-menu';
//import SideMenu from 'react-native-side-menu';
import { SideMenu } from 'src/components/side-menu.js';
import { SideMenuContent } from 'src/components/side-menu-content.js';
import { NoteFolderService } from 'src/services/note-folder-service.js';
let defaultState = {
notes: [],
@ -45,19 +46,14 @@ const reducer = (state = defaultState, action) => {
case 'Navigation/NAVIGATE':
case 'Navigation/BACK':
// If the current screen is already the requested screen, don't do anything
const r = state.nav.routes;
if (r.length && r[r.length - 1].routeName == action.routeName) {
return state
}
const currentRoute = r.length ? r[r.length - 1] : null;
const currentRouteName = currentRoute ? currentRoute.routeName : '';
action.params = { listMode: 'view' };
Log.info('Current route name', currentRouteName);
Log.info('New route name', action.routeName);
const nextStateNav = AppNavigator.router.getStateForAction(action, state.nav);
newState = Object.assign({}, state);
if (nextStateNav) {
newState.nav = nextStateNav;
}
if ('noteId' in action) {
newState.selectedNoteId = action.noteId;
@ -67,6 +63,17 @@ const reducer = (state = defaultState, action) => {
newState.selectedFolderId = action.folderId;
}
if (currentRouteName == action.routeName) {
// If the current screen is already the requested screen, don't do anything
} else {
action.params = { listMode: 'view' };
const nextStateNav = AppNavigator.router.getStateForAction(action, currentRouteName != 'Loading' ? state.nav : null);
if (nextStateNav) {
newState.nav = nextStateNav;
}
}
break;
// Replace all the notes with the provided array
@ -168,17 +175,20 @@ const reducer = (state = defaultState, action) => {
}
// Log.info('newState.selectedFolderId', newState.selectedFolderId);
return newState;
}
let store = createStore(reducer);
const AppNavigator = StackNavigator({
Notes: {screen: NotesScreen},
Note: {screen: NoteScreen},
Folder: {screen: FolderScreen},
Folders: {screen: FoldersScreen},
Login: {screen: LoginScreen},
Notes: { screen: NotesScreen },
Note: { screen: NoteScreen },
Folder: { screen: FolderScreen },
Folders: { screen: FoldersScreen },
Login: { screen: LoginScreen },
Loading: { screen: LoadingScreen },
});
class AppComponent extends React.Component {
@ -190,6 +200,7 @@ class AppComponent extends React.Component {
BaseModel.dispatch = this.props.dispatch;
BaseModel.db_ = db;
NoteFolderService.dispatch = this.props.dispatch;
db.open().then(() => {
Log.info('Database is ready.');
@ -211,14 +222,27 @@ class AppComponent extends React.Component {
Log.info('Loading folders...');
Folder.all().then((folders) => {
return Folder.all().then((folders) => {
this.props.dispatch({
type: 'FOLDERS_UPDATE_ALL',
folders: folders,
});
return folders;
}).catch((error) => {
Log.warn('Cannot load folders', error);
});
}).then((folders) => {
let folder = folders[0];
if (!folder) throw new Error('No default folder is defined');
return NoteFolderService.openNoteList(folder.id);
// this.props.dispatch({
// type: 'Navigation/NAVIGATE',
// routeName: 'Notes',
// folderId: folder.id,
// });
}).then(() => {
let synchronizer = new Synchronizer(db, Registry.api());
Registry.setSynchronizer(synchronizer);
@ -254,7 +278,7 @@ class AppComponent extends React.Component {
defaultState.nav = AppNavigator.router.getStateForAction({
type: 'Navigation/NAVIGATE',
routeName: 'Folders',
routeName: 'Loading',
params: {listMode: 'view'}
});

View File

@ -36,6 +36,23 @@ class NoteFolderService extends BaseService {
});
}
static openNoteList(folderId) {
return Note.previews(folderId).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', error);
});
}
}
export { NoteFolderService };