1
0
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:
Laurent Cozic 2017-12-01 21:55:02 +00:00
parent 739c6be476
commit aef2e4845d
2 changed files with 23 additions and 3 deletions

View File

@ -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;

View File

@ -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) => {