1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ReactNativeClient/src/components/screens/folder.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-05-15 21:10:00 +02:00
import React, { Component } from 'react';
import { View, Button, TextInput } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'src/log.js'
import { Folder } from 'src/models/folder.js'
2017-05-16 21:57:09 +02:00
import { ScreenHeader } from 'src/components/screen-header.js';
import { NoteFolderService } from 'src/services/note-folder-service.js';
2017-05-15 21:10:00 +02:00
class FolderScreenComponent extends React.Component {
2017-06-06 22:01:43 +02:00
static navigationOptions(options) {
2017-05-16 21:57:09 +02:00
return { header: null };
}
2017-05-15 21:10:00 +02:00
constructor() {
super();
this.state = { folder: Folder.new() };
this.originalFolder = null;
2017-05-15 21:10:00 +02:00
}
componentWillMount() {
if (!this.props.folderId) {
this.setState({ folder: Folder.new() });
} else {
Folder.load(this.props.folderId).then((folder) => {
this.originalFolder = Object.assign({}, folder);
this.setState({ folder: folder });
});
}
2017-05-15 21:10:00 +02:00
}
2017-06-06 22:01:43 +02:00
folderComponent_change(propName, propValue) {
2017-05-15 21:10:00 +02:00
this.setState((prevState, props) => {
let folder = Object.assign({}, prevState.folder);
folder[propName] = propValue;
return { folder: folder }
});
}
2017-06-06 22:01:43 +02:00
title_changeText(text) {
2017-05-15 21:10:00 +02:00
this.folderComponent_change('title', text);
}
2017-06-06 22:01:43 +02:00
saveFolderButton_press() {
2017-06-21 00:16:41 +02:00
console.warn('CHANGE NOT TESTED');
let toSave = BaseModel.diffObjects(this.originalFolder, this.state.folder);
toSave.id = this.state.folder.id;
Folder.save(toSave).then((folder) => {
this.originalFolder = Object.assign({}, folder);
this.setState({ folder: folder });
2017-05-15 21:10:00 +02:00
});
2017-06-21 00:16:41 +02:00
// NoteFolderService.save('folder', this.state.folder, this.originalFolder).then((folder) => {
// this.originalFolder = Object.assign({}, folder);
// this.setState({ folder: folder });
// });
2017-05-15 21:10:00 +02:00
}
render() {
return (
<View style={{flex: 1}}>
2017-05-16 21:57:09 +02:00
<ScreenHeader navState={this.props.navigation.state} />
2017-06-06 22:01:43 +02:00
<TextInput value={this.state.folder.title} onChangeText={(text) => this.title_changeText(text)} />
<Button title="Save folder" onPress={() => this.saveFolderButton_press()} />
2017-05-15 21:10:00 +02:00
</View>
);
}
}
const FolderScreen = connect(
(state) => {
return {
folderId: state.selectedFolderId,
2017-05-15 21:10:00 +02:00
};
}
)(FolderScreenComponent)
export { FolderScreen };