1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Create note under folder

This commit is contained in:
Laurent Cozic 2017-05-15 19:46:34 +00:00
parent ae0eac0f3b
commit 933ad269a5
8 changed files with 139 additions and 29 deletions

View File

@ -0,0 +1,37 @@
import React, { Component } from 'react';
import { connect } from 'react-redux'
import { ListView, Text, TouchableHighlight } from 'react-native';
import { Log } from 'src/log.js';
import { ItemListComponent } from 'src/components/item-list.js';
import { Note } from 'src/models/note.js';
import { _ } from 'src/locale.js';
class FolderListComponent extends ItemListComponent {
listView_itemClick = (folderId) => {
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);
});
}
}
const FolderList = connect(
(state) => {
return { items: state.folders };
}
)(FolderListComponent)
export { FolderList };

View File

@ -22,10 +22,15 @@ class ItemListComponent extends Component {
this.setState({ dataSource: this.state.dataSource.cloneWithRows(newProps.items) }); this.setState({ dataSource: this.state.dataSource.cloneWithRows(newProps.items) });
} }
listView_itemClick = (itemId) => {
}
render() { render() {
let renderRow = (rowData) => { let renderRow = (rowData) => {
let onPress = () => { let onPress = () => {
this.props.onItemClick(rowData.id) this.listView_itemClick(rowData.id);
//this.props.onItemClick(rowData.id)
} }
return ( return (
<TouchableHighlight onPress={onPress}> <TouchableHighlight onPress={onPress}>

View File

@ -5,22 +5,21 @@ import { Log } from 'src/log.js';
import { ItemListComponent } from 'src/components/item-list.js'; import { ItemListComponent } from 'src/components/item-list.js';
import { _ } from 'src/locale.js'; import { _ } from 'src/locale.js';
class NoteListComponent extends ItemListComponent {} class NoteListComponent extends ItemListComponent {
listView_itemClick = (noteId) => {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Note',
noteId: noteId,
});
}
}
const NoteList = connect( const NoteList = connect(
(state) => { (state) => {
return { items: state.notes }; return { items: state.notes };
},
(dispatch) => {
return {
onItemClick: (noteId) => {
dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Note',
noteId: noteId,
});
}
}
} }
)(NoteListComponent) )(NoteListComponent)

View File

@ -0,0 +1,39 @@
import React, { Component } from 'react';
import { View, Button, Picker } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'src/log.js'
import { FolderList } from 'src/components/folder-list.js'
class FoldersScreenComponent extends React.Component {
static navigationOptions = {
title: 'Folders',
};
createFolderButton_press = () => {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Folder',
});
}
render() {
const { navigate } = this.props.navigation;
return (
<View style={{flex: 1}}>
<FolderList style={{flex: 1}}/>
<Button title="Create folder" onPress={this.createFolderButton_press} />
</View>
);
}
}
const FoldersScreen = connect(
(state) => {
return {
folders: state.folders
};
}
)(FoldersScreenComponent)
export { FoldersScreen };

View File

@ -49,6 +49,7 @@ class NoteScreenComponent extends React.Component {
render() { render() {
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<TextInput value={this.state.note.parent_id} />
<TextInput value={this.state.note.title} onChangeText={this.title_changeText} /> <TextInput value={this.state.note.title} onChangeText={this.title_changeText} />
<TextInput style={{flex: 1, textAlignVertical: 'top'}} multiline={true} value={this.state.note.body} onChangeText={this.body_changeText} /> <TextInput style={{flex: 1, textAlignVertical: 'top'}} multiline={true} value={this.state.note.body} onChangeText={this.body_changeText} />
<Button title="Save note" onPress={this.saveNoteButton_press} /> <Button title="Save note" onPress={this.saveNoteButton_press} />
@ -61,7 +62,7 @@ class NoteScreenComponent extends React.Component {
const NoteScreen = connect( const NoteScreen = connect(
(state) => { (state) => {
return { return {
note: state.selectedNoteId ? Note.byId(state.notes, state.selectedNoteId) : Note.newNote(), note: state.selectedNoteId ? Note.byId(state.notes, state.selectedNoteId) : Note.newNote(state.selectedFolderId),
}; };
} }
)(NoteScreenComponent) )(NoteScreenComponent)

View File

@ -102,7 +102,7 @@ class Database {
} }
open() { open() {
this.db_ = SQLite.openDatabase({ name: '/storage/emulated/0/Download/joplin-5.sqlite' }, (db) => { this.db_ = SQLite.openDatabase({ name: '/storage/emulated/0/Download/joplin-6.sqlite' }, (db) => {
Log.info('Database was open successfully'); Log.info('Database was open successfully');
}, (error) => { }, (error) => {
Log.error('Cannot open database: ', error); Log.error('Cannot open database: ', error);

View File

@ -11,16 +11,17 @@ class Note extends BaseModel {
return true; return true;
} }
static newNote() { static newNote(parentId = null) {
return { return {
id: null, id: null,
title: '', title: '',
body: '', body: '',
parent_id: parentId,
} }
} }
static previews() { static previews(parentId) {
return this.db().selectAll('SELECT id, title, body, updated_time FROM notes').then((r) => { return this.db().selectAll('SELECT id, title, body, parent_id, updated_time FROM notes WHERE parent_id = ?', [parentId]).then((r) => {
let output = []; let output = [];
for (let i = 0; i < r.rows.length; i++) { for (let i = 0; i < r.rows.length; i++) {
output.push(r.rows.item(i)); output.push(r.rows.item(i));
@ -29,6 +30,10 @@ class Note extends BaseModel {
}); });
} }
static byFolderId() {
}
} }
export { Note }; export { Note };

View File

@ -8,12 +8,14 @@ import { StackNavigator } from 'react-navigation';
import { addNavigationHelpers } from 'react-navigation'; import { addNavigationHelpers } from 'react-navigation';
import { Log } from 'src/log.js' import { Log } from 'src/log.js'
import { Note } from 'src/models/note.js' import { Note } from 'src/models/note.js'
import { Folder } from 'src/models/folder.js'
import { Database } from 'src/database.js' import { Database } from 'src/database.js'
import { Registry } from 'src/registry.js' import { Registry } from 'src/registry.js'
import { ItemList } from 'src/components/item-list.js' import { ItemList } from 'src/components/item-list.js'
import { NotesScreen } from 'src/components/screens/notes.js' import { NotesScreen } from 'src/components/screens/notes.js'
import { NoteScreen } from 'src/components/screens/note.js' import { NoteScreen } from 'src/components/screens/note.js'
import { FolderScreen } from 'src/components/screens/folder.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 { LoginScreen } from 'src/components/screens/login.js'
import { Setting } from 'src/models/setting.js' import { Setting } from 'src/models/setting.js'
@ -21,10 +23,10 @@ let defaultState = {
defaultText: 'bla', defaultText: 'bla',
notes: [], notes: [],
folders: [ folders: [
{ id: 'abcdabcdabcdabcdabcdabcdabcdab01', title: "un" }, // { id: 'abcdabcdabcdabcdabcdabcdabcdab01', title: "un" },
{ id: 'abcdabcdabcdabcdabcdabcdabcdab02', title: "deux" }, // { id: 'abcdabcdabcdabcdabcdabcdabcdab02', title: "deux" },
{ id: 'abcdabcdabcdabcdabcdabcdabcdab03', title: "trois" }, // { id: 'abcdabcdabcdabcdabcdabcdabcdab03', title: "trois" },
{ id: 'abcdabcdabcdabcdabcdabcdabcdab04', title: "quatre" }, // { id: 'abcdabcdabcdabcdabcdabcdabcdab04', title: "quatre" },
], ],
selectedNoteId: null, selectedNoteId: null,
selectedFolderId: null, selectedFolderId: null,
@ -56,6 +58,10 @@ const reducer = (state = defaultState, action) => {
newState.selectedNoteId = action.noteId; newState.selectedNoteId = action.noteId;
} }
if (action.folderId) {
newState.selectedFolderId = action.folderId;
}
break; break;
// Replace all the notes with the provided array // Replace all the notes with the provided array
@ -86,6 +92,12 @@ const reducer = (state = defaultState, action) => {
newState.notes = newNotes; newState.notes = newNotes;
break; break;
case 'FOLDERS_UPDATE_ALL':
newState = Object.assign({}, state);
newState.folders = action.folders;
break;
case 'FOLDERS_UPDATE_ONE': case 'FOLDERS_UPDATE_ONE':
let newFolders = state.folders.splice(0); let newFolders = state.folders.splice(0);
@ -116,6 +128,7 @@ const AppNavigator = StackNavigator({
Notes: {screen: NotesScreen}, Notes: {screen: NotesScreen},
Note: {screen: NoteScreen}, Note: {screen: NoteScreen},
Folder: {screen: FolderScreen}, Folder: {screen: FolderScreen},
Folders: {screen: FoldersScreen},
Login: {screen: LoginScreen}, Login: {screen: LoginScreen},
}); });
@ -133,15 +146,26 @@ class AppComponent extends React.Component {
return Setting.load(); return Setting.load();
}).then(() => { }).then(() => {
Log.info('Client ID', Setting.value('clientId')); Log.info('Client ID', Setting.value('clientId'));
Log.info('Loading notes...'); Log.info('Loading folders...');
Note.previews().then((notes) => {
Folder.all().then((folders) => {
this.props.dispatch({ this.props.dispatch({
type: 'NOTES_UPDATE_ALL', type: 'FOLDERS_UPDATE_ALL',
notes: notes, folders: folders,
}); });
}).catch((error) => { }).catch((error) => {
Log.warn('Cannot load notes', error); Log.warn('Cannot load folders', error);
}); });
// }).then(() => {
// Log.info('Loading notes...');
// Note.previews().then((notes) => {
// this.props.dispatch({
// type: 'NOTES_UPDATE_ALL',
// notes: notes,
// });
// }).catch((error) => {
// Log.warn('Cannot load notes', error);
// });
}).catch((error) => { }).catch((error) => {
Log.error('Cannot initialize database:', error); Log.error('Cannot initialize database:', error);
}); });
@ -157,7 +181,7 @@ class AppComponent extends React.Component {
} }
} }
defaultState.nav = AppNavigator.router.getStateForAction(AppNavigator.router.getActionForPathAndParams('Notes')); defaultState.nav = AppNavigator.router.getStateForAction(AppNavigator.router.getActionForPathAndParams('Folders'));
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {