Skip to content

Commit f8c982b

Browse files
Fix help response thread overwrites — fetch current note from DB before appending
Replies now read the existing response_note from Supabase before appending the new reply, avoiding race conditions where the local reactive state could be stale. The append logic moved from the UI to the store's respond() function with an appendToExisting flag. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c48762f commit f8c982b

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/components/CellLibraryPanel.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,11 @@ function getAnnotationLayers(): string[] {
436436
437437
async function submitResponse(req: HelpRequest, andResolve = false) {
438438
if (!responseNote.value.trim()) return;
439-
// If there's an existing response, append as a thread entry
440-
const userName = backend.userName || 'Unknown';
441-
let note = responseNote.value.trim();
442-
if (req.responseNote) {
443-
note = `${req.responseNote}\n---\n${userName}: ${note}`;
444-
}
445439
const payload = {
446-
note,
440+
note: responseNote.value.trim(),
447441
url: responseUrl.value.trim() || undefined,
448442
annotationLayer: responseAnnotationLayer.value.trim() || undefined,
443+
appendToExisting: !!req.responseNote, // signal to append, not replace
449444
};
450445
if (andResolve) {
451446
await helpStore.resolve(req.id, payload);

src/store.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,28 @@ export const useHelpRequestStore = defineStore('helpRequests', () => {
10611061
}
10621062

10631063
/** Add a response to a help request WITHOUT resolving it. */
1064-
async function respond(id: string, response: { note?: string; url?: string; annotationLayer?: string }) {
1064+
async function respond(id: string, response: { note?: string; url?: string; annotationLayer?: string; appendToExisting?: boolean }) {
10651065
const backend = useProofreadingBackendStore();
10661066
const responderName = backend.userName || backend.userEmail?.split('@')[0] || 'Anonymous';
1067+
1068+
// If appending to an existing thread, fetch current note from DB to avoid overwrites
1069+
let finalNote = response.note || '';
1070+
if (response.appendToExisting && response.note) {
1071+
const { data } = await supabase
1072+
.from('help_requests')
1073+
.select('response_note')
1074+
.eq('id', id)
1075+
.single();
1076+
const existing = data?.response_note || '';
1077+
if (existing) {
1078+
finalNote = `${existing}\n---\n${responderName}: ${response.note}`;
1079+
}
1080+
}
1081+
10671082
const updateData: Record<string, any> = {
10681083
resolved_by_name: responderName,
10691084
};
1070-
if (response.note) updateData.response_note = response.note;
1085+
if (finalNote) updateData.response_note = finalNote;
10711086
if (response.url) updateData.response_url = response.url;
10721087
if (response.annotationLayer) updateData.response_annotation_layer = response.annotationLayer;
10731088

@@ -1083,7 +1098,7 @@ export const useHelpRequestStore = defineStore('helpRequests', () => {
10831098
const r = requests.value.find(x => x.id === id);
10841099
if (r) {
10851100
r.resolvedByName = responderName;
1086-
if (response.note) r.responseNote = response.note;
1101+
if (finalNote) r.responseNote = finalNote;
10871102
if (response.url) r.responseUrl = response.url;
10881103
if (response.annotationLayer) r.responseAnnotationLayer = response.annotationLayer;
10891104
}

0 commit comments

Comments
 (0)