diff --git a/frontend/src/ofrak/remote_resource.js b/frontend/src/ofrak/remote_resource.js index 77cad8187..059d32ba7 100644 --- a/frontend/src/ofrak/remote_resource.js +++ b/frontend/src/ofrak/remote_resource.js @@ -468,13 +468,13 @@ export class RemoteResource extends Resource { return find_replace_results; } - async add_comment(optional_range, comment) { + async add_comment(optional_range, comment_text) { await fetch(`${this.uri}/add_comment`, { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify([optional_range, comment]), + body: JSON.stringify([optional_range, comment_text]), }).then(async (r) => { if (!r.ok) { throw Error(JSON.stringify(await r.json(), undefined, 2)); @@ -508,13 +508,13 @@ export class RemoteResource extends Resource { await this.update_script(); } - async delete_comment(optional_range) { + async delete_comment(optional_range, comment_text) { await fetch(`${this.uri}/delete_comment`, { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify(optional_range), + body: JSON.stringify([optional_range, comment_text]), }).then(async (r) => { if (!r.ok) { throw Error(JSON.stringify(await r.json(), undefined, 2)); diff --git a/frontend/src/ofrak/resource.js b/frontend/src/ofrak/resource.js index c9241de6e..f442ae2f1 100644 --- a/frontend/src/ofrak/resource.js +++ b/frontend/src/ofrak/resource.js @@ -365,11 +365,11 @@ export class Resource { throw new NotImplementedError("summarize_tree"); } - async add_comment(optional_range, comment) { + async add_comment(optional_range, comment_text) { throw new NotImplementedError("add_comment"); } - async delete_comment(optional_range) { + async delete_comment(optional_range, comment_text) { throw new NotImplementedError("delete_comment"); } diff --git a/frontend/src/resource/ResourceTreeNode.svelte b/frontend/src/resource/ResourceTreeNode.svelte index 30df8cfcb..5325e62c8 100644 --- a/frontend/src/resource/ResourceTreeNode.svelte +++ b/frontend/src/resource/ResourceTreeNode.svelte @@ -244,15 +244,17 @@ > {rootResource.get_caption()} - {#await commentsPromise then comments} - {#each comments as comment} -
- -
+ {#await commentsPromise then comment_group} + {#each comment_group as [comment_range, comment_strs]} + {#each comment_strs as comment_text} +
+ +
+ {/each} {/each} {/await} diff --git a/frontend/src/views/Comment.svelte b/frontend/src/views/Comment.svelte index d7e6b0459..dbabf6d78 100644 --- a/frontend/src/views/Comment.svelte +++ b/frontend/src/views/Comment.svelte @@ -20,17 +20,18 @@ import Hoverable from "../utils/Hoverable.svelte"; import Icon from "../utils/Icon.svelte"; export let comment, rootResource, selfId; - let text = comment[1]; - let addresses = text.matchAll("#[a-fA-F0-9]+[@0x[0-9a-fA-F]+]*", text); + let addresses = comment.comment_text.matchAll( + "#[a-fA-F0-9]+(@0x[0-9a-fA-F]+)?" + ); let text_elements = []; Array.from(addresses).forEach((location) => { - let text_split = text.split(location[0]); + let text_split = comment.comment_text.split(location[0]); text_elements.push(text_split[0]); text_elements.push(createAddressButton(location[0])); - text = text_split.slice(1).join(location[0]); + comment.comment_text = text_split.slice(1).join(location[0]); }); - text_elements.push(text); + text_elements.push(comment.comment_text); function createAddressButton(location) { let resource_id; @@ -53,11 +54,14 @@ return button; } - async function onDeleteClick(optional_range) { + async function onDeleteClick(comment) { // Delete the selected comment. // As a side effect, the corresponding resource gets selected. $selected = selfId; - await rootResource.delete_comment(optional_range); + await rootResource.delete_comment( + comment.comment_range, + comment.comment_text + ); $resourceNodeDataMap[$selected].commentsPromise = rootResource.get_comments(); } @@ -65,7 +69,7 @@
-