TootBottomSheet: basic toot switching (#6)
All checks were successful
/ depoly (push) Successful in 1m2s

This commit is contained in:
thislight 2024-09-14 13:40:50 +08:00
parent e8c1b796a6
commit 7a04598375
No known key found for this signature in database
GPG key ID: A50F9451AC56A63E

View file

@ -1,4 +1,4 @@
import { useNavigate, useParams } from "@solidjs/router"; import { useLocation, useNavigate, useParams } from "@solidjs/router";
import { import {
createEffect, createEffect,
createRenderEffect, createRenderEffect,
@ -17,7 +17,11 @@ import {
Toolbar, Toolbar,
} from "@suid/material"; } from "@suid/material";
import { Title } from "../material/typography"; import { Title } from "../material/typography";
import { Close as CloseIcon, Send } from "@suid/icons-material"; import {
ArrowBack as BackIcon,
Close as CloseIcon,
Send,
} from "@suid/icons-material";
import { isiOS } from "../platform/host"; import { isiOS } from "../platform/host";
import { createUnauthorizedClient, useSessions } from "../masto/clients"; import { createUnauthorizedClient, useSessions } from "../masto/clients";
import { resolveCustomEmoji } from "../masto/toot"; import { resolveCustomEmoji } from "../masto/toot";
@ -41,6 +45,7 @@ function getCache(acct: string, id: string) {
const TootBottomSheet: Component = (props) => { const TootBottomSheet: Component = (props) => {
const params = useParams<{ acct: string; id: string }>(); const params = useParams<{ acct: string; id: string }>();
const location = useLocation<{ tootBottomSheetPushedCount?: number }>();
const navigate = useNavigate(); const navigate = useNavigate();
const allSession = useSessions(); const allSession = useSessions();
const acctText = () => decodeURIComponent(params.acct); const acctText = () => decodeURIComponent(params.acct);
@ -62,6 +67,10 @@ const TootBottomSheet: Component = (props) => {
return session().account; return session().account;
}; };
const pushedCount = () => {
return location.state?.tootBottomSheetPushedCount || 0;
};
const [remoteToot, { mutate: setRemoteToot }] = createResource( const [remoteToot, { mutate: setRemoteToot }] = createResource(
() => [session().client, params.id] as const, () => [session().client, params.id] as const,
async ([client, id]) => { async ([client, id]) => {
@ -71,6 +80,13 @@ const TootBottomSheet: Component = (props) => {
const toot = () => remoteToot() ?? getCache(acctText(), params.id); const toot = () => remoteToot() ?? getCache(acctText(), params.id);
createEffect(() => {
const tootId = toot()?.id;
if (!tootId) return;
const elementId = `toot-${tootId}`;
document.getElementById(elementId)?.scrollIntoView({ behavior: "smooth" });
});
const [tootContext] = createResource( const [tootContext] = createResource(
() => [session().client, params.id] as const, () => [session().client, params.id] as const,
async ([client, id]) => { async ([client, id]) => {
@ -135,6 +151,15 @@ const TootBottomSheet: Component = (props) => {
setRemoteToot(result); setRemoteToot(result);
}; };
const switchContext = (status: mastodon.v1.Status) => {
setCache(params.acct, status);
navigate(`/${params.acct}/${status.id}`, {
state: {
tootBottomSheetPushedCount: pushedCount() + 1,
},
});
};
css` css`
.bottom-dock { .bottom-dock {
position: sticky; position: sticky;
@ -162,7 +187,7 @@ const TootBottomSheet: Component = (props) => {
sx={{ paddingTop: "var(--safe-area-inset-top, 0px)" }} sx={{ paddingTop: "var(--safe-area-inset-top, 0px)" }}
> >
<IconButton color="inherit" onClick={[navigate, -1]} disableRipple> <IconButton color="inherit" onClick={[navigate, -1]} disableRipple>
<CloseIcon /> {pushedCount() > 0 ? <BackIcon /> : <CloseIcon />}
</IconButton> </IconButton>
<Title <Title
class="name" class="name"
@ -181,6 +206,7 @@ const TootBottomSheet: Component = (props) => {
class={cards.card} class={cards.card}
status={item} status={item}
actionable={false} actionable={false}
onClick={[switchContext, item]}
></RegularToot> ></RegularToot>
)} )}
</For> </For>
@ -222,6 +248,7 @@ const TootBottomSheet: Component = (props) => {
class={cards.card} class={cards.card}
status={item} status={item}
actionable={false} actionable={false}
onClick={[switchContext, item]}
></RegularToot> ></RegularToot>
)} )}
</For> </For>