From f3ad73dae1ea4ef050f579e522339406b4cdb445 Mon Sep 17 00:00:00 2001 From: 0-ft <0ft@pm.me> Date: Wed, 18 May 2022 16:55:55 +0100 Subject: [PATCH] Update event editing modal --- src/EditModal.css | 51 +++++++ src/components/EditEvent.tsx | 285 ++++++++++++++++++++--------------- src/view.ts | 1 + 3 files changed, 215 insertions(+), 122 deletions(-) create mode 100644 src/EditModal.css diff --git a/src/EditModal.css b/src/EditModal.css new file mode 100644 index 0000000..b84aab0 --- /dev/null +++ b/src/EditModal.css @@ -0,0 +1,51 @@ +.ofc-edit-modal-content { + display: grid; + gap: 1em; + grid-template-columns: 1fr 1fr; +} + +.ofc-edit-modal-column { + display: flex; + flex-direction: column; +} + +.ofc-edit-modal-event-save-button { + margin: 0; +} + +.ofc-edit-modal-content label { + color: var(--text-muted); + font-size: 14px; +} + +.ofc-edit-modal-content input[type="date"], +.ofc-edit-modal-content input[type="time"], +.ofc-edit-modal-content select { + background: var(--background-modifier-form-field); + border: 1px solid var(--background-modifier-border); + color: var(--text-normal); + font-family: inherit; + padding: 5px 14px; + font-size: 16px; + border-radius: 4px; + outline: none; + height: 30px; +} + +.ofc-edit-modal-buttons, +.ofc-edit-modal-checkbox { + display: flex; +} + +.ofc-edit-modal-event-delete-button { + background-color: var(--background-secondary); + color: var(--background-modifier-error); + border-color: var(--background-modifier-error); + border-width: 1px; + border-style: solid; + margin-right: auto; +} + +.not-visible { + display: none; +} \ No newline at end of file diff --git a/src/components/EditEvent.tsx b/src/components/EditEvent.tsx index c333c0d..fa8df1c 100644 --- a/src/components/EditEvent.tsx +++ b/src/components/EditEvent.tsx @@ -1,4 +1,3 @@ -import { DropdownComponent } from "obsidian"; import * as React from "react"; import { useEffect, useRef, useState } from "react"; import { @@ -57,26 +56,31 @@ const DAY_MAP = { const DaySelect = ({ value: days, onChange, + label: selectLabel, }: { value: string[]; onChange: (days: string[]) => void; + label: string; }) => { return ( -
- {Object.entries(DAY_MAP).map(([code, label]) => ( - - days.includes(code) - ? onChange(days.filter((c) => c !== code)) - : onChange([code, ...days]) - } - /> - ))} -
+ <> + +
+ {Object.entries(DAY_MAP).map(([code, label]) => ( + + days.includes(code) + ? onChange(days.filter((c) => c !== code)) + : onChange([code, ...days]) + } + /> + ))} +
+ ); }; @@ -134,6 +138,11 @@ export const EditEvent = ({ [] ); + const onRecurringDaysChanged = (days: string[]) => { + setIsRecurring(days.length > 0); + setDaysOfWeek(days); + }; + const [allDay, setAllDay] = useState(initialEvent?.allDay || false); const [calendarIndex, setCalendarIndex] = useState(defaultCalendarIndex); @@ -161,6 +170,7 @@ export const EditEvent = ({ endRecur: endRecur || undefined, } : { + type: "single", date, endDate, }), @@ -169,18 +179,83 @@ export const EditEvent = ({ ); }; - return ( + const startTimeInput = ( <> -
-

- {open && } -

-
+ + x)} + /> + + ); + + const endTimeInput = ( + <> + + x)} + /> + + ); + + const startDateInput = ( + <> + + x)} + /> + + ); + + const endDateInput = ( + <> + + + x == "undefined" ? undefined : x + )} + /> + + ); -
-

+ const stopRecurringInput = ( + <> + + x)} + /> + + ); + + return ( + <> + +

+ x)} /> -

-

+

+
+ -

-

- {!isRecurring && ( - x)} - /> - )} - - {allDay ? ( - <> - ) : ( - <> - x - )} - /> - - - x - )} - /> - - )} -

-

- +

+
{startDateInput}
+
+ {!isRecurring && endDateInput} +
+
setAllDay(e.target.checked)} type="checkbox" /> -

-

- + +

+
setIsRecurring(e.target.checked)} type="checkbox" /> -

- + +
+ {!allDay && ( + <> +
+ {startTimeInput} +
+
+ {endTimeInput} +
+ + )} {isRecurring && ( <> - -

- Starts recurring - x)} - /> - and stops recurring - x - )} +

+ -

+
+
+ {stopRecurringInput} +
)} -

- - - {deleteEvent && ( - - )} - -

+ {deleteEvent && ( + + )} + + + ); diff --git a/src/view.ts b/src/view.ts index 655fc5e..650dbbd 100644 --- a/src/view.ts +++ b/src/view.ts @@ -1,4 +1,5 @@ import "./overrides.css"; +import "./EditModal.css"; import { ItemView, Notice, TFile, WorkspaceLeaf } from "obsidian"; import { Calendar } from "@fullcalendar/core"; import { renderCalendar } from "./calendar";