tutu/src/timelines/TrendTimelinePanel.tsx

75 lines
1.9 KiB
TypeScript
Raw Normal View History

import {
Component,
createSignal,
Match,
Switch as JsSwitch,
ErrorBoundary,
} from "solid-js";
import { type mastodon } from "masto";
import { Button } from "@suid/material";
import { createTimelineSnapshot } from "../masto/timelines.js";
import PullDownToRefresh from "./PullDownToRefresh.jsx";
2024-10-29 15:22:25 +08:00
import TootList from "./TootList.jsx";
const TrendTimelinePanel: Component<{
client: mastodon.rest.Client;
}> = (props) => {
const [scrollLinked, setScrollLinked] = createSignal<HTMLElement>();
const [tl, snapshot, { refetch: refetchTimeline }] = createTimelineSnapshot(
() => props.client.v1.trends.statuses,
() => ({ limit: 120 }),
);
return (
<ErrorBoundary
fallback={(err, reset) => {
return <p>Oops: {String(err)}</p>;
}}
>
<PullDownToRefresh
linkedElement={scrollLinked()}
loading={snapshot.loading}
2024-10-30 23:25:33 +08:00
onRefresh={() => refetchTimeline("next")}
/>
<div
ref={(e) =>
setTimeout(() => {
setScrollLinked(e.parentElement!);
}, 0)
}
>
2024-10-29 15:22:25 +08:00
<TootList
threads={tl.list}
onUnknownThread={tl.getPath}
onChangeToot={tl.set}
2024-10-29 15:22:25 +08:00
/>
</div>
<div
style={{
display: "flex",
padding: "20px 0 calc(20px + var(--safe-area-inset-bottom, 0px))",
"align-items": "center",
"justify-content": "center",
"flex-flow": "column",
2024-10-27 00:29:14 +08:00
gap: "20px",
}}
>
<JsSwitch>
<Match when={snapshot.error}>
<p>{`Oops: ${snapshot.error}`}</p>
<Button
variant="contained"
onClick={[refetchTimeline, undefined]}
disabled={snapshot.loading}
>
Retry
</Button>
</Match>
</JsSwitch>
</div>
</ErrorBoundary>
);
};
export default TrendTimelinePanel;