mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 02:59:03 +01:00
refactor(react/collections/calendar): refactor into API
This commit is contained in:
parent
b93d9a6b6e
commit
f0b5954c54
33
apps/client/src/widgets/collections/calendar/api.ts
Normal file
33
apps/client/src/widgets/collections/calendar/api.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { CreateChildrenResponse } from "@triliumnext/commons";
|
||||
import server from "../../../services/server";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import { setLabel } from "../../../services/attributes";
|
||||
|
||||
interface NewEventOpts {
|
||||
title: string;
|
||||
startDate: string;
|
||||
endDate?: string | null;
|
||||
startTime?: string | null;
|
||||
endTime?: string | null;
|
||||
}
|
||||
|
||||
export async function newEvent(parentNote: FNote, { title, startDate, endDate, startTime, endTime }: NewEventOpts) {
|
||||
// Create the note.
|
||||
const { note } = await server.post<CreateChildrenResponse>(`notes/${parentNote.noteId}/children?target=into`, {
|
||||
title,
|
||||
content: "",
|
||||
type: "text"
|
||||
});
|
||||
|
||||
// Set the attributes.
|
||||
setLabel(note.noteId, "startDate", startDate);
|
||||
if (endDate) {
|
||||
setLabel(note.noteId, "endDate", endDate);
|
||||
}
|
||||
if (startTime) {
|
||||
setLabel(note.noteId, "startTime", startTime);
|
||||
}
|
||||
if (endTime) {
|
||||
setLabel(note.noteId, "endTime", endTime);
|
||||
}
|
||||
}
|
||||
@ -6,13 +6,14 @@ import "./index.css";
|
||||
import { useNoteLabel, useNoteLabelBoolean, useResizeObserver, useSpacedUpdate, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";
|
||||
import { CreateChildrenResponse, LOCALE_IDS } from "@triliumnext/commons";
|
||||
import { Calendar as FullCalendar } from "@fullcalendar/core";
|
||||
import { setLabel } from "../../../services/attributes";
|
||||
import { removeOwnedAttributesByNameOrType, setLabel } from "../../../services/attributes";
|
||||
import { circle } from "leaflet";
|
||||
import server from "../../../services/server";
|
||||
import { parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
|
||||
import dialog from "../../../services/dialog";
|
||||
import { t } from "../../../services/i18n";
|
||||
import { buildEvents, buildEventsForCalendar } from "./event_builder";
|
||||
import { newEvent } from "./api";
|
||||
|
||||
interface CalendarViewData {
|
||||
|
||||
@ -67,13 +68,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
|
||||
const locale = useLocale();
|
||||
|
||||
const onCalendarSelection = useCallback(async (e: DateSelectArg) => {
|
||||
// Handle start and end date
|
||||
const { startDate, endDate } = parseStartEndDateFromEvent(e);
|
||||
if (!startDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle start and end time.
|
||||
if (!startDate) return;
|
||||
const { startTime, endTime } = parseStartEndTimeFromEvent(e);
|
||||
|
||||
// Ask for the title
|
||||
@ -82,25 +78,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the note.
|
||||
const { note: eventNote } = await server.post<CreateChildrenResponse>(`notes/${note.noteId}/children?target=into`, {
|
||||
title,
|
||||
content: "",
|
||||
type: "text"
|
||||
});
|
||||
|
||||
// Set the attributes.
|
||||
setLabel(eventNote.noteId, "startDate", startDate);
|
||||
if (endDate) {
|
||||
setLabel(eventNote.noteId, "endDate", endDate);
|
||||
}
|
||||
if (startTime) {
|
||||
setLabel(eventNote.noteId, "startTime", startTime);
|
||||
}
|
||||
if (endTime) {
|
||||
setLabel(eventNote.noteId, "endTime", endTime);
|
||||
}
|
||||
}, []);
|
||||
newEvent(note, { title, startDate, endDate, startTime, endTime });
|
||||
}, [ note ]);
|
||||
|
||||
return (plugins &&
|
||||
<div className="calendar-view" ref={containerRef}>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user