Files
mailspring-mirror/app/internal_packages/main-calendar/lib/quick-event-popover.tsx
Ben Gotow cff437e900 Upgrade to Electron 8, improve TS usage and TS errors outside calendar [requires re- npm install] (#2284)
* Shfit away from default exports and PropTypes for better TS support

* localize strings and expand use of types in WeekView, create new EventOccurence distinct from Event

* Remove calendar wrap, use TS enum for view type + consistent prop interface

* Bump Typescript to 3.8.3 and improve query / attribute / search typings

* Re-use the Autolinker for calendar event descriptions with aggressive phone detection

* Clean up WeekView and the editing popover, lots of cruft here

* Update ScrollRegion to initialize scrollbar provided by external ref

* Expose ScrollRegion’s resizeObserver to clean up tick interval tracking

* Simply tickGenerator and move it to a helper

* Bump to Electron 8.x for Chrome 75+ CSS features

* Bump Handlebars dep to fix annoying npm audit noise

* Remove electron-remote from electron-spellchecker

* Explicitly add node-gyp, why is this necessary?

* Fix lesslint issues

* Bump eslint and let it fix 133 issues

* Satisfy remaining eslint@2020 errors by hand

* Add tsc-watch npm script and fix all TS errors outside calendar

* Configure appveyor to publish all the pdb files it gets

* Log sync exit codes and signals for easier triage on Windows

* Upgrade npm, mark that the build process supports Node 11+ not just Node 11

* Resolve more errors

* Upgrade sqlite to be a context-aware native module

* Fix: Tab key no longer navigating into contenteditable because tabIndex not inferred

* Fix: Bad print styles because Chrome now adds more CSS of it’s own when doctype is missing

* Fix: before-navigate is now called after beforeunload
2021-02-14 15:58:22 -06:00

107 lines
2.7 KiB
TypeScript

import React from 'react';
import { Actions, Calendar, DatabaseStore, DateUtils, Event, localized } from 'mailspring-exports';
import { Moment } from 'moment';
interface QuickEventPopoverState {
start: Moment | null;
end: Moment | null;
leftoverText: string | null;
}
export class QuickEventPopover extends React.Component<{}, QuickEventPopoverState> {
constructor(props) {
super(props);
this.state = {
start: null,
end: null,
leftoverText: null,
};
}
onInputKeyDown = event => {
const {
key,
target: { value },
} = event;
if (value.length > 0 && ['Enter', 'Return'].includes(key)) {
// This prevents onInputChange from being fired
event.stopPropagation();
this.createEvent(DateUtils.parseDateString(value));
Actions.closePopover();
}
};
onInputChange = event => {
this.setState(DateUtils.parseDateString(event.target.value));
};
createEvent = async ({
leftoverText,
start,
end,
}: {
leftoverText: string;
start: Moment;
end: Moment;
}) => {
const allCalendars = await DatabaseStore.findAll<Calendar>(Calendar);
const editableCals = allCalendars.filter(c => !c.readOnly);
if (editableCals.length === 0) {
AppEnv.showErrorDialog(
localized(
"This account has no editable calendars. We can't create an event for you. Please make sure you have an editable calendar with your account provider."
)
);
return;
}
const event = new Event({
calendarId: editableCals[0].id,
accountId: editableCals[0].accountId,
start: start.unix(),
end: end.unix(),
when: {
start_time: start.unix(),
end_time: end.unix(),
},
title: leftoverText,
});
console.log(event);
// todo bg
// return DatabaseStore.inTransaction((t) => {
// return t.persistModel(event)
// }).then(() => {
// const task = new SyncbackEventTask(event.id);
// Actions.queueTask(task);
// })
};
render() {
let dateInterpretation;
if (this.state.start) {
dateInterpretation = (
<span className="date-interpretation">
Title: {this.state.leftoverText} <br />
Start: {DateUtils.format(this.state.start, DateUtils.DATE_FORMAT_SHORT)} <br />
End: {DateUtils.format(this.state.end, DateUtils.DATE_FORMAT_SHORT)}
</span>
);
}
return (
<div className="quick-event-popover nylas-date-input">
<input
tabIndex={0}
type="text"
placeholder={localized("Coffee next Monday at 9AM'")}
onKeyDown={this.onInputKeyDown}
onChange={this.onInputChange}
/>
{dateInterpretation}
</div>
);
}
}