From fa44e12868bd5c4a1c3541629fe0200c3d83d97d Mon Sep 17 00:00:00 2001 From: dvirtz Date: Thu, 5 Dec 2024 23:39:06 +0000 Subject: [PATCH] refactor: remove edit note hack --- src/common/musicbrainz/edit-note.ts | 9 +-------- src/types/MB.d.ts | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/common/musicbrainz/edit-note.ts b/src/common/musicbrainz/edit-note.ts index 65b0bf6..de8af5f 100644 --- a/src/common/musicbrainz/edit-note.ts +++ b/src/common/musicbrainz/edit-note.ts @@ -1,15 +1,8 @@ -// from https://github.com/kellnerd/es-utils/blob/main/dom/react.js -function setReactTextareaValue(input: HTMLTextAreaElement, value: string) { - const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set?.bind(Object); - setter?.call(input, value); - input.dispatchEvent(new Event('input', {bubbles: true})); -} - export function addEditNote(message: string) { const textArea = document.querySelector('#edit-note-text') as HTMLTextAreaElement; const note = editNote(message); if (!textArea.value.includes(message)) { - setReactTextareaValue(textArea, `${textArea.value}\n${note}`); + MB.relationshipEditor.dispatch({type: 'update-edit-note', editNote: `${textArea.value}\n${note}`}); } } diff --git a/src/types/MB.d.ts b/src/types/MB.d.ts index cb54ee1..df24b7b 100644 --- a/src/types/MB.d.ts +++ b/src/types/MB.d.ts @@ -456,6 +456,10 @@ declare global { | Array<[Array, WsJsEditWorkCreateT]>; responseData: WsJsEditResponseT; type: 'update-submitted-relationships'; + } + | { + editNote: string; + type: 'update-edit-note'; }; type MediumStateTreeT = tree.ImmutableTree<[MediumWithRecordingsT, MediumRecordingStateTreeT]> | null;