mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
desktop: Key timeline runs and replies by id
So that a comment arriving above them doesn't re-render the rest of the timeline and lose its state.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
import partial from "lodash/partial";
|
||||
|
||||
import * as roles from "@app/lib/roles";
|
||||
import { mergeTimeline, timelineRuns } from "@app/lib/timelineRuns";
|
||||
import { mergeTimeline, runKey, timelineRuns } from "@app/lib/timelineRuns";
|
||||
import { authorForNodeId } from "@app/lib/utils";
|
||||
|
||||
import ExtendedTextarea from "@app/components/ExtendedTextarea.svelte";
|
||||
@@ -182,7 +182,7 @@
|
||||
<div class="discussion" class:flush>
|
||||
<div class="timeline-rail">
|
||||
<div class="activity-stream" class:has-runs={runs.length > 0}>
|
||||
{#each runs as run, runIndex (runIndex)}
|
||||
{#each runs as run (runKey(run))}
|
||||
{#if run.kind === "thread"}
|
||||
<ThreadComponent
|
||||
thread={run.entry.thread}
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
|
||||
{#snippet repliesSnippet()}
|
||||
<div class="replies-list">
|
||||
{#each replies as reply}
|
||||
{#each replies as reply (reply.id)}
|
||||
<div
|
||||
class="reply-box"
|
||||
class:highlighted={highlightedCommentId === reply.id}>
|
||||
|
||||
@@ -114,3 +114,10 @@ export function timelineRuns<A>(
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// A run's identity across updates, so that a thread keeps its open reply
|
||||
/// draft when comments are added or removed around it.
|
||||
export function runKey<A>(run: Run<A>): string {
|
||||
if (run.kind === "group") return `group:${run.entries[0].key}`;
|
||||
return `${run.kind}:${run.entry.key}`;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Thread } from "@bindings/cob/thread/Thread";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import type { Run, TimelineEntry } from "@app/lib/timelineRuns";
|
||||
import { mergeTimeline, timelineRuns } from "@app/lib/timelineRuns";
|
||||
import { mergeTimeline, runKey, timelineRuns } from "@app/lib/timelineRuns";
|
||||
|
||||
import { author, comment } from "./support/cobs";
|
||||
|
||||
@@ -148,3 +148,31 @@ describe("timelineRuns", () => {
|
||||
).toEqual(["x", "y"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("runKey", () => {
|
||||
test("a thread keeps its key when a run before it goes away", () => {
|
||||
const authorOf = (data: Data) => data.by;
|
||||
const before = timelineRuns(
|
||||
[threadEntry("t1", alice), activity("a1", bob), threadEntry("t2", bob)],
|
||||
authorOf,
|
||||
);
|
||||
const after = timelineRuns([threadEntry("t2", bob)], authorOf);
|
||||
|
||||
expect(runKey(after[0])).toBe(runKey(before[2]));
|
||||
});
|
||||
|
||||
test("keys are unique within a timeline", () => {
|
||||
const runs = timelineRuns(
|
||||
[
|
||||
activity("x", alice),
|
||||
threadEntry("x", bob),
|
||||
activity("y", bob),
|
||||
activity("z", bob),
|
||||
],
|
||||
(data: Data) => data.by,
|
||||
);
|
||||
const keys = runs.map(runKey);
|
||||
|
||||
expect(new Set(keys).size).toBe(keys.length);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user