TrendTimelinePanel: improved error handling
This commit is contained in:
parent
971fb6a8e7
commit
f6c540a3ad
3 changed files with 69 additions and 53 deletions
|
@ -1,5 +1,5 @@
|
|||
import { type mastodon } from "masto";
|
||||
import { Accessor, createEffect, createResource } from "solid-js";
|
||||
import { Accessor, catchError, createEffect, createResource } from "solid-js";
|
||||
import { createStore } from "solid-js/store";
|
||||
|
||||
type TimelineFetchTips = {
|
||||
|
@ -114,7 +114,7 @@ export function createTimelineSnapshot(
|
|||
timeline: Accessor<Timeline>,
|
||||
limit: Accessor<number>,
|
||||
) {
|
||||
const [shot, {refetch}] = createResource(
|
||||
const [shot, { refetch }] = createResource(
|
||||
() => [timeline(), limit()] as const,
|
||||
async ([tl, limit]) => {
|
||||
const ls = await tl.list({ limit }).next();
|
||||
|
@ -125,7 +125,7 @@ export function createTimelineSnapshot(
|
|||
const [snapshot, setSnapshot] = createStore([] as mastodon.v1.Status[][]);
|
||||
|
||||
createEffect(() => {
|
||||
const nls = shot();
|
||||
const nls = catchError(shot, (e) => console.error(e));
|
||||
if (!nls) return;
|
||||
const ols = Array.from(snapshot);
|
||||
// The algorithm below assumes the snapshot is not changing
|
||||
|
@ -154,10 +154,14 @@ export function createTimelineSnapshot(
|
|||
}
|
||||
});
|
||||
|
||||
return [snapshot, shot, {
|
||||
refetch,
|
||||
mutate: setSnapshot
|
||||
}] as const;
|
||||
return [
|
||||
snapshot,
|
||||
shot,
|
||||
{
|
||||
refetch,
|
||||
mutate: setSnapshot,
|
||||
},
|
||||
] as const;
|
||||
}
|
||||
|
||||
export function createTimeline(timeline: Accessor<Timeline>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue