2017-05-12 20:23:54 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-05-15 19:10:00 +00:00
|
|
|
import { View, Button, Picker } from 'react-native';
|
2017-05-12 20:23:54 +00:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { Log } from 'src/log.js'
|
2017-05-15 19:10:00 +00:00
|
|
|
import { NoteList } from 'src/components/note-list.js'
|
2017-05-16 20:25:19 +00:00
|
|
|
import { Folder } from 'src/models/folder.js'
|
2017-05-16 19:57:09 +00:00
|
|
|
import { ScreenHeader } from 'src/components/screen-header.js';
|
2017-05-16 20:25:19 +00:00
|
|
|
import { MenuOption, Text } from 'react-native-popup-menu';
|
2017-05-16 19:57:09 +00:00
|
|
|
import { _ } from 'src/locale.js';
|
2017-05-12 20:23:54 +00:00
|
|
|
|
|
|
|
class NotesScreenComponent extends React.Component {
|
|
|
|
|
2017-05-16 19:57:09 +00:00
|
|
|
static navigationOptions = (options) => {
|
|
|
|
return { header: null };
|
|
|
|
}
|
2017-05-12 20:23:54 +00:00
|
|
|
|
|
|
|
createNoteButton_press = () => {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Note',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-15 19:10:00 +00:00
|
|
|
createFolderButton_press = () => {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Folder',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:23:54 +00:00
|
|
|
loginButton_press = () => {
|
2017-05-12 20:31:03 +00:00
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Login',
|
|
|
|
});
|
2017-05-12 20:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
syncButton_press = () => {
|
|
|
|
Log.info('SYNC');
|
|
|
|
}
|
|
|
|
|
2017-05-16 20:25:19 +00:00
|
|
|
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); } },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:23:54 +00:00
|
|
|
render() {
|
2017-05-16 20:25:19 +00:00
|
|
|
let folder = Folder.byId(this.props.folders, this.props.selectedFolderId);
|
|
|
|
let title = folder ? folder.title : null;
|
|
|
|
|
2017-05-12 20:23:54 +00:00
|
|
|
const { navigate } = this.props.navigation;
|
|
|
|
return (
|
|
|
|
<View style={{flex: 1}}>
|
2017-05-16 20:25:19 +00:00
|
|
|
<ScreenHeader title={title} navState={this.props.navigation.state} menuOptions={this.menuOptions()} />
|
2017-05-15 19:10:00 +00:00
|
|
|
<NoteList style={{flex: 1}}/>
|
2017-05-12 20:23:54 +00:00
|
|
|
<View style={{flexDirection: 'row'}}>
|
|
|
|
<Button title="Create note" onPress={this.createNoteButton_press} />
|
2017-05-15 19:10:00 +00:00
|
|
|
<Button title="Create folder" onPress={this.createFolderButton_press} />
|
2017-05-12 20:23:54 +00:00
|
|
|
<Button title="Login" onPress={this.loginButton_press} />
|
|
|
|
<Button title="Sync" onPress={this.syncButton_press} />
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const NotesScreen = connect(
|
|
|
|
(state) => {
|
2017-05-15 19:10:00 +00:00
|
|
|
return {
|
2017-05-16 20:25:19 +00:00
|
|
|
folders: state.folders,
|
|
|
|
selectedFolderId: state.selectedFolderId,
|
2017-05-15 19:10:00 +00:00
|
|
|
};
|
2017-05-12 20:23:54 +00:00
|
|
|
}
|
|
|
|
)(NotesScreenComponent)
|
|
|
|
|
|
|
|
export { NotesScreen };
|