mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-06 00:07:28 +00:00
fix: keep what was typed in the event editor when calendars refresh
The editor reset its form whenever `calendars` or `currentUserEmails` got a new identity, which happens when a calendar push refetches the calendars or the alias lookup finishes, so the title and times the user had typed were replaced mid-edit. Reset only when the editor opens or moves to another event, and fill in the calendar separately when the calendars arrive after a new-event form opened.
This commit is contained in:
@@ -228,6 +228,10 @@ export function EventModal({
|
||||
const [showEndTime, setShowEndTime] = React.useState(false);
|
||||
const [saving, setSaving] = React.useState(false);
|
||||
|
||||
// Reset the form when the editor opens or switches to another event only.
|
||||
// `calendars` and `currentUserEmails` get new identities when a calendar
|
||||
// push or the alias lookup lands, which used to wipe what the user typed.
|
||||
const formKey = visible ? event?.id ?? 'new' : null;
|
||||
React.useEffect(() => {
|
||||
if (!visible) return;
|
||||
if (event) {
|
||||
@@ -270,7 +274,13 @@ export function EventModal({
|
||||
setLocation('');
|
||||
setVideoUrl('');
|
||||
}
|
||||
}, [visible, event, defaultDate, fallbackCalendarId, calendars, currentUserEmails]);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [formKey]);
|
||||
|
||||
// The calendars can arrive after a new-event form opened.
|
||||
React.useEffect(() => {
|
||||
if (visible && !calendarId && fallbackCalendarId) setCalendarId(fallbackCalendarId);
|
||||
}, [visible, calendarId, fallbackCalendarId]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (allDay) {
|
||||
|
||||
Reference in New Issue
Block a user