Profile: pinned toots
All checks were successful
/ depoly (push) Successful in 1m26s

This commit is contained in:
thislight 2024-10-31 00:18:47 +08:00
parent dbddaae05c
commit e7410c7296
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
3 changed files with 28 additions and 7 deletions

View file

@ -87,12 +87,12 @@ export function createTimelineSnapshot<
T extends Timeline<mastodon.DefaultPaginationParams>, T extends Timeline<mastodon.DefaultPaginationParams>,
>( >(
timeline: Accessor<T>, timeline: Accessor<T>,
limit: Accessor<number>, params: Accessor<TimelineParamsOf<T>>,
): TimelineResource<mastodon.v1.Status[] | undefined> { ): TimelineResource<mastodon.v1.Status[] | undefined> {
const [shot, { refetch }] = createResource( const [shot, { refetch }] = createResource(
() => [timeline(), limit()] as const, () => [timeline(), params()] as const,
async ([tl, limit]) => { async ([tl, limit]) => {
const ls = await tl.list({ limit }).next(); const ls = await tl.list(limit).next();
return ls.value; return ls.value;
}, },
); );

View file

@ -39,7 +39,7 @@ import { resolveCustomEmoji } from "../masto/toot";
import { FastAverageColor } from "fast-average-color"; import { FastAverageColor } from "fast-average-color";
import { useWindowSize } from "@solid-primitives/resize-observer"; import { useWindowSize } from "@solid-primitives/resize-observer";
import { css } from "solid-styled"; import { css } from "solid-styled";
import { createTimeline } from "../masto/timelines"; import { createTimeline, createTimelineSnapshot } from "../masto/timelines";
import TootList from "../timelines/TootList"; import TootList from "../timelines/TootList";
import { createTimeSource, TimeSourceProvider } from "../platform/timesrc"; import { createTimeSource, TimeSourceProvider } from "../platform/timesrc";
import TootFilterButton from "./TootFilterButton"; import TootFilterButton from "./TootFilterButton";
@ -91,6 +91,7 @@ const Profile: Component = () => {
}); });
const [recentTootFilter, setRecentTootFilter] = createSignal({ const [recentTootFilter, setRecentTootFilter] = createSignal({
pinned: true,
boost: false, boost: false,
reply: true, reply: true,
original: true, original: true,
@ -105,6 +106,13 @@ const Profile: Component = () => {
}, },
); );
const [pinnedToots, pinnedTootChunk] = createTimelineSnapshot(
() => session().client.v1.accounts.$select(params.id).statuses,
() => {
return { limit: 20, pinned: true };
},
);
const bannerImg = () => profile()?.header; const bannerImg = () => profile()?.header;
const avatarImg = () => profile()?.avatar; const avatarImg = () => profile()?.avatar;
const displayName = () => const displayName = () =>
@ -112,6 +120,10 @@ const Profile: Component = () => {
const fullUsername = () => (profile()?.acct ? `@${profile()!.acct!}` : ""); // TODO: full user name const fullUsername = () => (profile()?.acct ? `@${profile()!.acct!}` : ""); // TODO: full user name
const description = () => profile()?.note; const description = () => profile()?.note;
const isTootListLoading = () =>
recentTootChunk.loading ||
(recentTootFilter().pinned && pinnedTootChunk.loading);
css` css`
.intro { .intro {
background-color: var(--tutu-color-surface-d); background-color: var(--tutu-color-surface-d);
@ -375,6 +387,7 @@ const Profile: Component = () => {
<div class="toot-list-toolbar"> <div class="toot-list-toolbar">
<TootFilterButton <TootFilterButton
options={{ options={{
pinned: "Pinneds",
boost: "Boosts", boost: "Boosts",
reply: "Replies", reply: "Replies",
original: "Originals", original: "Originals",
@ -386,6 +399,14 @@ const Profile: Component = () => {
</div> </div>
<TimeSourceProvider value={time}> <TimeSourceProvider value={time}>
<Show when={recentTootFilter().pinned}>
<TootList
threads={pinnedToots.list}
onUnknownThread={pinnedToots.getPath}
onChangeToot={pinnedToots.set}
/>
<Divider />
</Show>
<TootList <TootList
threads={recentToots.list} threads={recentToots.list}
onUnknownThread={recentToots.getPath} onUnknownThread={recentToots.getPath}
@ -405,9 +426,9 @@ const Profile: Component = () => {
size="large" size="large"
color="primary" color="primary"
onClick={[refetchRecentToots, "prev"]} onClick={[refetchRecentToots, "prev"]}
disabled={recentTootChunk.loading} disabled={isTootListLoading()}
> >
<Show when={recentTootChunk.loading} fallback={<ExpandMore />}> <Show when={isTootListLoading()} fallback={<ExpandMore />}>
<CircularProgress sx={{ width: "24px", height: "24px" }} /> <CircularProgress sx={{ width: "24px", height: "24px" }} />
</Show> </Show>
</IconButton> </IconButton>

View file

@ -28,7 +28,7 @@ const TrendTimelinePanel: Component<{
const [timeline, snapshot, { refetch: refetchTimeline }] = const [timeline, snapshot, { refetch: refetchTimeline }] =
createTimelineSnapshot( createTimelineSnapshot(
() => props.client.v1.trends.statuses, () => props.client.v1.trends.statuses,
() => 120, () => ({ limit: 120 }),
); );
return ( return (