From 5aa5b3d7b26efc782bdb52fb68717f6e0a5cbb19 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 16 May 2017 20:25:19 +0000 Subject: [PATCH] Added context menu --- ReactNativeClient/package.json | 1 + ReactNativeClient/src/base-model.js | 9 ++++ .../src/components/base-screen.js | 8 --- .../src/components/login-button.js | 30 ----------- .../src/components/offline-button.js | 29 ----------- .../src/components/screen-header.js | 51 ++++++++++++++++++- .../src/components/screens/folders.js | 1 - .../src/components/screens/notes.js | 38 +++++++++++++- ReactNativeClient/src/root.js | 25 ++++++++- 9 files changed, 119 insertions(+), 73 deletions(-) delete mode 100644 ReactNativeClient/src/components/base-screen.js delete mode 100644 ReactNativeClient/src/components/login-button.js delete mode 100644 ReactNativeClient/src/components/offline-button.js diff --git a/ReactNativeClient/package.json b/ReactNativeClient/package.json index 2b3387c00..21ed6c503 100644 --- a/ReactNativeClient/package.json +++ b/ReactNativeClient/package.json @@ -10,6 +10,7 @@ "react": "16.0.0-alpha.6", "react-native": "0.44.0", "react-native-checkbox": "^1.1.0", + "react-native-popup-menu": "^0.7.4", "react-native-vector-icons": "^2.0.3", "react-navigation": "^1.0.0-beta.9", "uuid": "^3.0.1" diff --git a/ReactNativeClient/src/base-model.js b/ReactNativeClient/src/base-model.js index 6e0cb0fa0..38644e0dc 100644 --- a/ReactNativeClient/src/base-model.js +++ b/ReactNativeClient/src/base-model.js @@ -37,6 +37,15 @@ class BaseModel { return this.db().exec(query.sql, query.params).then(() => { return o; }); } + static delete(id) { + if (!id) { + Log.warn('Cannot delete object without an ID'); + return; + } + + return this.db().exec('DELETE FROM ' + this.tableName() + ' WHERE id = ?', [id]); + } + static db() { return Registry.db(); } diff --git a/ReactNativeClient/src/components/base-screen.js b/ReactNativeClient/src/components/base-screen.js deleted file mode 100644 index 5c74b977b..000000000 --- a/ReactNativeClient/src/components/base-screen.js +++ /dev/null @@ -1,8 +0,0 @@ -import React, { Component } from 'react'; -import { Log } from 'src/log.js' - -class BaseScreenComponent extends React.Component { - -} - -export { BaseScreenComponent }; \ No newline at end of file diff --git a/ReactNativeClient/src/components/login-button.js b/ReactNativeClient/src/components/login-button.js deleted file mode 100644 index 48ed12f58..000000000 --- a/ReactNativeClient/src/components/login-button.js +++ /dev/null @@ -1,30 +0,0 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux' -import { Button } from 'react-native'; -import { _ } from 'src/locale.js'; - -class LoginButtonComponent extends Component { - - render() { - return - {_(this.props.navState.routeName)} + {title} + + + + + + { menuOptionComponents } + + {_('Configuration')} + + + ); } diff --git a/ReactNativeClient/src/components/screens/folders.js b/ReactNativeClient/src/components/screens/folders.js index d338e8569..6780b8ff7 100644 --- a/ReactNativeClient/src/components/screens/folders.js +++ b/ReactNativeClient/src/components/screens/folders.js @@ -3,7 +3,6 @@ import { View, Button, Picker, Text } from 'react-native'; import { connect } from 'react-redux' import { Log } from 'src/log.js' import { FolderList } from 'src/components/folder-list.js' -import { BaseScreenComponent } from 'src/components/base-screen.js' import { ScreenHeader } from 'src/components/screen-header.js'; import { _ } from 'src/locale.js'; diff --git a/ReactNativeClient/src/components/screens/notes.js b/ReactNativeClient/src/components/screens/notes.js index f814772c6..2ff983117 100644 --- a/ReactNativeClient/src/components/screens/notes.js +++ b/ReactNativeClient/src/components/screens/notes.js @@ -3,7 +3,9 @@ import { View, Button, Picker } from 'react-native'; import { connect } from 'react-redux' import { Log } from 'src/log.js' import { NoteList } from 'src/components/note-list.js' +import { Folder } from 'src/models/folder.js' import { ScreenHeader } from 'src/components/screen-header.js'; +import { MenuOption, Text } from 'react-native-popup-menu'; import { _ } from 'src/locale.js'; class NotesScreenComponent extends React.Component { @@ -37,11 +39,42 @@ class NotesScreenComponent extends React.Component { Log.info('SYNC'); } + deleteFolder_onPress = (folderId) => { + Folder.delete(folderId).then(() => { + this.props.dispatch({ + type: 'FOLDER_DELETE', + folderId: folderId, + }); + this.props.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'Folders', + }); + }); + } + + editFolder_onPress = (folderId) => { + this.props.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'Folder', + folderId: folderId, + }); + } + + menuOptions = () => { + return [ + { title: _('Delete folder'), onPress: () => { this.deleteFolder_onPress(this.props.selectedFolderId); } }, + { title: _('Edit folder'), onPress: () => { this.editFolder_onPress(this.props.selectedFolderId); } }, + ]; + } + render() { + let folder = Folder.byId(this.props.folders, this.props.selectedFolderId); + let title = folder ? folder.title : null; + const { navigate } = this.props.navigation; return ( - +