mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
Electron: Fixes #32: Error when manually input alarm date
This commit is contained in:
parent
739c6be476
commit
aef2e4845d
@ -183,12 +183,16 @@ class MainScreenComponent extends React.Component {
|
||||
} else if (command.name === 'editAlarm') {
|
||||
const note = await Note.load(command.noteId);
|
||||
|
||||
let defaultDate = new Date(Date.now() + 2 * 3600 * 1000);
|
||||
defaultDate.setMinutes(0);
|
||||
defaultDate.setSeconds(0);
|
||||
|
||||
this.setState({
|
||||
promptOptions: {
|
||||
label: _('Set alarm:'),
|
||||
inputType: 'datetime',
|
||||
buttons: ['ok', 'cancel', 'clear'],
|
||||
value: note.todo_due ? new Date(note.todo_due) : null,
|
||||
value: note.todo_due ? new Date(note.todo_due) : defaultDate,
|
||||
onClose: async (answer, buttonType) => {
|
||||
let newNote = null;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
const React = require('react');
|
||||
const { connect } = require('react-redux');
|
||||
const { _ } = require('lib/locale.js');
|
||||
const moment = require('moment');
|
||||
const { themeStyle } = require('../theme.js');
|
||||
const { time } = require('lib/time-utils.js');
|
||||
const Datetime = require('react-datetime');
|
||||
@ -113,7 +114,13 @@ class PromptDialog extends React.Component {
|
||||
const styles = this.styles(this.props.theme, style.width, style.height, this.state.visible);
|
||||
|
||||
const onClose = (accept, buttonType) => {
|
||||
if (this.props.onClose) this.props.onClose(accept ? this.state.answer : null, buttonType);
|
||||
if (this.props.onClose) {
|
||||
let outputAnswer = this.state.answer;
|
||||
if (this.props.inputType === 'datetime') {
|
||||
outputAnswer = anythingToDate(outputAnswer);
|
||||
}
|
||||
this.props.onClose(accept ? outputAnswer : null, buttonType);
|
||||
}
|
||||
this.setState({ visible: false, answer: '' });
|
||||
}
|
||||
|
||||
@ -121,8 +128,17 @@ class PromptDialog extends React.Component {
|
||||
this.setState({ answer: event.target.value });
|
||||
}
|
||||
|
||||
const anythingToDate = (o) => {
|
||||
if (o && o.toDate) return o.toDate();
|
||||
if (!o) return null;
|
||||
let m = moment(o, time.dateTimeFormat());
|
||||
if (m.isValid()) return m.toDate();
|
||||
m = moment(o, time.dateFormat());
|
||||
return m.isValid() ? m.toDate() : null;
|
||||
}
|
||||
|
||||
const onDateTimeChange = (momentObject) => {
|
||||
this.setState({ answer: momentObject.toDate() });
|
||||
this.setState({ answer: momentObject });
|
||||
}
|
||||
|
||||
const onKeyDown = (event) => {
|
||||
|
Loading…
Reference in New Issue
Block a user