mirror of
https://github.com/zadam/trilium.git
synced 2025-11-26 02:24:23 +01:00
chore(quick_edit): inject note context
This commit is contained in:
parent
31180afbd1
commit
29f049c411
@ -1,17 +1,34 @@
|
|||||||
import { useState } from "preact/hooks";
|
import { useContext, useEffect, useState } from "preact/hooks";
|
||||||
import Modal from "../react/Modal";
|
import Modal from "../react/Modal";
|
||||||
import "./PopupEditor.css";
|
import "./PopupEditor.css";
|
||||||
import { useTriliumEvent } from "../react/hooks";
|
import { useTriliumEvent } from "../react/hooks";
|
||||||
import NoteTitleWidget from "../note_title";
|
import NoteTitleWidget from "../note_title";
|
||||||
import NoteIcon from "../note_icon";
|
import NoteIcon from "../note_icon";
|
||||||
|
import NoteContext from "../../components/note_context";
|
||||||
|
import { ParentComponent } from "../react/react_utils";
|
||||||
|
|
||||||
|
const noteContext = new NoteContext("_popup-editor");
|
||||||
|
|
||||||
export default function PopupEditor() {
|
export default function PopupEditor() {
|
||||||
const [ shown, setShown ] = useState(false);
|
const [ shown, setShown ] = useState(false);
|
||||||
|
const parentComponent = useContext(ParentComponent);
|
||||||
|
|
||||||
|
useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => {
|
||||||
|
await noteContext.setNote(noteIdOrPath, {
|
||||||
|
viewScope: {
|
||||||
|
readOnlyTemporarilyDisabled: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
useTriliumEvent("openInPopup", () => {
|
|
||||||
setShown(true);
|
setShown(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Inject the note context
|
||||||
|
useEffect(() => {
|
||||||
|
if (!shown || !parentComponent) return;
|
||||||
|
parentComponent.handleEventInChildren("activeContextChanged", { noteContext });
|
||||||
|
}, [ shown ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={(
|
title={(
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export default class PopupEditorDialog extends Container<BasicWidget> {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.noteContext = new NoteContext("_popup-editor");
|
this.noteContext =
|
||||||
}
|
}
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
@ -34,11 +34,7 @@ export default class PopupEditorDialog extends Container<BasicWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async openInPopupEvent({ noteIdOrPath }: EventData<"openInPopup">) {
|
async openInPopupEvent({ noteIdOrPath }: EventData<"openInPopup">) {
|
||||||
await this.noteContext.setNote(noteIdOrPath, {
|
|
||||||
viewScope: {
|
|
||||||
readOnlyTemporarilyDisabled: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const colorClass = this.noteContext.note?.getColorClass();
|
const colorClass = this.noteContext.note?.getColorClass();
|
||||||
const wrapperElement = this.$wrapper.get(0)!;
|
const wrapperElement = this.$wrapper.get(0)!;
|
||||||
@ -61,7 +57,6 @@ export default class PopupEditorDialog extends Container<BasicWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dialog.on("shown.bs.modal", async () => {
|
$dialog.on("shown.bs.modal", async () => {
|
||||||
await this.handleEventInChildren("activeContextChanged", { noteContext: this.noteContext });
|
|
||||||
this.setVisibility(true);
|
this.setVisibility(true);
|
||||||
await this.handleEventInChildren("focusOnDetail", { ntxId: this.noteContext.ntxId });
|
await this.handleEventInChildren("focusOnDetail", { ntxId: this.noteContext.ntxId });
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user