mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Handle reserved names in RN
This commit is contained in:
parent
0e05567706
commit
e3db1e028a
@ -7,6 +7,8 @@ import { BaseModel } from 'lib/base-model.js'
|
||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
||||
import { dialogs } from 'lib/dialogs.js';
|
||||
import { _ } from 'lib/locale.js';
|
||||
|
||||
class FolderScreenComponent extends BaseScreenComponent {
|
||||
|
||||
@ -50,7 +52,17 @@ class FolderScreenComponent extends BaseScreenComponent {
|
||||
|
||||
if (this.originalFolder) toSave.id = this.originalFolder.id;
|
||||
|
||||
this.originalFolder = await Folder.save(toSave);
|
||||
try {
|
||||
let f = await Folder.save(toSave, {
|
||||
duplicateCheck: true,
|
||||
reservedTitleCheck: true,
|
||||
});
|
||||
this.originalFolder = f;
|
||||
} catch (error) {
|
||||
dialogs.error(this, _('The folder could not be saved: %s', error.message));
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ folder: this.originalFolder });
|
||||
|
||||
await NotesScreenUtils.openDefaultNoteList();
|
||||
@ -62,6 +74,7 @@ class FolderScreenComponent extends BaseScreenComponent {
|
||||
<ScreenHeader navState={this.props.navigation.state} />
|
||||
<TextInput value={this.state.folder.title} onChangeText={(text) => this.title_changeText(text)} />
|
||||
<Button title="Save folder" onPress={() => this.saveFolderButton_press()} />
|
||||
<dialogs.DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import DialogBox from 'react-native-dialogbox';
|
||||
import { Keyboard } from 'react-native';
|
||||
|
||||
// Add this at the bottom of the component:
|
||||
//
|
||||
@ -10,6 +11,8 @@ dialogs.confirm = (parentComponent, message) => {
|
||||
if (!'dialogbox' in parentComponent) throw new Error('A "dialogbox" component must be defined on the parent component!');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Keyboard.dismiss();
|
||||
|
||||
parentComponent.dialogbox.confirm({
|
||||
content: message,
|
||||
|
||||
@ -26,7 +29,14 @@ dialogs.confirm = (parentComponent, message) => {
|
||||
},
|
||||
|
||||
});
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
dialogs.error = (parentComponent, message) => {
|
||||
Keyboard.dismiss();
|
||||
return parentComponent.dialogbox.alert(message);
|
||||
}
|
||||
|
||||
dialogs.DialogBox = DialogBox
|
||||
|
||||
export { dialogs };
|
@ -119,7 +119,7 @@ class Folder extends BaseItem {
|
||||
static async save(o, options = null) {
|
||||
if (options && options.duplicateCheck === true && o.title) {
|
||||
let existingFolder = await Folder.loadByTitle(o.title);
|
||||
if (existingFolder) throw new Error(_('A notebook with this title already exists: "%s"', o.title));
|
||||
if (existingFolder && existingFolder.id != o.id) throw new Error(_('A notebook with this title already exists: "%s"', o.title));
|
||||
}
|
||||
|
||||
if (options && options.reservedTitleCheck === true && o.title) {
|
||||
|
Loading…
Reference in New Issue
Block a user