diff --git a/apps/client/src/widgets/bulk_actions/relation/update_relation_target.ts b/apps/client/src/widgets/bulk_actions/relation/update_relation_target.ts deleted file mode 100644 index b75dd40fa..000000000 --- a/apps/client/src/widgets/bulk_actions/relation/update_relation_target.ts +++ /dev/null @@ -1,74 +0,0 @@ -import SpacedUpdate from "../../../services/spaced_update.js"; -import AbstractBulkAction from "../abstract_bulk_action.js"; -import noteAutocompleteService from "../../../services/note_autocomplete.js"; -import { t } from "../../../services/i18n.js"; - -const TPL = /*html*/` - - -
-
${t("update_relation_target.update_relation")}
- - - -
${t("update_relation_target.to")}
- -
- -
-
- - - - - - -`; - -export default class UpdateRelationTargetBulkAction extends AbstractBulkAction { - static get actionName() { - return "updateRelationTarget"; - } - static get actionTitle() { - return t("update_relation_target.update_relation_target"); - } - - doRender() { - const $action = $(TPL); - - const $relationName = $action.find(".relation-name"); - $relationName.val(this.actionDef.relationName || ""); - - const $targetNote = $action.find(".target-note"); - noteAutocompleteService.initNoteAutocomplete($targetNote); - $targetNote.setNote(this.actionDef.targetNoteId); - - $targetNote.on("autocomplete:closed", () => spacedUpdate.scheduleUpdate()); - - const spacedUpdate = new SpacedUpdate(async () => { - await this.saveAction({ - relationName: $relationName.val(), - targetNoteId: $targetNote.getSelectedNoteId() - }); - }, 1000); - - $relationName.on("input", () => spacedUpdate.scheduleUpdate()); - $targetNote.on("input", () => spacedUpdate.scheduleUpdate()); - - return $action; - } -} diff --git a/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx b/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx new file mode 100644 index 000000000..b2d593544 --- /dev/null +++ b/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx @@ -0,0 +1,60 @@ +import AbstractBulkAction, { ActionDefinition } from "../abstract_bulk_action.js"; +import { t } from "../../../services/i18n.js"; +import BulkAction, { BulkActionText } from "../BulkAction.jsx"; +import FormTextBox from "../../react/FormTextBox.jsx"; +import NoteAutocomplete from "../../react/NoteAutocomplete.jsx"; +import { useEffect, useState } from "preact/hooks"; +import { useSpacedUpdate } from "../../react/hooks.jsx"; + +function UpdateRelationTargetComponent({ bulkAction, actionDef }: { bulkAction: AbstractBulkAction, actionDef: ActionDefinition }) { + const [ relationName, setRelationName ] = useState(actionDef.relationName); + const [ targetNoteId, setTargetNoteId ] = useState(actionDef.targetNoteId); + const spacedUpdate = useSpacedUpdate(() => bulkAction.saveAction({ relationName, targetNoteId })); + useEffect(() => spacedUpdate.scheduleUpdate(), [ relationName, targetNoteId ]); + + return ( + +

{t("update_relation_target.on_all_matched_notes")}:

+ + + } + > + + + + + +
+ ) +} + +export default class UpdateRelationTargetBulkAction extends AbstractBulkAction { + + static get actionName() { + return "updateRelationTarget"; + } + + static get actionTitle() { + return t("update_relation_target.update_relation_target"); + } + + doRender() { + return + } + +} diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsx index 926a9e328..580c00002 100644 --- a/apps/client/src/widgets/react/NoteAutocomplete.tsx +++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx @@ -3,12 +3,14 @@ import { t } from "../../services/i18n"; import { useEffect } from "react"; import note_autocomplete, { Options, type Suggestion } from "../../services/note_autocomplete"; import type { RefObject } from "preact"; +import { CSSProperties } from "preact/compat"; interface NoteAutocompleteProps { inputRef?: RefObject; text?: string; placeholder?: string; container?: RefObject; + containerStyle?: CSSProperties; opts?: Omit; onChange?: (suggestion: Suggestion | null) => void; onTextChange?: (text: string) => void; @@ -16,7 +18,7 @@ interface NoteAutocompleteProps { noteId?: string; } -export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, onChange, onTextChange, container, opts, noteId, noteIdChanged }: NoteAutocompleteProps) { +export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, onChange, onTextChange, container, containerStyle, opts, noteId, noteIdChanged }: NoteAutocompleteProps) { const ref = _ref ?? useRef(null); useEffect(() => { @@ -67,7 +69,7 @@ export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, on }, [text]); return ( -
+