[prettify] tweaked full calendar to remove the temp event only when quitting the popup
This commit is contained in:
@@ -104,6 +104,7 @@ export default function CalendarApp() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClosePopover = () => {
|
const handleClosePopover = () => {
|
||||||
|
calendarRef.current?.unselect();
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
setSelectedRange(null);
|
setSelectedRange(null);
|
||||||
};
|
};
|
||||||
@@ -230,6 +231,7 @@ export default function CalendarApp() {
|
|||||||
slotDuration={"00:30:00"}
|
slotDuration={"00:30:00"}
|
||||||
slotLabelInterval={"00:30:00"}
|
slotLabelInterval={"00:30:00"}
|
||||||
scrollTime={"09:00:00"}
|
scrollTime={"09:00:00"}
|
||||||
|
unselectAuto={false}
|
||||||
allDayText=""
|
allDayText=""
|
||||||
slotLabelFormat={{
|
slotLabelFormat={{
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
@@ -285,6 +287,8 @@ export default function CalendarApp() {
|
|||||||
open={Boolean(anchorEl)}
|
open={Boolean(anchorEl)}
|
||||||
onClose={handleClosePopover}
|
onClose={handleClosePopover}
|
||||||
selectedRange={selectedRange}
|
selectedRange={selectedRange}
|
||||||
|
setSelectedRange={setSelectedRange}
|
||||||
|
calendarRef={calendarRef}
|
||||||
/>
|
/>
|
||||||
<CalendarPopover
|
<CalendarPopover
|
||||||
anchorEl={anchorElCal}
|
anchorEl={anchorElCal}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { addEvent, putEventAsync } from "../Calendars/CalendarSlice";
|
import { addEvent, putEventAsync } from "../Calendars/CalendarSlice";
|
||||||
import { CalendarEvent } from "./EventsTypes";
|
import { CalendarEvent } from "./EventsTypes";
|
||||||
import { DateSelectArg } from "@fullcalendar/core";
|
import { CalendarApi, DateSelectArg } from "@fullcalendar/core";
|
||||||
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
@@ -25,11 +25,15 @@ function EventPopover({
|
|||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
selectedRange,
|
selectedRange,
|
||||||
|
setSelectedRange,
|
||||||
|
calendarRef,
|
||||||
}: {
|
}: {
|
||||||
anchorEl: HTMLElement | null;
|
anchorEl: HTMLElement | null;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: (event: {}, reason: "backdropClick" | "escapeKeyDown") => void;
|
onClose: (event: {}, reason: "backdropClick" | "escapeKeyDown") => void;
|
||||||
selectedRange: DateSelectArg | null;
|
selectedRange: DateSelectArg | null;
|
||||||
|
setSelectedRange: Function;
|
||||||
|
calendarRef: React.RefObject<CalendarApi | null>;
|
||||||
}) {
|
}) {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
@@ -60,6 +64,7 @@ function EventPopover({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedRange) {
|
if (selectedRange) {
|
||||||
setStart(selectedRange ? formatLocalDateTime(selectedRange.start) : "");
|
setStart(selectedRange ? formatLocalDateTime(selectedRange.start) : "");
|
||||||
|
setEnd(selectedRange ? formatLocalDateTime(selectedRange.end) : "");
|
||||||
}
|
}
|
||||||
}, [selectedRange]);
|
}, [selectedRange]);
|
||||||
|
|
||||||
@@ -148,8 +153,19 @@ function EventPopover({
|
|||||||
fullWidth
|
fullWidth
|
||||||
label="Start"
|
label="Start"
|
||||||
type={allday ? "date" : "datetime-local"}
|
type={allday ? "date" : "datetime-local"}
|
||||||
value={start}
|
value={allday ? start.split("T")[0] : start}
|
||||||
onChange={(e) => setStart(e.target.value)}
|
onChange={(e) => {
|
||||||
|
const newStart = e.target.value;
|
||||||
|
setStart(newStart);
|
||||||
|
const newRange = {
|
||||||
|
...selectedRange,
|
||||||
|
start: new Date(newStart),
|
||||||
|
startStr: newStart,
|
||||||
|
allDay: allday,
|
||||||
|
};
|
||||||
|
setSelectedRange(newRange);
|
||||||
|
calendarRef.current?.select(newRange);
|
||||||
|
}}
|
||||||
size="small"
|
size="small"
|
||||||
margin="dense"
|
margin="dense"
|
||||||
InputLabelProps={{ shrink: true }}
|
InputLabelProps={{ shrink: true }}
|
||||||
@@ -158,8 +174,19 @@ function EventPopover({
|
|||||||
fullWidth
|
fullWidth
|
||||||
label="End"
|
label="End"
|
||||||
type={allday ? "date" : "datetime-local"}
|
type={allday ? "date" : "datetime-local"}
|
||||||
value={end}
|
value={allday ? end.split("T")[0] : end}
|
||||||
onChange={(e) => setEnd(e.target.value)}
|
onChange={(e) => {
|
||||||
|
const newEnd = e.target.value;
|
||||||
|
setEnd(newEnd);
|
||||||
|
const newRange = {
|
||||||
|
...selectedRange,
|
||||||
|
end: new Date(newEnd),
|
||||||
|
endStr: newEnd,
|
||||||
|
allDay: allday,
|
||||||
|
};
|
||||||
|
setSelectedRange(newRange);
|
||||||
|
calendarRef.current?.select(newRange);
|
||||||
|
}}
|
||||||
size="small"
|
size="small"
|
||||||
margin="dense"
|
margin="dense"
|
||||||
InputLabelProps={{ shrink: true }}
|
InputLabelProps={{ shrink: true }}
|
||||||
@@ -168,7 +195,19 @@ function EventPopover({
|
|||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={allday}
|
checked={allday}
|
||||||
onChange={() => setAllDay(!allday)}
|
onChange={() => {
|
||||||
|
setAllDay(!allday);
|
||||||
|
const newRange = {
|
||||||
|
startStr: allday ? start.split("T")[0] : start,
|
||||||
|
endStr: allday ? end.split("T")[0] : end,
|
||||||
|
start: new Date(allday ? start.split("T")[0] : start),
|
||||||
|
end: new Date(allday ? end.split("T")[0] : end),
|
||||||
|
allday,
|
||||||
|
...selectedRange,
|
||||||
|
};
|
||||||
|
setSelectedRange(newRange);
|
||||||
|
calendarRef.current?.select(newRange);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
All day
|
All day
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user