mirror of
https://github.com/ozntel/oz-calendar.git
synced 2026-07-22 07:40:24 +00:00
Create a New Note Command
This commit is contained in:
parent
36a9fe4287
commit
cf616320e4
3 changed files with 28 additions and 12 deletions
|
|
@ -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}
|
||||
/>
|
||||
</>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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) {
|
|||
<>
|
||||
<div className="oz-calendar-notelist-header-container">
|
||||
<div className="oz-calendar-nav-action-plus">
|
||||
<RiAddCircleLine
|
||||
size={20}
|
||||
aria-label="Create note for today"
|
||||
onClick={() => {
|
||||
let newFileModal = new CreateNoteModal(
|
||||
plugin,
|
||||
plugin.settings.newNoteDate === 'current-date' ? new Date() : selectedDay
|
||||
);
|
||||
newFileModal.open();
|
||||
}}
|
||||
/>
|
||||
<RiAddCircleLine size={20} aria-label="Create note for today" onClick={createNote} />
|
||||
</div>
|
||||
<div className="oz-calendar-nav-action-left">
|
||||
<BsArrowLeft size={22} aria-label="Go to previous day" onClick={() => setNewSelectedDay(-1)} />
|
||||
|
|
|
|||
13
src/main.ts
13
src/main.ts
|
|
@ -14,6 +14,7 @@ export default class OZCalendarPlugin extends Plugin {
|
|||
EVENT_TYPES = {
|
||||
forceUpdate: 'ozCalendarForceUpdate',
|
||||
changeDate: 'ozCalendarChangeDate',
|
||||
createNote: 'ozCalendarCreateNote',
|
||||
};
|
||||
|
||||
dayMonthSelectorQuery = '.oz-calendar-plugin-view .react-calendar__tile.react-calendar__month-view__days__day';
|
||||
|
|
@ -96,6 +97,18 @@ export default class OZCalendarPlugin extends Plugin {
|
|||
);
|
||||
},
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: 'oz-calendar-new-note',
|
||||
name: 'Create a New Note',
|
||||
callback: () => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent(this.EVENT_TYPES.createNote, {
|
||||
detail: {},
|
||||
})
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue