TimelinePanel: rewrite thread expand algorithm

This commit is contained in:
thislight 2024-08-12 12:22:13 +08:00
parent 8787cb7ad0
commit 7c0fac95a0
2 changed files with 36 additions and 31 deletions

View file

@ -13,12 +13,13 @@ type TootThreadProps = {
onBoost?(client: mastodon.rest.Client, status: mastodon.v1.Status): void;
onBookmark?(client: mastodon.rest.Client, status: mastodon.v1.Status): void;
onExpandChange?(level: 0 | 1 | 2): void;
};
const TootThread: Component<TootThreadProps> = (props) => {
const status = () => props.status;
const now = useTimeSource();
const [expanded, setExpanded] = createSignal(false);
const expanded = () => props.expanded ?? 0;
const [inReplyTo] = createResource(
() => [props.client, status().inReplyToId || null] as const,
@ -65,10 +66,12 @@ const TootThread: Component<TootThreadProps> = (props) => {
}
`;
const nextExpandLevel = [1, 2, 2] as const;
return (
<article
classList={{ "thread-line": !!inReplyTo(), expanded: expanded() }}
onClick={() => setExpanded((x) => !x)}
classList={{ "thread-line": !!inReplyTo(), expanded: expanded() > 0 }}
onClick={() => props.onExpandChange?.(nextExpandLevel[expanded()])}
>
<Show when={inReplyTo()}>
<CompactToot
@ -80,7 +83,7 @@ const TootThread: Component<TootThreadProps> = (props) => {
<RegularToot
status={status()}
class={cardStyle.card}
actionable={expanded()}
actionable={expanded() > 0}
onBookmark={(s) => bookmark(s)}
onRetoot={(s) => boost(s)}
/>