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