mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
Many small changes
This commit is contained in:
parent
f840dd505f
commit
1c16e493f6
@ -23,6 +23,12 @@ class ActionButtonComponent extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(newProps) {
|
||||||
|
if ('toggled' in newProps) {
|
||||||
|
this.setState({ toggled: newProps.toggled });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newTodo_press() {
|
newTodo_press() {
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'Navigation/NAVIGATE',
|
type: 'Navigation/NAVIGATE',
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { View, Button, TextInput, WebView, Text, StyleSheet } from 'react-native';
|
import { BackHandler, View, Button, TextInput, WebView, Text, StyleSheet } from 'react-native';
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Log } from 'lib/log.js'
|
import { Log } from 'lib/log.js'
|
||||||
import { Note } from 'lib/models/note.js'
|
import { Note } from 'lib/models/note.js'
|
||||||
import { Folder } from 'lib/models/folder.js'
|
import { Folder } from 'lib/models/folder.js'
|
||||||
|
import { BaseModel } from 'lib/base-model.js'
|
||||||
import { ActionButton } from 'lib/components/action-button.js';
|
import { ActionButton } from 'lib/components/action-button.js';
|
||||||
import Icon from 'react-native-vector-icons/Ionicons';
|
import Icon from 'react-native-vector-icons/Ionicons';
|
||||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||||
@ -11,6 +12,9 @@ import { Checkbox } from 'lib/components/checkbox.js'
|
|||||||
import { _ } from 'lib/locale.js';
|
import { _ } from 'lib/locale.js';
|
||||||
import marked from 'lib/marked.js';
|
import marked from 'lib/marked.js';
|
||||||
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
import { BaseScreenComponent } from 'lib/components/base-screen.js';
|
||||||
|
import { dialogs } from 'lib/dialogs.js';
|
||||||
|
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
|
||||||
|
import DialogBox from 'react-native-dialogbox';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
webView: {
|
webView: {
|
||||||
@ -32,17 +36,47 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
noteMetadata: '',
|
noteMetadata: '',
|
||||||
showNoteMetadata: false,
|
showNoteMetadata: false,
|
||||||
folder: null,
|
folder: null,
|
||||||
|
lastSavedNote: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.backHandler = () => {
|
||||||
|
if (!this.state.note.id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.mode == 'edit') {
|
||||||
|
this.setState({ mode: 'view' });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
isModified() {
|
||||||
|
if (!this.state.note || !this.state.lastSavedNote) return false;
|
||||||
|
let diff = BaseModel.diffObjects(this.state.note, this.state.lastSavedNote);
|
||||||
|
delete diff.type_;
|
||||||
|
return !!Object.getOwnPropertyNames(diff).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
|
BackHandler.addEventListener('hardwareBackPress', this.backHandler);
|
||||||
|
|
||||||
if (!this.props.noteId) {
|
if (!this.props.noteId) {
|
||||||
let note = this.props.itemType == 'todo' ? Note.newTodo(this.props.folderId) : Note.new(this.props.folderId);
|
let note = this.props.itemType == 'todo' ? Note.newTodo(this.props.folderId) : Note.new(this.props.folderId);
|
||||||
this.setState({ note: note });
|
this.setState({
|
||||||
|
lastSavedNote: Object.assign({}, note),
|
||||||
|
note: note,
|
||||||
|
mode: 'edit',
|
||||||
|
});
|
||||||
this.refreshNoteMetadata();
|
this.refreshNoteMetadata();
|
||||||
} else {
|
} else {
|
||||||
Note.load(this.props.noteId).then((note) => {
|
Note.load(this.props.noteId).then((note) => {
|
||||||
this.setState({ note: note });
|
this.setState({
|
||||||
|
lastSavedNote: Object.assign({}, note),
|
||||||
|
note: note,
|
||||||
|
});
|
||||||
this.refreshNoteMetadata();
|
this.refreshNoteMetadata();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -50,6 +84,10 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
this.refreshFolder();
|
this.refreshFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
BackHandler.removeEventListener('hardwareBackPress', this.backHandler);
|
||||||
|
}
|
||||||
|
|
||||||
async currentFolder() {
|
async currentFolder() {
|
||||||
let folderId = this.props.folderId;
|
let folderId = this.props.folderId;
|
||||||
if (!folderId) {
|
if (!folderId) {
|
||||||
@ -91,7 +129,7 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
async saveNoteButton_press() {
|
async saveNoteButton_press() {
|
||||||
let note = Object.assign({}, this.state.note);
|
let note = Object.assign({}, this.state.note);
|
||||||
|
|
||||||
if (!this.state.note.parent_id) {
|
if (!note.parent_id) {
|
||||||
let folder = await Folder.defaultFolder();
|
let folder = await Folder.defaultFolder();
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
Log.warn('Cannot save note without a notebook');
|
Log.warn('Cannot save note without a notebook');
|
||||||
@ -101,17 +139,30 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let isNew = !note.id;
|
let isNew = !note.id;
|
||||||
|
if (!note.title) note.title = _('Untitled');
|
||||||
note = await Note.save(note);
|
note = await Note.save(note);
|
||||||
this.setState({ note: note });
|
this.setState({
|
||||||
|
lastSavedNote: Object.assign({}, note),
|
||||||
|
note: note,
|
||||||
|
});
|
||||||
if (isNew) Note.updateGeolocation(note.id);
|
if (isNew) Note.updateGeolocation(note.id);
|
||||||
this.refreshNoteMetadata();
|
this.refreshNoteMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteNote_onPress(noteId) {
|
async deleteNote_onPress() {
|
||||||
Log.info('DELETE', noteId);
|
let note = this.state.note;
|
||||||
|
if (!note.id) return;
|
||||||
|
|
||||||
|
let ok = await dialogs.confirm(this, _('Delete note?'));
|
||||||
|
if (!ok) return;
|
||||||
|
|
||||||
|
let folderId = note.parent_id;
|
||||||
|
|
||||||
|
await Note.delete(note.id);
|
||||||
|
await NotesScreenUtils.openNoteList(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
attachFile_onPress(noteId) {
|
attachFile_onPress() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +173,16 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
|
|
||||||
menuOptions() {
|
menuOptions() {
|
||||||
return [
|
return [
|
||||||
{ title: _('Attach file'), onPress: () => { this.attachFile_onPress(this.state.note.id); } },
|
{ title: _('Attach file'), onPress: () => { this.attachFile_onPress(); } },
|
||||||
{ title: _('Delete note'), onPress: () => { this.deleteNote_onPress(this.state.note.id); } },
|
{ title: _('Delete note'), onPress: () => { this.deleteNote_onPress(); } },
|
||||||
{ title: _('Toggle metadata'), onPress: () => { this.showMetadata_onPress(); } },
|
{ title: _('Toggle metadata'), onPress: () => { this.showMetadata_onPress(); } },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
todoCheckbox_change(checked) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const note = this.state.note;
|
const note = this.state.note;
|
||||||
const isTodo = !!Number(note.is_todo);
|
const isTodo = !!Number(note.is_todo);
|
||||||
@ -195,7 +250,15 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
bodyComponent = <TextInput autoFocus={true} style={{flex: 1, textAlignVertical: 'top', fontFamily: 'monospace'}} multiline={true} value={note.body} onChangeText={(text) => this.body_changeText(text)} />
|
bodyComponent = (
|
||||||
|
<TextInput
|
||||||
|
autoFocus={true}
|
||||||
|
style={{flex: 1, textAlignVertical: 'top', fontFamily: 'monospace'}}
|
||||||
|
multiline={true}
|
||||||
|
value={note.body}
|
||||||
|
onChangeText={(text) => this.body_changeText(text)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let title = null;
|
let title = null;
|
||||||
@ -226,7 +289,11 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return <ActionButton isToggle={true} buttons={buttons}/>
|
if (this.state.mode == 'edit' && !this.isModified()) return <ActionButton style={{display:'none'}}/>;
|
||||||
|
|
||||||
|
let toggled = this.state.mode == 'edit';
|
||||||
|
|
||||||
|
return <ActionButton isToggle={true} buttons={buttons} toggled={toggled} />
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionButtonComp = renderActionButton();
|
const actionButtonComp = renderActionButton();
|
||||||
@ -235,12 +302,13 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
<View style={this.styles().screen}>
|
<View style={this.styles().screen}>
|
||||||
<ScreenHeader navState={this.props.navigation.state} menuOptions={this.menuOptions()} title={title} />
|
<ScreenHeader navState={this.props.navigation.state} menuOptions={this.menuOptions()} title={title} />
|
||||||
<View style={{ flexDirection: 'row' }}>
|
<View style={{ flexDirection: 'row' }}>
|
||||||
{ isTodo && <Checkbox checked={!!Number(note.todo_completed)} /> }<TextInput style={{flex:1}} value={note.title} onChangeText={(text) => this.title_changeText(text)} />
|
{ isTodo && <Checkbox checked={!!Number(note.todo_completed)} onChange={(checked) => { this.todoCheckbox_change(checked) }} /> }<TextInput style={{flex:1}} value={note.title} onChangeText={(text) => this.title_changeText(text)} />
|
||||||
</View>
|
</View>
|
||||||
{ bodyComponent }
|
{ bodyComponent }
|
||||||
{ todoComponents }
|
{ todoComponents }
|
||||||
{ actionButtonComp }
|
{ actionButtonComp }
|
||||||
{ this.state.showNoteMetadata && <Text>{this.state.noteMetadata}</Text> }
|
{ this.state.showNoteMetadata && <Text>{this.state.noteMetadata}</Text> }
|
||||||
|
<DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,15 @@ class Note extends BaseItem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async delete(id, options = null) {
|
||||||
|
let r = await super.delete(id, options);
|
||||||
|
|
||||||
|
this.dispatch({
|
||||||
|
type: 'NOTES_DELETE',
|
||||||
|
noteId: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Note.updateGeolocationEnabled_ = true;
|
Note.updateGeolocationEnabled_ = true;
|
||||||
|
@ -9,10 +9,11 @@ import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js';
|
|||||||
const reg = {};
|
const reg = {};
|
||||||
|
|
||||||
reg.logger = () => {
|
reg.logger = () => {
|
||||||
if (reg.logger_) return reg.logger_;
|
if (!reg.logger_) {
|
||||||
reg.logger_ = new Logger();
|
console.warn('Calling logger before it is initialized');
|
||||||
reg.logger_.addTarget('console');
|
return new Logger();
|
||||||
reg.logger_.setLevel(Logger.LEVEL_DEBUG);
|
}
|
||||||
|
|
||||||
return reg.logger_;
|
return reg.logger_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ let time = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
formatMsToLocal(ms, format) {
|
formatMsToLocal(ms, format) {
|
||||||
return moment.unix(ms / 1000).format(format);
|
return moment(ms).format(format);
|
||||||
},
|
},
|
||||||
|
|
||||||
msleep(ms) {
|
msleep(ms) {
|
||||||
|
@ -26,7 +26,6 @@ import { StatusScreen } from 'lib/components/screens/status.js'
|
|||||||
import { WelcomeScreen } from 'lib/components/screens/welcome.js'
|
import { WelcomeScreen } from 'lib/components/screens/welcome.js'
|
||||||
import { OneDriveLoginScreen } from 'lib/components/screens/onedrive-login.js'
|
import { OneDriveLoginScreen } from 'lib/components/screens/onedrive-login.js'
|
||||||
import { Setting } from 'lib/models/setting.js'
|
import { Setting } from 'lib/models/setting.js'
|
||||||
import { Synchronizer } from 'lib/synchronizer.js'
|
|
||||||
import { MenuContext } from 'react-native-popup-menu';
|
import { MenuContext } from 'react-native-popup-menu';
|
||||||
import { SideMenu } from 'lib/components/side-menu.js';
|
import { SideMenu } from 'lib/components/side-menu.js';
|
||||||
import { SideMenuContent } from 'lib/components/side-menu-content.js';
|
import { SideMenuContent } from 'lib/components/side-menu-content.js';
|
||||||
@ -62,6 +61,7 @@ const reducer = (state = defaultState, action) => {
|
|||||||
|
|
||||||
let newState = state;
|
let newState = state;
|
||||||
|
|
||||||
|
try {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
case 'Navigation/BACK':
|
case 'Navigation/BACK':
|
||||||
@ -103,6 +103,10 @@ const reducer = (state = defaultState, action) => {
|
|||||||
|
|
||||||
newState.historyCanGoBack = navHistory.length >= 2;
|
newState.historyCanGoBack = navHistory.length >= 2;
|
||||||
|
|
||||||
|
if (newState.route.routeName == 'Notes') {
|
||||||
|
Setting.setValue('activeFolderId', newState.selectedFolderId);
|
||||||
|
}
|
||||||
|
|
||||||
Keyboard.dismiss(); // TODO: should probably be in some middleware
|
Keyboard.dismiss(); // TODO: should probably be in some middleware
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -143,6 +147,19 @@ const reducer = (state = defaultState, action) => {
|
|||||||
newState.notes = newNotes;
|
newState.notes = newNotes;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'NOTES_DELETE':
|
||||||
|
|
||||||
|
var newNotes = [];
|
||||||
|
for (let i = 0; i < state.notes.length; i++) {
|
||||||
|
let f = state.notes[i];
|
||||||
|
if (f.id == action.noteId) continue;
|
||||||
|
newNotes.push(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
newState = Object.assign({}, state);
|
||||||
|
newState.notes = newNotes;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'FOLDERS_UPDATE_ALL':
|
case 'FOLDERS_UPDATE_ALL':
|
||||||
|
|
||||||
newState = Object.assign({}, state);
|
newState = Object.assign({}, state);
|
||||||
@ -200,6 +217,10 @@ const reducer = (state = defaultState, action) => {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
error.message = 'In reducer: ' + error.message;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
@ -223,12 +244,25 @@ async function initialize(dispatch, backButtonHandler) {
|
|||||||
const logDatabase = new Database(new DatabaseDriverReactNative());
|
const logDatabase = new Database(new DatabaseDriverReactNative());
|
||||||
await logDatabase.open({ name: 'log.sqlite' });
|
await logDatabase.open({ name: 'log.sqlite' });
|
||||||
await logDatabase.exec(Logger.databaseCreateTableSql());
|
await logDatabase.exec(Logger.databaseCreateTableSql());
|
||||||
reg.logger().addTarget('database', { database: logDatabase, source: 'm' });
|
|
||||||
|
const mainLogger = new Logger();
|
||||||
|
mainLogger.addTarget('database', { database: logDatabase, source: 'm' });
|
||||||
|
mainLogger.addTarget('console');
|
||||||
|
mainLogger.setLevel(Logger.LEVEL_DEBUG);
|
||||||
|
mainLogger.addTarget('database', { database: logDatabase, source: 'm' });
|
||||||
|
|
||||||
|
reg.setLogger(mainLogger);
|
||||||
|
|
||||||
reg.logger().info('====================================');
|
reg.logger().info('====================================');
|
||||||
reg.logger().info('Starting application ' + Setting.value('appId') + ' (' + Setting.value('env') + ')');
|
reg.logger().info('Starting application ' + Setting.value('appId') + ' (' + Setting.value('env') + ')');
|
||||||
|
|
||||||
|
const dbLogger = new Logger();
|
||||||
|
dbLogger.addTarget('database', { database: logDatabase, source: 'm' });
|
||||||
|
dbLogger.addTarget('console');
|
||||||
|
dbLogger.setLevel(Logger.LEVEL_INFO);
|
||||||
|
|
||||||
let db = new JoplinDatabase(new DatabaseDriverReactNative());
|
let db = new JoplinDatabase(new DatabaseDriverReactNative());
|
||||||
|
db.setLogger(dbLogger);
|
||||||
reg.setDb(db);
|
reg.setDb(db);
|
||||||
|
|
||||||
BaseModel.dispatch = dispatch;
|
BaseModel.dispatch = dispatch;
|
||||||
@ -271,7 +305,14 @@ async function initialize(dispatch, backButtonHandler) {
|
|||||||
type: 'APPLICATION_LOADING_DONE',
|
type: 'APPLICATION_LOADING_DONE',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let folderId = Setting.value('activeFolderId');
|
||||||
|
let folder = await Folder.load(folderId);
|
||||||
|
|
||||||
|
if (folder) {
|
||||||
|
await NotesScreenUtils.openNoteList(folderId);
|
||||||
|
} else {
|
||||||
await NotesScreenUtils.openDefaultNoteList();
|
await NotesScreenUtils.openDefaultNoteList();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reg.logger().error('Initialization error:', error);
|
reg.logger().error('Initialization error:', error);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user