From 933ad269a56e97531478fe4bf26022cd9bed71fd Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 15 May 2017 19:46:34 +0000 Subject: [PATCH] Create note under folder --- .../src/components/folder-list.js | 37 +++++++++++++++ ReactNativeClient/src/components/item-list.js | 7 ++- ReactNativeClient/src/components/note-list.js | 23 +++++----- .../src/components/screens/folders.js | 39 ++++++++++++++++ .../src/components/screens/note.js | 3 +- ReactNativeClient/src/database.js | 2 +- ReactNativeClient/src/models/note.js | 11 +++-- ReactNativeClient/src/root.js | 46 ++++++++++++++----- 8 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 ReactNativeClient/src/components/folder-list.js create mode 100644 ReactNativeClient/src/components/screens/folders.js diff --git a/ReactNativeClient/src/components/folder-list.js b/ReactNativeClient/src/components/folder-list.js new file mode 100644 index 000000000..11cdb403d --- /dev/null +++ b/ReactNativeClient/src/components/folder-list.js @@ -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 }; \ No newline at end of file diff --git a/ReactNativeClient/src/components/item-list.js b/ReactNativeClient/src/components/item-list.js index 1c732e054..4d247f7ea 100644 --- a/ReactNativeClient/src/components/item-list.js +++ b/ReactNativeClient/src/components/item-list.js @@ -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 ( diff --git a/ReactNativeClient/src/components/note-list.js b/ReactNativeClient/src/components/note-list.js index b491878bf..39cadea3d 100644 --- a/ReactNativeClient/src/components/note-list.js +++ b/ReactNativeClient/src/components/note-list.js @@ -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) diff --git a/ReactNativeClient/src/components/screens/folders.js b/ReactNativeClient/src/components/screens/folders.js new file mode 100644 index 000000000..f3b5a418f --- /dev/null +++ b/ReactNativeClient/src/components/screens/folders.js @@ -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 ( + + +