fix #35: the actions don't update the status
All checks were successful
/ depoly (push) Successful in 1m18s

This commit is contained in:
thislight 2024-11-08 23:17:01 +08:00
parent 17e738e21a
commit 29eaf1a02b
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
5 changed files with 114 additions and 96 deletions

View file

@ -18,9 +18,9 @@ type Timeline<T extends mastodon.DefaultPaginationParams> = {
type TimelineParamsOf<T> = T extends Timeline<infer P> ? P : never;
function createControlsForLookup(
lookup: ReactiveMap<string, TreeNode<mastodon.v1.Status>>,
) {
export type ThreadNode = TreeNode<mastodon.v1.Status>;
function createControlsForLookup(lookup: ReactiveMap<string, ThreadNode>) {
return {
get(id: string) {
return lookup.get(id);
@ -37,7 +37,7 @@ function createControlsForLookup(
set(id: string, value: mastodon.v1.Status) {
const node = untrack(() => lookup.get(id));
if (!node) return;
lookup.set(id, {...node, value});
lookup.set(id, { ...node, value });
},
};
}
@ -45,7 +45,7 @@ function createControlsForLookup(
export function createTimelineControlsForArray(
status: () => mastodon.v1.Status[] | undefined,
): TimelineControls {
const lookup = new ReactiveMap<string, TreeNode<mastodon.v1.Status>>();
const lookup = new ReactiveMap<string, ThreadNode>();
const [threads, setThreads] = createStore([] as mastodon.v1.Status["id"][]);
@ -55,22 +55,24 @@ export function createTimelineControlsForArray(
});
if (!nls) return;
setThreads([]);
lookup.clear();
batch(() => {
setThreads([]);
lookup.clear();
const existence = [] as boolean[];
for (const status of nls) {
lookup.set(status.id, {
value: status,
});
}
});
for (const [idx, status] of nls.entries()) {
existence[idx] = !!untrack(() => lookup.get(status.id));
lookup.set(status.id, {
value: status,
});
}
untrack(() => {
for (const status of nls) {
const node = lookup.get(status.id)!;
const parent = status.inReplyToId
? lookup.get(status.inReplyToId)
: undefined;
for (const status of nls) {
const node = untrack(() => lookup.get(status.id))!;
if (status.inReplyToId) {
const parent = lookup.get(status.inReplyToId);
if (parent) {
const children = parent.children ?? [];
if (!children.find((x) => x.value.id == status.id)) {
@ -80,12 +82,13 @@ export function createTimelineControlsForArray(
node.parent = parent;
}
}
}
});
const newThreads = nls
.filter((x, i) => !existence[i])
.map((x) => x.id)
.filter((id) => (lookup.get(id)!.children?.length ?? 0) === 0);
const newThreads = untrack(() =>
nls
.map((x) => x.id)
.filter((id) => (lookup.get(id)!.children?.length ?? 0) === 0),
);
setThreads(newThreads);
});
@ -269,32 +272,34 @@ export function createTimeline<
return;
}
if (chk.rebuilt) {
lookup.clear();
setThreads([]);
}
const existence = [] as boolean[];
for (const [idx, status] of chk.chunk.entries()) {
existence[idx] = !!untrack(() => lookup.get(status.id));
lookup.set(status.id, {
value: status,
});
}
batch(() => {
if (chk.rebuilt) {
lookup.clear();
setThreads([]);
}
for (const [idx, status] of chk.chunk.entries()) {
existence[idx] = !!untrack(() => lookup.get(status.id));
lookup.set(status.id, {
value: status,
});
}
});
for (const status of chk.chunk) {
const node = untrack(() => lookup.get(status.id))!;
if (status.inReplyToId) {
const parent = lookup.get(status.inReplyToId);
if (parent) {
const children = parent.children ?? [];
if (!children.find((x) => x.value.id == status.id)) {
children.push(node);
}
parent.children = children;
node.parent = parent;
const parent = untrack(() =>
status.inReplyToId ? lookup.get(status.inReplyToId) : undefined,
);
if (parent) {
const children = parent.children ?? [];
if (!children.find((x) => x.value.id == status.id)) {
children.push(node);
}
parent.children = children;
node.parent = parent;
}
}