1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/app-mobile/components/screens/folder.js
Laurent Cozic be0fa69b3b Revert "Mobile: Resolves #1044: Add create sub-notebook feature (#7728)"
This reverts commit f5fc1f2f22.

Cancel button is gone with this change
2023-02-10 23:48:46 +00:00

116 lines
3.0 KiB
JavaScript

const React = require('react');
const { View } = require('react-native');
const { connect } = require('react-redux');
const Folder = require('@joplin/lib/models/Folder').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
const { ScreenHeader } = require('../ScreenHeader');
const { BaseScreenComponent } = require('../base-screen.js');
const { dialogs } = require('../../utils/dialogs.js');
const { _ } = require('@joplin/lib/locale');
const TextInput = require('../TextInput').default;
class FolderScreenComponent extends BaseScreenComponent {
static navigationOptions() {
return { header: null };
}
constructor() {
super();
this.state = {
folder: Folder.new(),
lastSavedFolder: null,
};
}
UNSAFE_componentWillMount() {
if (!this.props.folderId) {
const folder = Folder.new();
this.setState({
folder: folder,
lastSavedFolder: Object.assign({}, folder),
});
} else {
// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied
Folder.load(this.props.folderId).then(folder => {
this.setState({
folder: folder,
lastSavedFolder: Object.assign({}, folder),
});
});
}
}
isModified() {
if (!this.state.folder || !this.state.lastSavedFolder) return false;
const diff = BaseModel.diffObjects(this.state.folder, this.state.lastSavedFolder);
delete diff.type_;
return !!Object.getOwnPropertyNames(diff).length;
}
folderComponent_change(propName, propValue) {
this.setState((prevState) => {
const folder = Object.assign({}, prevState.folder);
folder[propName] = propValue;
return { folder: folder };
});
}
title_changeText(text) {
this.folderComponent_change('title', text);
}
async saveFolderButton_press() {
let folder = Object.assign({}, this.state.folder);
try {
folder = await Folder.save(folder, { userSideValidation: true });
} catch (error) {
dialogs.error(this, _('The notebook could not be saved: %s', error.message));
return;
}
this.setState({
lastSavedFolder: Object.assign({}, folder),
folder: folder,
});
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Notes',
folderId: folder.id,
});
}
render() {
const saveButtonDisabled = !this.isModified();
return (
<View style={this.rootStyle(this.props.themeId).root}>
<ScreenHeader title={_('Edit notebook')} showSaveButton={true} saveButtonDisabled={saveButtonDisabled} onSaveButtonPress={() => this.saveFolderButton_press()} showSideMenuButton={false} showSearchButton={false} />
<TextInput
themeId={this.props.themeId}
placeholder={_('Enter notebook title')}
autoFocus={true}
value={this.state.folder.title}
onChangeText={text => this.title_changeText(text)}
/>
<dialogs.DialogBox
ref={dialogbox => {
this.dialogbox = dialogbox;
}}
/>
</View>
);
}
}
const FolderScreen = connect(state => {
return {
folderId: state.selectedFolderId,
themeId: state.settings.theme,
};
})(FolderScreenComponent);
module.exports = { FolderScreen };