mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Refactored to use only ES6
This commit is contained in:
parent
cb2ca28e09
commit
bbf21cd03c
@ -4,12 +4,6 @@ import { uuid } from 'src/uuid.js';
|
||||
|
||||
class BaseModel {
|
||||
|
||||
static ITEM_TYPE_NOTE = 1;
|
||||
static ITEM_TYPE_FOLDER = 2;
|
||||
static tableInfo_ = null;
|
||||
static tableKeys_ = null;
|
||||
static db_ = null;
|
||||
|
||||
static tableName() {
|
||||
throw new Error('Must be overriden');
|
||||
}
|
||||
@ -221,4 +215,10 @@ class BaseModel {
|
||||
|
||||
}
|
||||
|
||||
BaseModel.ITEM_TYPE_NOTE = 1;
|
||||
BaseModel.ITEM_TYPE_FOLDER = 2;
|
||||
BaseModel.tableInfo_ = null;
|
||||
BaseModel.tableKeys_ = null;
|
||||
BaseModel.db_ = null;
|
||||
|
||||
export { BaseModel };
|
@ -23,7 +23,7 @@ class Checkbox extends Component {
|
||||
this.state = { checked: this.props.checked };
|
||||
}
|
||||
|
||||
onPress = () => {
|
||||
onPress() {
|
||||
let newChecked = !this.state.checked;
|
||||
this.setState({ checked: newChecked });
|
||||
if (this.props.onChange) this.props.onChange(newChecked);
|
||||
@ -33,7 +33,7 @@ class Checkbox extends Component {
|
||||
const iconName = this.state.checked ? 'md-checkbox-outline' : 'md-square-outline';
|
||||
|
||||
return (
|
||||
<TouchableHighlight onPress={this.onPress} style={{justifyContent: 'center', alignItems: 'center'}}>
|
||||
<TouchableHighlight onPress={() => this.onPress()} style={{justifyContent: 'center', alignItems: 'center'}}>
|
||||
<Icon name={iconName} style={styles.checkboxIcon}/>
|
||||
</TouchableHighlight>
|
||||
);
|
||||
|
@ -10,7 +10,7 @@ import { NoteFolderService } from 'src/services/note-folder-service.js';
|
||||
|
||||
class FolderListComponent extends ItemListComponent {
|
||||
|
||||
listView_itemPress = (folderId) => {
|
||||
listView_itemPress(folderId) {
|
||||
NoteFolderService.openNoteList(folderId);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ class ItemListComponent extends Component {
|
||||
// });
|
||||
}
|
||||
|
||||
listView_itemPress = (itemId) => {}
|
||||
listView_itemPress(itemId) {}
|
||||
|
||||
render() {
|
||||
let renderRow = (item) => {
|
||||
|
@ -7,7 +7,7 @@ import { _ } from 'src/locale.js';
|
||||
|
||||
class NoteListComponent extends ItemListComponent {
|
||||
|
||||
listView_itemPress = (noteId) => {
|
||||
listView_itemPress(noteId) {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Note',
|
||||
|
@ -28,28 +28,28 @@ class ScreenHeaderComponent extends Component {
|
||||
return this.props.navState.routeName != 'Notes';
|
||||
}
|
||||
|
||||
sideMenuButton_press = () => {
|
||||
sideMenuButton_press() {
|
||||
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
|
||||
}
|
||||
|
||||
backButton_press = () => {
|
||||
backButton_press() {
|
||||
this.props.dispatch({ type: 'Navigation/BACK' });
|
||||
}
|
||||
|
||||
menu_select = (value) => {
|
||||
menu_select(value) {
|
||||
if (typeof(value) == 'function') {
|
||||
value();
|
||||
}
|
||||
}
|
||||
|
||||
menu_login = () => {
|
||||
menu_login() {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Login',
|
||||
});
|
||||
}
|
||||
|
||||
menu_logout = () => {
|
||||
menu_logout() {
|
||||
let user = { email: null, session: null };
|
||||
Setting.setObject('user', user);
|
||||
this.props.dispatch({
|
||||
@ -75,12 +75,12 @@ class ScreenHeaderComponent extends Component {
|
||||
|
||||
if (this.props.user && this.props.user.session) {
|
||||
menuOptionComponents.push(
|
||||
<MenuOption value={this.menu_logout} key={'menuOption_' + key++}>
|
||||
<MenuOption value={() => this.menu_logout()} key={'menuOption_' + key++}>
|
||||
<Text>{_('Logout')}</Text>
|
||||
</MenuOption>);
|
||||
} else {
|
||||
menuOptionComponents.push(
|
||||
<MenuOption value={this.menu_login} key={'menuOption_' + key++}>
|
||||
<MenuOption value={() => this.menu_login()} key={'menuOption_' + key++}>
|
||||
<Text>{_('Login')}</Text>
|
||||
</MenuOption>);
|
||||
}
|
||||
@ -94,10 +94,10 @@ class ScreenHeaderComponent extends Component {
|
||||
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', padding: 10, backgroundColor: '#ffffff', alignItems: 'center' }} >
|
||||
<Button title="☰" onPress={this.sideMenuButton_press} />
|
||||
<Button disabled={!this.showBackButton()} title="<" onPress={this.backButton_press}></Button>
|
||||
<Button title="☰" onPress={() => this.sideMenuButton_press()} />
|
||||
<Button disabled={!this.showBackButton()} title="<" onPress={() => this.backButton_press()}></Button>
|
||||
<Text style={{ flex:1, marginLeft: 10 }} >{title}</Text>
|
||||
<Menu onSelect={this.menu_select}>
|
||||
<Menu onSelect={(value) => this.menu_select(value)}>
|
||||
<MenuTrigger>
|
||||
<Text style={{ fontSize: 20 }}> ⋮ </Text>
|
||||
</MenuTrigger>
|
||||
|
@ -8,7 +8,7 @@ import { NoteFolderService } from 'src/services/note-folder-service.js';
|
||||
|
||||
class FolderScreenComponent extends React.Component {
|
||||
|
||||
static navigationOptions = (options) => {
|
||||
static navigationOptions(options) {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ class FolderScreenComponent extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
folderComponent_change = (propName, propValue) => {
|
||||
folderComponent_change(propName, propValue) {
|
||||
this.setState((prevState, props) => {
|
||||
let folder = Object.assign({}, prevState.folder);
|
||||
folder[propName] = propValue;
|
||||
@ -37,11 +37,11 @@ class FolderScreenComponent extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
title_changeText = (text) => {
|
||||
title_changeText(text) {
|
||||
this.folderComponent_change('title', text);
|
||||
}
|
||||
|
||||
saveFolderButton_press = () => {
|
||||
saveFolderButton_press() {
|
||||
NoteFolderService.save('folder', this.state.folder, this.originalFolder).then((folder) => {
|
||||
this.originalFolder = Object.assign({}, folder);
|
||||
this.setState({ folder: folder });
|
||||
@ -52,8 +52,8 @@ class FolderScreenComponent extends React.Component {
|
||||
return (
|
||||
<View style={{flex: 1}}>
|
||||
<ScreenHeader navState={this.props.navigation.state} />
|
||||
<TextInput value={this.state.folder.title} onChangeText={this.title_changeText} />
|
||||
<Button title="Save folder" onPress={this.saveFolderButton_press} />
|
||||
<TextInput value={this.state.folder.title} onChangeText={(text) => this.title_changeText(text)} />
|
||||
<Button title="Save folder" onPress={() => this.saveFolderButton_press()} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import { ActionButton } from 'src/components/action-button.js';
|
||||
|
||||
class FoldersScreenComponent extends React.Component {
|
||||
|
||||
static navigationOptions = (options) => {
|
||||
static navigationOptions(options) {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import { NoteFolderService } from 'src/services/note-folder-service.js';
|
||||
|
||||
class LoadingScreenComponent extends React.Component {
|
||||
|
||||
static navigationOptions = (options) => {
|
||||
static navigationOptions(options) {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import { _ } from 'src/locale.js';
|
||||
|
||||
class LoginScreenComponent extends React.Component {
|
||||
|
||||
static navigationOptions = (options) => {
|
||||
static navigationOptions(options) {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
@ -26,15 +26,15 @@ class LoginScreenComponent extends React.Component {
|
||||
this.setState({ email: this.props.user.email });
|
||||
}
|
||||
|
||||
email_changeText = (text) => {
|
||||
email_changeText(text) {
|
||||
this.setState({ email: text });
|
||||
}
|
||||
|
||||
password_changeText = (text) => {
|
||||
password_changeText(text) {
|
||||
this.setState({ password: text });
|
||||
}
|
||||
|
||||
loginButton_press = () => {
|
||||
loginButton_press() {
|
||||
this.setState({ errorMessage: null });
|
||||
|
||||
return Registry.api().post('sessions', null, {
|
||||
@ -71,10 +71,10 @@ class LoginScreenComponent extends React.Component {
|
||||
return (
|
||||
<View style={{flex: 1}}>
|
||||
<ScreenHeader navState={this.props.navigation.state} />
|
||||
<TextInput value={this.state.email} onChangeText={this.email_changeText} keyboardType="email-address" />
|
||||
<TextInput value={this.state.password} onChangeText={this.password_changeText} secureTextEntry={true} />
|
||||
<TextInput value={this.state.email} onChangeText={(text) => this.email_changeText(text)} keyboardType="email-address" />
|
||||
<TextInput value={this.state.password} onChangeText={(text) => this.password_changeText(text)} secureTextEntry={true} />
|
||||
{ this.state.errorMessage && <Text style={{color:'#ff0000'}}>{this.state.errorMessage}</Text> }
|
||||
<Button title="Login" onPress={this.loginButton_press} />
|
||||
<Button title="Login" onPress={() => this.loginButton_press()} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import { _ } from 'src/locale.js';
|
||||
|
||||
class NoteScreenComponent extends React.Component {
|
||||
|
||||
static navigationOptions = (options) => {
|
||||
static navigationOptions(options) {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ class NoteScreenComponent extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
noteComponent_change = (propName, propValue) => {
|
||||
noteComponent_change(propName, propValue) {
|
||||
this.setState((prevState, props) => {
|
||||
let note = Object.assign({}, prevState.note);
|
||||
note[propName] = propValue;
|
||||
@ -42,29 +42,29 @@ class NoteScreenComponent extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
title_changeText = (text) => {
|
||||
title_changeText(text) {
|
||||
this.noteComponent_change('title', text);
|
||||
}
|
||||
|
||||
body_changeText = (text) => {
|
||||
body_changeText(text) {
|
||||
this.noteComponent_change('body', text);
|
||||
}
|
||||
|
||||
saveNoteButton_press = () => {
|
||||
saveNoteButton_press() {
|
||||
NoteFolderService.save('note', this.state.note, this.originalNote).then((note) => {
|
||||
this.originalNote = Object.assign({}, note);
|
||||
this.setState({ note: note });
|
||||
});
|
||||
}
|
||||
|
||||
deleteNote_onPress = (noteId) => {
|
||||
deleteNote_onPress(noteId) {
|
||||
Log.info('DELETE', noteId);
|
||||
}
|
||||
|
||||
attachFile_onPress = (noteId) => {
|
||||
attachFile_onPress(noteId) {
|
||||
}
|
||||
|
||||
menuOptions = () => {
|
||||
menuOptions() {
|
||||
return [
|
||||
{ title: _('Attach file'), onPress: () => { this.attachFile_onPress(this.state.note.id); } },
|
||||
{ title: _('Delete note'), onPress: () => { this.deleteNote_onPress(this.state.note.id); } },
|
||||
@ -88,11 +88,11 @@ class NoteScreenComponent extends React.Component {
|
||||
<View style={{flex: 1}}>
|
||||
<ScreenHeader navState={this.props.navigation.state} menuOptions={this.menuOptions()} />
|
||||
<View style={{ flexDirection: 'row' }}>
|
||||
{ isTodo && <Checkbox checked={!!Number(note.todo_completed)} /> }<TextInput style={{flex:1}} value={note.title} onChangeText={this.title_changeText} />
|
||||
{ isTodo && <Checkbox checked={!!Number(note.todo_completed)} /> }<TextInput style={{flex:1}} value={note.title} onChangeText={(text) => this.title_changeText(text)} />
|
||||
</View>
|
||||
<TextInput style={{flex: 1, textAlignVertical: 'top'}} multiline={true} value={note.body} onChangeText={this.body_changeText} />
|
||||
<TextInput style={{flex: 1, textAlignVertical: 'top'}} multiline={true} value={note.body} onChangeText={(text) => this.body_changeText(text)} />
|
||||
{ todoComponents }
|
||||
<Button title="Save note" onPress={this.saveNoteButton_press} />
|
||||
<Button title="Save note" onPress={() => this.saveNoteButton_press()} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -11,25 +11,11 @@ import { ActionButton } from 'src/components/action-button.js';
|
||||
|
||||
class NotesScreenComponent extends React.Component {
|
||||
|
||||
static navigationOptions = (options) => {
|
||||
static navigationOptions(options) {
|
||||
return { header: null };
|
||||
}
|
||||
|
||||
createNoteButton_press = () => {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Note',
|
||||
});
|
||||
}
|
||||
|
||||
createFolderButton_press = () => {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Folder',
|
||||
});
|
||||
}
|
||||
|
||||
deleteFolder_onPress = (folderId) => {
|
||||
deleteFolder_onPress(folderId) {
|
||||
Folder.delete(folderId).then(() => {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
@ -40,7 +26,7 @@ class NotesScreenComponent extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
editFolder_onPress = (folderId) => {
|
||||
editFolder_onPress(folderId) {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
routeName: 'Folder',
|
||||
@ -48,7 +34,7 @@ class NotesScreenComponent extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
menuOptions = () => {
|
||||
menuOptions() {
|
||||
return [
|
||||
{ title: _('Delete folder'), onPress: () => { this.deleteFolder_onPress(this.props.selectedFolderId); } },
|
||||
{ title: _('Edit folder'), onPress: () => { this.editFolder_onPress(this.props.selectedFolderId); } },
|
||||
|
@ -3,11 +3,6 @@ import { Log } from 'src/log.js';
|
||||
|
||||
class Change extends BaseModel {
|
||||
|
||||
static TYPE_NOOP = 0;
|
||||
static TYPE_CREATE = 1;
|
||||
static TYPE_UPDATE = 2;
|
||||
static TYPE_DELETE = 3;
|
||||
|
||||
static tableName() {
|
||||
return 'changes';
|
||||
}
|
||||
@ -103,4 +98,9 @@ class Change extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
Change.TYPE_NOOP = 0;
|
||||
Change.TYPE_CREATE = 1;
|
||||
Change.TYPE_UPDATE = 2;
|
||||
Change.TYPE_DELETE = 3;
|
||||
|
||||
export { Change };
|
@ -4,14 +4,6 @@ import { Database } from 'src/database.js';
|
||||
|
||||
class Setting extends BaseModel {
|
||||
|
||||
static defaults_ = {
|
||||
'clientId': { value: '', type: 'string' },
|
||||
'sessionId': { value: '', type: 'string' },
|
||||
'user.email': { value: '', type: 'string' },
|
||||
'user.session': { value: '', type: 'string' },
|
||||
'sync.lastRevId': { value: 0, type: 'int' },
|
||||
};
|
||||
|
||||
static tableName() {
|
||||
return 'settings';
|
||||
}
|
||||
@ -121,4 +113,12 @@ class Setting extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
Setting.defaults_ = {
|
||||
'clientId': { value: '', type: 'string' },
|
||||
'sessionId': { value: '', type: 'string' },
|
||||
'user.email': { value: '', type: 'string' },
|
||||
'user.session': { value: '', type: 'string' },
|
||||
'sync.lastRevId': { value: 0, type: 'int' },
|
||||
};
|
||||
|
||||
export { Setting };
|
Loading…
Reference in New Issue
Block a user