From 5be9bb47a77cfeb6498b9e3cd4edb7b13f26d036 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 9 Aug 2025 19:41:49 +0300 Subject: [PATCH] feat(react/bulk_actions): port add relation --- .../bulk_actions/relation/add_relation.ts | 70 ------------------- .../bulk_actions/relation/add_relation.tsx | 52 ++++++++++++++ apps/client/src/widgets/react/FormTextBox.tsx | 8 ++- 3 files changed, 57 insertions(+), 73 deletions(-) delete mode 100644 apps/client/src/widgets/bulk_actions/relation/add_relation.ts create mode 100644 apps/client/src/widgets/bulk_actions/relation/add_relation.tsx diff --git a/apps/client/src/widgets/bulk_actions/relation/add_relation.ts b/apps/client/src/widgets/bulk_actions/relation/add_relation.ts deleted file mode 100644 index 165162d85..000000000 --- a/apps/client/src/widgets/bulk_actions/relation/add_relation.ts +++ /dev/null @@ -1,70 +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("add_relation.add_relation")}
- - - -
${t("add_relation.to")}
- -
- -
-
- - - - - - -`; - -export default class AddRelationBulkAction extends AbstractBulkAction { - static get actionName() { - return "addRelation"; - } - static get actionTitle() { - return t("add_relation.add_relation"); - } - - 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/add_relation.tsx b/apps/client/src/widgets/bulk_actions/relation/add_relation.tsx new file mode 100644 index 000000000..927c10ace --- /dev/null +++ b/apps/client/src/widgets/bulk_actions/relation/add_relation.tsx @@ -0,0 +1,52 @@ +import SpacedUpdate from "../../../services/spaced_update.js"; +import AbstractBulkAction, { ActionDefinition } from "../abstract_bulk_action.js"; +import noteAutocompleteService from "../../../services/note_autocomplete.js"; +import { t } from "../../../services/i18n.js"; +import BulkAction, { BulkActionText } from "../BulkAction.jsx"; +import NoteAutocomplete from "../../react/NoteAutocomplete.jsx"; +import FormTextBox from "../../react/FormTextBox.jsx"; +import { useEffect, useState } from "preact/hooks"; +import { useSpacedUpdate } from "../../react/hooks.jsx"; + +function AddRelationBulkActionComponent({ 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 ( + + + + + + + + ) +} + +export default class AddRelationBulkAction extends AbstractBulkAction { + + static get actionName() { + return "addRelation"; + } + static get actionTitle() { + return t("add_relation.add_relation"); + } + + doRender() { + return + } +} diff --git a/apps/client/src/widgets/react/FormTextBox.tsx b/apps/client/src/widgets/react/FormTextBox.tsx index e06004fb5..476825d96 100644 --- a/apps/client/src/widgets/react/FormTextBox.tsx +++ b/apps/client/src/widgets/react/FormTextBox.tsx @@ -1,13 +1,13 @@ import { InputHTMLAttributes, RefObject } from "preact/compat"; -interface FormTextBoxProps extends Pick, "placeholder" | "autoComplete" | "className" | "type" | "name" | "pattern" | "title"> { +interface FormTextBoxProps extends Pick, "placeholder" | "autoComplete" | "className" | "type" | "name" | "pattern" | "title" | "style"> { id?: string; currentValue?: string; onChange?(newValue: string): void; inputRef?: RefObject; } -export default function FormTextBox({ id, type, name, className, currentValue, onChange, autoComplete, inputRef, placeholder, title, pattern }: FormTextBoxProps) { +export default function FormTextBox({ id, type, name, className, currentValue, onChange, autoComplete, inputRef, placeholder, title, pattern, style }: FormTextBoxProps) { return ( onChange?.(e.currentTarget.value)} /> + onInput={e => onChange?.(e.currentTarget.value)} + style={style} + /> ); } \ No newline at end of file