mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-11 19:44:00 -06:00
feat(collections/calendar): context menu option to delete event
This commit is contained in:
parent
218b9404fc
commit
a0edf00caa
@ -2037,6 +2037,9 @@
|
|||||||
"start-presentation": "Start presentation",
|
"start-presentation": "Start presentation",
|
||||||
"slide-overview": "Toggle an overview of the slides"
|
"slide-overview": "Toggle an overview of the slides"
|
||||||
},
|
},
|
||||||
|
"calendar_view": {
|
||||||
|
"delete_note": "Delete note..."
|
||||||
|
},
|
||||||
"command_palette": {
|
"command_palette": {
|
||||||
"tree-action-name": "Tree: {{name}}",
|
"tree-action-name": "Tree: {{name}}",
|
||||||
"export_note_title": "Export Note",
|
"export_note_title": "Export Note",
|
||||||
|
|||||||
28
apps/client/src/widgets/collections/calendar/context_menu.ts
Normal file
28
apps/client/src/widgets/collections/calendar/context_menu.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import FNote from "../../../entities/fnote";
|
||||||
|
import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
|
||||||
|
import link_context_menu from "../../../menus/link_context_menu";
|
||||||
|
import branches from "../../../services/branches";
|
||||||
|
import { t } from "../../../services/i18n";
|
||||||
|
|
||||||
|
export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, parentNote: FNote) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
contextMenu.show({
|
||||||
|
x: e.pageX,
|
||||||
|
y: e.pageY,
|
||||||
|
items: [
|
||||||
|
...link_context_menu.getItems(),
|
||||||
|
{ kind: "separator" },
|
||||||
|
{
|
||||||
|
title: t("calendar_view.delete_note"),
|
||||||
|
uiIcon: "bx bx-trash",
|
||||||
|
handler: async () => {
|
||||||
|
const branchId = parentNote.childToBranch[noteId];
|
||||||
|
await branches.deleteNotes([ branchId ], false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
selectMenuItemHandler: ({ command }) => link_context_menu.handleLinkContextMenuItem(command, noteId),
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -20,6 +20,7 @@ import Button, { ButtonGroup } from "../../react/Button";
|
|||||||
import ActionButton from "../../react/ActionButton";
|
import ActionButton from "../../react/ActionButton";
|
||||||
import { RefObject } from "preact";
|
import { RefObject } from "preact";
|
||||||
import TouchBar, { TouchBarButton, TouchBarLabel, TouchBarSegmentedControl, TouchBarSpacer } from "../../react/TouchBar";
|
import TouchBar, { TouchBarButton, TouchBarLabel, TouchBarSegmentedControl, TouchBarSpacer } from "../../react/TouchBar";
|
||||||
|
import { openCalendarContextMenu } from "./context_menu";
|
||||||
|
|
||||||
interface CalendarViewData {
|
interface CalendarViewData {
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
|
|||||||
const plugins = usePlugins(isEditable, isCalendarRoot);
|
const plugins = usePlugins(isEditable, isCalendarRoot);
|
||||||
const locale = useLocale();
|
const locale = useLocale();
|
||||||
|
|
||||||
const { eventDidMount } = useEventDisplayCustomization();
|
const { eventDidMount } = useEventDisplayCustomization(note);
|
||||||
const editingProps = useEditing(note, isEditable, isCalendarRoot);
|
const editingProps = useEditing(note, isEditable, isCalendarRoot);
|
||||||
|
|
||||||
// React to changes.
|
// React to changes.
|
||||||
@ -253,7 +254,7 @@ function useEditing(note: FNote, isEditable: boolean, isCalendarRoot: boolean) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function useEventDisplayCustomization() {
|
function useEventDisplayCustomization(parentNote: FNote) {
|
||||||
const eventDidMount = useCallback((e: EventMountArg) => {
|
const eventDidMount = useCallback((e: EventMountArg) => {
|
||||||
const { iconClass, promotedAttributes } = e.event.extendedProps;
|
const { iconClass, promotedAttributes } = e.event.extendedProps;
|
||||||
|
|
||||||
@ -302,6 +303,11 @@ function useEventDisplayCustomization() {
|
|||||||
}
|
}
|
||||||
$(mainContainer ?? e.el).append($(promotedAttributesHtml));
|
$(mainContainer ?? e.el).append($(promotedAttributesHtml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.el.addEventListener("contextmenu", (contextMenuEvent) => {
|
||||||
|
const noteId = e.event.extendedProps.noteId;
|
||||||
|
openCalendarContextMenu(contextMenuEvent, noteId, parentNote);
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
return { eventDidMount };
|
return { eventDidMount };
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user