mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Create note under folder
This commit is contained in:
parent
ae0eac0f3b
commit
933ad269a5
37
ReactNativeClient/src/components/folder-list.js
Normal file
37
ReactNativeClient/src/components/folder-list.js
Normal 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 };
|
@ -22,10 +22,15 @@ class ItemListComponent extends Component {
|
||||
this.setState({ dataSource: this.state.dataSource.cloneWithRows(newProps.items) });
|
||||
}
|
||||
|
||||
listView_itemClick = (itemId) => {
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
let renderRow = (rowData) => {
|
||||
let onPress = () => {
|
||||
this.props.onItemClick(rowData.id)
|
||||
this.listView_itemClick(rowData.id);
|
||||
//this.props.onItemClick(rowData.id)
|
||||
}
|
||||
return (
|
||||
<TouchableHighlight onPress={onPress}>
|
||||
|
@ -5,22 +5,21 @@ import { Log } from 'src/log.js';
|
||||
import { ItemListComponent } from 'src/components/item-list.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(
|
||||
(state) => {
|
||||
return { items: state.notes };
|
||||
},
|
||||
(dispatch) => {
|
||||
return {
|
||||
onItemClick: (noteId) => {
|
||||
dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Note',
|
||||
noteId: noteId,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
)(NoteListComponent)
|
||||
|
||||
|
39
ReactNativeClient/src/components/screens/folders.js
Normal file
39
ReactNativeClient/src/components/screens/folders.js
Normal 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 };
|
@ -49,6 +49,7 @@ class NoteScreenComponent extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<View style={{flex: 1}}>
|
||||
<TextInput value={this.state.note.parent_id} />
|
||||
<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} />
|
||||
<Button title="Save note" onPress={this.saveNoteButton_press} />
|
||||
@ -61,7 +62,7 @@ class NoteScreenComponent extends React.Component {
|
||||
const NoteScreen = connect(
|
||||
(state) => {
|
||||
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)
|
||||
|
@ -102,7 +102,7 @@ class Database {
|
||||
}
|
||||
|
||||
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');
|
||||
}, (error) => {
|
||||
Log.error('Cannot open database: ', error);
|
||||
|
@ -11,16 +11,17 @@ class Note extends BaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
static newNote() {
|
||||
static newNote(parentId = null) {
|
||||
return {
|
||||
id: null,
|
||||
title: '',
|
||||
body: '',
|
||||
parent_id: parentId,
|
||||
}
|
||||
}
|
||||
|
||||
static previews() {
|
||||
return this.db().selectAll('SELECT id, title, body, updated_time FROM notes').then((r) => {
|
||||
static previews(parentId) {
|
||||
return this.db().selectAll('SELECT id, title, body, parent_id, updated_time FROM notes WHERE parent_id = ?', [parentId]).then((r) => {
|
||||
let output = [];
|
||||
for (let i = 0; i < r.rows.length; i++) {
|
||||
output.push(r.rows.item(i));
|
||||
@ -29,6 +30,10 @@ class Note extends BaseModel {
|
||||
});
|
||||
}
|
||||
|
||||
static byFolderId() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Note };
|
@ -8,12 +8,14 @@ import { StackNavigator } from 'react-navigation';
|
||||
import { addNavigationHelpers } from 'react-navigation';
|
||||
import { Log } from 'src/log.js'
|
||||
import { Note } from 'src/models/note.js'
|
||||
import { Folder } from 'src/models/folder.js'
|
||||
import { Database } from 'src/database.js'
|
||||
import { Registry } from 'src/registry.js'
|
||||
import { ItemList } from 'src/components/item-list.js'
|
||||
import { NotesScreen } from 'src/components/screens/notes.js'
|
||||
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 { Setting } from 'src/models/setting.js'
|
||||
|
||||
@ -21,10 +23,10 @@ let defaultState = {
|
||||
defaultText: 'bla',
|
||||
notes: [],
|
||||
folders: [
|
||||
{ id: 'abcdabcdabcdabcdabcdabcdabcdab01', title: "un" },
|
||||
{ id: 'abcdabcdabcdabcdabcdabcdabcdab02', title: "deux" },
|
||||
{ id: 'abcdabcdabcdabcdabcdabcdabcdab03', title: "trois" },
|
||||
{ id: 'abcdabcdabcdabcdabcdabcdabcdab04', title: "quatre" },
|
||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab01', title: "un" },
|
||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab02', title: "deux" },
|
||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab03', title: "trois" },
|
||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab04', title: "quatre" },
|
||||
],
|
||||
selectedNoteId: null,
|
||||
selectedFolderId: null,
|
||||
@ -53,7 +55,11 @@ const reducer = (state = defaultState, action) => {
|
||||
}
|
||||
|
||||
if (action.noteId) {
|
||||
newState.selectedNoteId = action.noteId;
|
||||
newState.selectedNoteId = action.noteId;
|
||||
}
|
||||
|
||||
if (action.folderId) {
|
||||
newState.selectedFolderId = action.folderId;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -86,6 +92,12 @@ const reducer = (state = defaultState, action) => {
|
||||
newState.notes = newNotes;
|
||||
break;
|
||||
|
||||
case 'FOLDERS_UPDATE_ALL':
|
||||
|
||||
newState = Object.assign({}, state);
|
||||
newState.folders = action.folders;
|
||||
break;
|
||||
|
||||
case 'FOLDERS_UPDATE_ONE':
|
||||
|
||||
let newFolders = state.folders.splice(0);
|
||||
@ -116,6 +128,7 @@ const AppNavigator = StackNavigator({
|
||||
Notes: {screen: NotesScreen},
|
||||
Note: {screen: NoteScreen},
|
||||
Folder: {screen: FolderScreen},
|
||||
Folders: {screen: FoldersScreen},
|
||||
Login: {screen: LoginScreen},
|
||||
});
|
||||
|
||||
@ -133,15 +146,26 @@ class AppComponent extends React.Component {
|
||||
return Setting.load();
|
||||
}).then(() => {
|
||||
Log.info('Client ID', Setting.value('clientId'));
|
||||
Log.info('Loading notes...');
|
||||
Note.previews().then((notes) => {
|
||||
Log.info('Loading folders...');
|
||||
|
||||
Folder.all().then((folders) => {
|
||||
this.props.dispatch({
|
||||
type: 'NOTES_UPDATE_ALL',
|
||||
notes: notes,
|
||||
type: 'FOLDERS_UPDATE_ALL',
|
||||
folders: folders,
|
||||
});
|
||||
}).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) => {
|
||||
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) => {
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user