1
0
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:
Laurent Cozic 2017-06-06 20:01:43 +00:00
parent cb2ca28e09
commit bbf21cd03c
14 changed files with 64 additions and 78 deletions

View File

@ -4,12 +4,6 @@ import { uuid } from 'src/uuid.js';
class BaseModel { class BaseModel {
static ITEM_TYPE_NOTE = 1;
static ITEM_TYPE_FOLDER = 2;
static tableInfo_ = null;
static tableKeys_ = null;
static db_ = null;
static tableName() { static tableName() {
throw new Error('Must be overriden'); 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 }; export { BaseModel };

View File

@ -23,7 +23,7 @@ class Checkbox extends Component {
this.state = { checked: this.props.checked }; this.state = { checked: this.props.checked };
} }
onPress = () => { onPress() {
let newChecked = !this.state.checked; let newChecked = !this.state.checked;
this.setState({ checked: newChecked }); this.setState({ checked: newChecked });
if (this.props.onChange) this.props.onChange(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'; const iconName = this.state.checked ? 'md-checkbox-outline' : 'md-square-outline';
return ( 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}/> <Icon name={iconName} style={styles.checkboxIcon}/>
</TouchableHighlight> </TouchableHighlight>
); );

View File

@ -10,7 +10,7 @@ import { NoteFolderService } from 'src/services/note-folder-service.js';
class FolderListComponent extends ItemListComponent { class FolderListComponent extends ItemListComponent {
listView_itemPress = (folderId) => { listView_itemPress(folderId) {
NoteFolderService.openNoteList(folderId); NoteFolderService.openNoteList(folderId);
} }

View File

@ -43,7 +43,7 @@ class ItemListComponent extends Component {
// }); // });
} }
listView_itemPress = (itemId) => {} listView_itemPress(itemId) {}
render() { render() {
let renderRow = (item) => { let renderRow = (item) => {

View File

@ -7,7 +7,7 @@ import { _ } from 'src/locale.js';
class NoteListComponent extends ItemListComponent { class NoteListComponent extends ItemListComponent {
listView_itemPress = (noteId) => { listView_itemPress(noteId) {
this.props.dispatch({ this.props.dispatch({
type: 'Navigation/NAVIGATE', type: 'Navigation/NAVIGATE',
routeName: 'Note', routeName: 'Note',

View File

@ -28,28 +28,28 @@ class ScreenHeaderComponent extends Component {
return this.props.navState.routeName != 'Notes'; return this.props.navState.routeName != 'Notes';
} }
sideMenuButton_press = () => { sideMenuButton_press() {
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' }); this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
} }
backButton_press = () => { backButton_press() {
this.props.dispatch({ type: 'Navigation/BACK' }); this.props.dispatch({ type: 'Navigation/BACK' });
} }
menu_select = (value) => { menu_select(value) {
if (typeof(value) == 'function') { if (typeof(value) == 'function') {
value(); value();
} }
} }
menu_login = () => { menu_login() {
this.props.dispatch({ this.props.dispatch({
type: 'Navigation/NAVIGATE', type: 'Navigation/NAVIGATE',
routeName: 'Login', routeName: 'Login',
}); });
} }
menu_logout = () => { menu_logout() {
let user = { email: null, session: null }; let user = { email: null, session: null };
Setting.setObject('user', user); Setting.setObject('user', user);
this.props.dispatch({ this.props.dispatch({
@ -75,12 +75,12 @@ class ScreenHeaderComponent extends Component {
if (this.props.user && this.props.user.session) { if (this.props.user && this.props.user.session) {
menuOptionComponents.push( menuOptionComponents.push(
<MenuOption value={this.menu_logout} key={'menuOption_' + key++}> <MenuOption value={() => this.menu_logout()} key={'menuOption_' + key++}>
<Text>{_('Logout')}</Text> <Text>{_('Logout')}</Text>
</MenuOption>); </MenuOption>);
} else { } else {
menuOptionComponents.push( menuOptionComponents.push(
<MenuOption value={this.menu_login} key={'menuOption_' + key++}> <MenuOption value={() => this.menu_login()} key={'menuOption_' + key++}>
<Text>{_('Login')}</Text> <Text>{_('Login')}</Text>
</MenuOption>); </MenuOption>);
} }
@ -94,10 +94,10 @@ class ScreenHeaderComponent extends Component {
return ( return (
<View style={{ flexDirection: 'row', padding: 10, backgroundColor: '#ffffff', alignItems: 'center' }} > <View style={{ flexDirection: 'row', padding: 10, backgroundColor: '#ffffff', alignItems: 'center' }} >
<Button title="☰" onPress={this.sideMenuButton_press} /> <Button title="☰" onPress={() => this.sideMenuButton_press()} />
<Button disabled={!this.showBackButton()} title="<" onPress={this.backButton_press}></Button> <Button disabled={!this.showBackButton()} title="<" onPress={() => this.backButton_press()}></Button>
<Text style={{ flex:1, marginLeft: 10 }} >{title}</Text> <Text style={{ flex:1, marginLeft: 10 }} >{title}</Text>
<Menu onSelect={this.menu_select}> <Menu onSelect={(value) => this.menu_select(value)}>
<MenuTrigger> <MenuTrigger>
<Text style={{ fontSize: 20 }}> &#8942; </Text> <Text style={{ fontSize: 20 }}> &#8942; </Text>
</MenuTrigger> </MenuTrigger>

View File

@ -8,7 +8,7 @@ import { NoteFolderService } from 'src/services/note-folder-service.js';
class FolderScreenComponent extends React.Component { class FolderScreenComponent extends React.Component {
static navigationOptions = (options) => { static navigationOptions(options) {
return { header: null }; return { header: null };
} }
@ -29,7 +29,7 @@ class FolderScreenComponent extends React.Component {
} }
} }
folderComponent_change = (propName, propValue) => { folderComponent_change(propName, propValue) {
this.setState((prevState, props) => { this.setState((prevState, props) => {
let folder = Object.assign({}, prevState.folder); let folder = Object.assign({}, prevState.folder);
folder[propName] = propValue; folder[propName] = propValue;
@ -37,11 +37,11 @@ class FolderScreenComponent extends React.Component {
}); });
} }
title_changeText = (text) => { title_changeText(text) {
this.folderComponent_change('title', text); this.folderComponent_change('title', text);
} }
saveFolderButton_press = () => { saveFolderButton_press() {
NoteFolderService.save('folder', this.state.folder, this.originalFolder).then((folder) => { NoteFolderService.save('folder', this.state.folder, this.originalFolder).then((folder) => {
this.originalFolder = Object.assign({}, folder); this.originalFolder = Object.assign({}, folder);
this.setState({ folder: folder }); this.setState({ folder: folder });
@ -52,8 +52,8 @@ class FolderScreenComponent extends React.Component {
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} /> <ScreenHeader navState={this.props.navigation.state} />
<TextInput value={this.state.folder.title} onChangeText={this.title_changeText} /> <TextInput value={this.state.folder.title} onChangeText={(text) => this.title_changeText(text)} />
<Button title="Save folder" onPress={this.saveFolderButton_press} /> <Button title="Save folder" onPress={() => this.saveFolderButton_press()} />
</View> </View>
); );
} }

View File

@ -9,7 +9,7 @@ import { ActionButton } from 'src/components/action-button.js';
class FoldersScreenComponent extends React.Component { class FoldersScreenComponent extends React.Component {
static navigationOptions = (options) => { static navigationOptions(options) {
return { header: null }; return { header: null };
} }

View File

@ -8,7 +8,7 @@ import { NoteFolderService } from 'src/services/note-folder-service.js';
class LoadingScreenComponent extends React.Component { class LoadingScreenComponent extends React.Component {
static navigationOptions = (options) => { static navigationOptions(options) {
return { header: null }; return { header: null };
} }

View File

@ -9,7 +9,7 @@ import { _ } from 'src/locale.js';
class LoginScreenComponent extends React.Component { class LoginScreenComponent extends React.Component {
static navigationOptions = (options) => { static navigationOptions(options) {
return { header: null }; return { header: null };
} }
@ -26,15 +26,15 @@ class LoginScreenComponent extends React.Component {
this.setState({ email: this.props.user.email }); this.setState({ email: this.props.user.email });
} }
email_changeText = (text) => { email_changeText(text) {
this.setState({ email: text }); this.setState({ email: text });
} }
password_changeText = (text) => { password_changeText(text) {
this.setState({ password: text }); this.setState({ password: text });
} }
loginButton_press = () => { loginButton_press() {
this.setState({ errorMessage: null }); this.setState({ errorMessage: null });
return Registry.api().post('sessions', null, { return Registry.api().post('sessions', null, {
@ -71,10 +71,10 @@ class LoginScreenComponent extends React.Component {
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} /> <ScreenHeader navState={this.props.navigation.state} />
<TextInput value={this.state.email} onChangeText={this.email_changeText} keyboardType="email-address" /> <TextInput value={this.state.email} onChangeText={(text) => this.email_changeText(text)} keyboardType="email-address" />
<TextInput value={this.state.password} onChangeText={this.password_changeText} secureTextEntry={true} /> <TextInput value={this.state.password} onChangeText={(text) => this.password_changeText(text)} secureTextEntry={true} />
{ this.state.errorMessage && <Text style={{color:'#ff0000'}}>{this.state.errorMessage}</Text> } { 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> </View>
); );
} }

View File

@ -11,7 +11,7 @@ import { _ } from 'src/locale.js';
class NoteScreenComponent extends React.Component { class NoteScreenComponent extends React.Component {
static navigationOptions = (options) => { static navigationOptions(options) {
return { header: null }; return { header: null };
} }
@ -34,7 +34,7 @@ class NoteScreenComponent extends React.Component {
} }
} }
noteComponent_change = (propName, propValue) => { noteComponent_change(propName, propValue) {
this.setState((prevState, props) => { this.setState((prevState, props) => {
let note = Object.assign({}, prevState.note); let note = Object.assign({}, prevState.note);
note[propName] = propValue; note[propName] = propValue;
@ -42,29 +42,29 @@ class NoteScreenComponent extends React.Component {
}); });
} }
title_changeText = (text) => { title_changeText(text) {
this.noteComponent_change('title', text); this.noteComponent_change('title', text);
} }
body_changeText = (text) => { body_changeText(text) {
this.noteComponent_change('body', text); this.noteComponent_change('body', text);
} }
saveNoteButton_press = () => { saveNoteButton_press() {
NoteFolderService.save('note', this.state.note, this.originalNote).then((note) => { NoteFolderService.save('note', this.state.note, this.originalNote).then((note) => {
this.originalNote = Object.assign({}, note); this.originalNote = Object.assign({}, note);
this.setState({ note: note }); this.setState({ note: note });
}); });
} }
deleteNote_onPress = (noteId) => { deleteNote_onPress(noteId) {
Log.info('DELETE', noteId); Log.info('DELETE', noteId);
} }
attachFile_onPress = (noteId) => { attachFile_onPress(noteId) {
} }
menuOptions = () => { menuOptions() {
return [ return [
{ title: _('Attach file'), onPress: () => { this.attachFile_onPress(this.state.note.id); } }, { title: _('Attach file'), onPress: () => { this.attachFile_onPress(this.state.note.id); } },
{ title: _('Delete note'), onPress: () => { this.deleteNote_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}}> <View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} menuOptions={this.menuOptions()} /> <ScreenHeader navState={this.props.navigation.state} menuOptions={this.menuOptions()} />
<View style={{ flexDirection: 'row' }}> <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> </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 } { todoComponents }
<Button title="Save note" onPress={this.saveNoteButton_press} /> <Button title="Save note" onPress={() => this.saveNoteButton_press()} />
</View> </View>
); );
} }

View File

@ -11,25 +11,11 @@ import { ActionButton } from 'src/components/action-button.js';
class NotesScreenComponent extends React.Component { class NotesScreenComponent extends React.Component {
static navigationOptions = (options) => { static navigationOptions(options) {
return { header: null }; return { header: null };
} }
createNoteButton_press = () => { deleteFolder_onPress(folderId) {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Note',
});
}
createFolderButton_press = () => {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Folder',
});
}
deleteFolder_onPress = (folderId) => {
Folder.delete(folderId).then(() => { Folder.delete(folderId).then(() => {
this.props.dispatch({ this.props.dispatch({
type: 'Navigation/NAVIGATE', type: 'Navigation/NAVIGATE',
@ -40,7 +26,7 @@ class NotesScreenComponent extends React.Component {
}); });
} }
editFolder_onPress = (folderId) => { editFolder_onPress(folderId) {
this.props.dispatch({ this.props.dispatch({
type: 'Navigation/NAVIGATE', type: 'Navigation/NAVIGATE',
routeName: 'Folder', routeName: 'Folder',
@ -48,7 +34,7 @@ class NotesScreenComponent extends React.Component {
}); });
} }
menuOptions = () => { menuOptions() {
return [ return [
{ title: _('Delete folder'), onPress: () => { this.deleteFolder_onPress(this.props.selectedFolderId); } }, { title: _('Delete folder'), onPress: () => { this.deleteFolder_onPress(this.props.selectedFolderId); } },
{ title: _('Edit folder'), onPress: () => { this.editFolder_onPress(this.props.selectedFolderId); } }, { title: _('Edit folder'), onPress: () => { this.editFolder_onPress(this.props.selectedFolderId); } },

View File

@ -3,11 +3,6 @@ import { Log } from 'src/log.js';
class Change extends BaseModel { class Change extends BaseModel {
static TYPE_NOOP = 0;
static TYPE_CREATE = 1;
static TYPE_UPDATE = 2;
static TYPE_DELETE = 3;
static tableName() { static tableName() {
return 'changes'; 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 }; export { Change };

View File

@ -4,14 +4,6 @@ import { Database } from 'src/database.js';
class Setting extends BaseModel { 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() { static tableName() {
return 'settings'; 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 }; export { Setting };