diff --git a/src/components/calendar.tsx b/src/components/calendar.tsx index 532c2ba..d9e99d9 100644 --- a/src/components/calendar.tsx +++ b/src/components/calendar.tsx @@ -6,6 +6,7 @@ import NoteListComponent from './noteList'; import dayjs from 'dayjs'; import useForceUpdate from 'hooks/forceUpdate'; import { DayChangeCommandAction } from 'types'; +import { CreateNoteModal } from 'modal'; export default function MyCalendar(params: { plugin: OZCalendarPlugin }) { const { plugin } = params; @@ -18,12 +19,22 @@ export default function MyCalendar(params: { plugin: OZCalendarPlugin }) { useEffect(() => { window.addEventListener(plugin.EVENT_TYPES.forceUpdate, forceUpdate); window.addEventListener(plugin.EVENT_TYPES.changeDate, changeDate); + window.addEventListener(plugin.EVENT_TYPES.createNote, createNote); return () => { window.removeEventListener(plugin.EVENT_TYPES.forceUpdate, forceUpdate); window.removeEventListener(plugin.EVENT_TYPES.changeDate, changeDate); + window.removeEventListener(plugin.EVENT_TYPES.createNote, createNote); }; }, []); + const createNote = () => { + let newFileModal = new CreateNoteModal( + plugin, + plugin.settings.newNoteDate === 'current-date' ? new Date() : selectedDay + ); + newFileModal.open(); + }; + const changeDate = (e: CustomEvent) => { let action = e.detail.action as DayChangeCommandAction; let currentSelectedDay = selectedDay; @@ -94,6 +105,7 @@ export default function MyCalendar(params: { plugin: OZCalendarPlugin }) { setActiveStartDate={setActiveStartDate} plugin={plugin} forceValue={forceValue} + createNote={createNote} /> > diff --git a/src/components/noteList.tsx b/src/components/noteList.tsx index 7f063d5..80e00a0 100644 --- a/src/components/noteList.tsx +++ b/src/components/noteList.tsx @@ -13,12 +13,13 @@ interface NoteListComponentParams { selectedDay: Date; setSelectedDay: (selectedDay: Date) => void; setActiveStartDate: (newActiveStartDate: Date) => void; + createNote: () => void; plugin: OZCalendarPlugin; forceValue: number; } export default function NoteListComponent(params: NoteListComponentParams) { - const { setSelectedDay, selectedDay, plugin, setActiveStartDate, forceValue } = params; + const { setSelectedDay, selectedDay, plugin, setActiveStartDate, forceValue, createNote } = params; const setNewSelectedDay = (nrChange: number) => { let newDate = dayjs(selectedDay).add(nrChange, 'day'); @@ -77,17 +78,7 @@ export default function NoteListComponent(params: NoteListComponentParams) { <>