added createTimelineChunk
This commit is contained in:
parent
b34580951f
commit
8fb8485663
1 changed files with 19 additions and 7 deletions
|
@ -82,6 +82,7 @@ export type TimelineFetchDirection = mastodon.Direction;
|
||||||
|
|
||||||
export type TimelineChunk = {
|
export type TimelineChunk = {
|
||||||
tl: Timeline;
|
tl: Timeline;
|
||||||
|
rebuilt: boolean;
|
||||||
chunk: readonly mastodon.v1.Status[];
|
chunk: readonly mastodon.v1.Status[];
|
||||||
done?: boolean;
|
done?: boolean;
|
||||||
direction: TimelineFetchDirection;
|
direction: TimelineFetchDirection;
|
||||||
|
@ -107,13 +108,10 @@ function collectPath<T>(node: TreeNode<T>) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTimeline(
|
function createTimelineChunk(
|
||||||
timeline: Accessor<Timeline>,
|
timeline: Accessor<Timeline>,
|
||||||
limit: Accessor<number>,
|
limit: Accessor<number>,
|
||||||
) {
|
) {
|
||||||
const lookup = new ReactiveMap<string, TreeNode<mastodon.v1.Status>>();
|
|
||||||
const [threads, setThreads] = createStore([] as mastodon.v1.Status["id"][]);
|
|
||||||
|
|
||||||
let vpMaxId: string | undefined, vpMinId: string | undefined;
|
let vpMaxId: string | undefined, vpMinId: string | undefined;
|
||||||
|
|
||||||
const fetchExtendingPage = async (
|
const fetchExtendingPage = async (
|
||||||
|
@ -146,7 +144,7 @@ export function createTimeline(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [chunk, { refetch }] = createResource(
|
return createResource(
|
||||||
() => [timeline(), limit()] as const,
|
() => [timeline(), limit()] as const,
|
||||||
async (
|
async (
|
||||||
[tl, limit],
|
[tl, limit],
|
||||||
|
@ -161,12 +159,11 @@ export function createTimeline(
|
||||||
if (rebuildTimeline) {
|
if (rebuildTimeline) {
|
||||||
vpMaxId = undefined;
|
vpMaxId = undefined;
|
||||||
vpMinId = undefined;
|
vpMinId = undefined;
|
||||||
lookup.clear();
|
|
||||||
setThreads([]);
|
|
||||||
}
|
}
|
||||||
const posts = await fetchExtendingPage(tl, direction, limit);
|
const posts = await fetchExtendingPage(tl, direction, limit);
|
||||||
return {
|
return {
|
||||||
tl,
|
tl,
|
||||||
|
rebuilt: rebuildTimeline,
|
||||||
chunk: posts.value ?? [],
|
chunk: posts.value ?? [],
|
||||||
done: posts.done,
|
done: posts.done,
|
||||||
direction,
|
direction,
|
||||||
|
@ -174,6 +171,16 @@ export function createTimeline(
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTimeline(
|
||||||
|
timeline: Accessor<Timeline>,
|
||||||
|
limit: Accessor<number>,
|
||||||
|
) {
|
||||||
|
const lookup = new ReactiveMap<string, TreeNode<mastodon.v1.Status>>();
|
||||||
|
const [threads, setThreads] = createStore([] as mastodon.v1.Status["id"][]);
|
||||||
|
|
||||||
|
const [chunk, { refetch }] = createTimelineChunk(timeline, limit);
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const chk = catchError(chunk, (e) => console.error(e));
|
const chk = catchError(chunk, (e) => console.error(e));
|
||||||
|
@ -181,6 +188,11 @@ export function createTimeline(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chk.rebuilt) {
|
||||||
|
lookup.clear();
|
||||||
|
setThreads([]);
|
||||||
|
}
|
||||||
|
|
||||||
const existence = [] as boolean[];
|
const existence = [] as boolean[];
|
||||||
|
|
||||||
for (const [idx, status] of chk.chunk.entries()) {
|
for (const [idx, status] of chk.chunk.entries()) {
|
||||||
|
|
Loading…
Reference in a new issue