2017-05-12 22:23:54 +02:00
|
|
|
import React, { Component } from 'react';
|
2017-05-15 21:10:00 +02:00
|
|
|
import { View, Button, Picker } from 'react-native';
|
2017-05-12 22:23:54 +02:00
|
|
|
import { connect } from 'react-redux'
|
2017-06-24 20:06:28 +02:00
|
|
|
import { Log } from 'lib/log.js'
|
|
|
|
import { NoteList } from 'lib/components/note-list.js'
|
|
|
|
import { Folder } from 'lib/models/folder.js'
|
|
|
|
import { ScreenHeader } from 'lib/components/screen-header.js';
|
2017-05-16 22:25:19 +02:00
|
|
|
import { MenuOption, Text } from 'react-native-popup-menu';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { _ } from 'lib/locale.js';
|
|
|
|
import { ActionButton } from 'lib/components/action-button.js';
|
2017-07-13 01:01:15 +02:00
|
|
|
import { dialogs } from 'lib/dialogs.js';
|
|
|
|
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
2017-07-13 00:32:08 +02:00
|
|
|
import DialogBox from 'react-native-dialogbox';
|
2017-07-14 20:49:14 +02:00
|
|
|
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
2017-05-12 22:23:54 +02:00
|
|
|
|
2017-07-14 20:49:14 +02:00
|
|
|
class NotesScreenComponent extends BaseScreenComponent {
|
2017-05-12 22:23:54 +02:00
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
static navigationOptions(options) {
|
2017-05-16 21:57:09 +02:00
|
|
|
return { header: null };
|
|
|
|
}
|
2017-05-12 22:23:54 +02:00
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
deleteFolder_onPress(folderId) {
|
2017-07-13 01:01:15 +02:00
|
|
|
dialogs.confirm(this, _('Delete notebook?')).then((ok) => {
|
|
|
|
if (!ok) return;
|
2017-07-13 00:32:08 +02:00
|
|
|
|
2017-07-13 01:01:15 +02:00
|
|
|
|
|
|
|
Folder.delete(folderId).then(() => {
|
|
|
|
return NotesScreenUtils.openDefaultNoteList();
|
|
|
|
}).catch((error) => {
|
|
|
|
alert(error.message);
|
2017-05-16 22:25:19 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
editFolder_onPress(folderId) {
|
2017-05-16 22:25:19 +02:00
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Folder',
|
|
|
|
folderId: folderId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
menuOptions() {
|
2017-05-16 22:25:19 +02:00
|
|
|
return [
|
|
|
|
{ title: _('Delete folder'), onPress: () => { this.deleteFolder_onPress(this.props.selectedFolderId); } },
|
|
|
|
{ title: _('Edit folder'), onPress: () => { this.editFolder_onPress(this.props.selectedFolderId); } },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:23:54 +02:00
|
|
|
render() {
|
2017-05-16 22:25:19 +02:00
|
|
|
let folder = Folder.byId(this.props.folders, this.props.selectedFolderId);
|
|
|
|
let title = folder ? folder.title : null;
|
|
|
|
|
2017-05-12 22:23:54 +02:00
|
|
|
const { navigate } = this.props.navigation;
|
|
|
|
return (
|
2017-07-14 20:49:14 +02:00
|
|
|
<View style={this.styles().screen}>
|
2017-05-16 22:25:19 +02:00
|
|
|
<ScreenHeader title={title} navState={this.props.navigation.state} menuOptions={this.menuOptions()} />
|
2017-07-08 01:25:10 +02:00
|
|
|
<NoteList noItemMessage={_('There are currently no notes. Create one by clicking on the (+) button.')} style={{flex: 1}}/>
|
2017-07-14 01:35:37 +02:00
|
|
|
<ActionButton addFolderNoteButtons={true} parentFolderId={this.props.selectedFolderId}></ActionButton>
|
2017-07-13 01:01:15 +02:00
|
|
|
<DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
2017-05-12 22:23:54 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const NotesScreen = connect(
|
|
|
|
(state) => {
|
2017-05-15 21:10:00 +02:00
|
|
|
return {
|
2017-05-16 22:25:19 +02:00
|
|
|
folders: state.folders,
|
|
|
|
selectedFolderId: state.selectedFolderId,
|
2017-05-15 21:10:00 +02:00
|
|
|
};
|
2017-05-12 22:23:54 +02:00
|
|
|
}
|
|
|
|
)(NotesScreenComponent)
|
|
|
|
|
|
|
|
export { NotesScreen };
|