Skip to content

Commit 2abbb7e

Browse files
authored
expose addGoogleCalendarEventCommand (#32)
1 parent 543f3d2 commit 2abbb7e

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

src/services/calendar.ts

+33-30
Original file line numberDiff line numberDiff line change
@@ -352,38 +352,40 @@ const loadGoogleCalendar = (args: OnloadArgs) => {
352352
})
353353
);
354354

355+
const addGoogleCalendarEventCommand = () => {
356+
const blockUid =
357+
window.roamAlphaAPI.ui.getFocusedBlock()?.["block-uid"] || "";
358+
const children = blockUid ? getBasicTreeByParentUid(blockUid) : [];
359+
const props = {
360+
summary: blockUid ? getTextByBlockUid(blockUid) : "No Summary",
361+
...Object.fromEntries(
362+
children.map((t) => {
363+
const [key, value] = t.text.split("::").map((s) => s.trim());
364+
const attr = key.toLowerCase();
365+
return [
366+
attr,
367+
["start", "end"].includes(attr) ? parseNlpDate(value) : value,
368+
];
369+
})
370+
),
371+
};
372+
renderOverlay({
373+
Overlay: CreateEventDialog,
374+
props: {
375+
blockUid,
376+
description: "",
377+
location: "",
378+
start: new Date(),
379+
end: addMinutes(new Date(), 30),
380+
...props,
381+
getCalendarIds,
382+
},
383+
});
384+
};
385+
355386
window.roamAlphaAPI.ui.commandPalette.addCommand({
356387
label: "Add Google Calendar Event",
357-
callback: () => {
358-
const blockUid =
359-
window.roamAlphaAPI.ui.getFocusedBlock()?.["block-uid"] || "";
360-
const children = blockUid ? getBasicTreeByParentUid(blockUid) : [];
361-
const props = {
362-
summary: blockUid ? getTextByBlockUid(blockUid) : "No Summary",
363-
...Object.fromEntries(
364-
children.map((t) => {
365-
const [key, value] = t.text.split("::").map((s) => s.trim());
366-
const attr = key.toLowerCase();
367-
return [
368-
attr,
369-
["start", "end"].includes(attr) ? parseNlpDate(value) : value,
370-
];
371-
})
372-
),
373-
};
374-
renderOverlay({
375-
Overlay: CreateEventDialog,
376-
props: {
377-
blockUid,
378-
description: "",
379-
location: "",
380-
start: new Date(),
381-
end: addMinutes(new Date(), 30),
382-
...props,
383-
getCalendarIds,
384-
},
385-
});
386-
},
388+
callback: addGoogleCalendarEventCommand,
387389
});
388390
unloads.add(() =>
389391
window.roamAlphaAPI.ui.commandPalette.removeCommand({
@@ -503,6 +505,7 @@ const loadGoogleCalendar = (args: OnloadArgs) => {
503505

504506
window.roamjs.extension.google = {
505507
fetchGoogleCalendar,
508+
addGoogleCalendarEventCommand,
506509
};
507510
unloads.add(
508511
registerSmartBlocksCommand({

0 commit comments

Comments
 (0)