diff --git a/src/timelines/Home.tsx b/src/timelines/Home.tsx index ad18c8d..5483771 100644 --- a/src/timelines/Home.tsx +++ b/src/timelines/Home.tsx @@ -43,6 +43,7 @@ import PullDownToRefresh from "./PullDownToRefresh"; import { HeroSourceProvider, type HeroSource } from "../platform/anim"; import { useNavigate } from "@solidjs/router"; import { useSignedInProfiles } from "../masto/acct"; +import { setCache as setTootBottomSheetCache } from "./TootBottomSheet"; const TimelinePanel: Component<{ client: mastodon.rest.Client; @@ -288,6 +289,7 @@ const Home: ParentComponent = (props) => { const rect = srcElement?.getBoundingClientRect(); setHeroSrc((x) => Object.assign({}, x, { [BOTTOM_SHEET_HERO]: rect })); const acct = `${inf.username}@${p.account.site}`; + setTootBottomSheetCache(acct, toot); navigate(`/${encodeURIComponent(acct)}/${toot.id}`); }; diff --git a/src/timelines/TootBottomSheet.tsx b/src/timelines/TootBottomSheet.tsx index e7abbf8..b51bf7c 100644 --- a/src/timelines/TootBottomSheet.tsx +++ b/src/timelines/TootBottomSheet.tsx @@ -1,5 +1,5 @@ import { useNavigate, useParams } from "@solidjs/router"; -import { createResource, Show, type Component } from "solid-js"; +import { createEffect, createResource, Show, type Component } from "solid-js"; import Scaffold from "../material/Scaffold"; import TootThread from "./TootThread"; import { AppBar, IconButton, Toolbar } from "@suid/material"; @@ -9,13 +9,28 @@ import { isiOS } from "../platform/host"; import { createUnauthorizedClient, useSessions } from "../masto/clients"; import { resolveCustomEmoji } from "../masto/toot"; import RegularToot from "./RegularToot"; +import type { mastodon } from "masto"; + +let cachedEntry: [string, mastodon.v1.Status] | undefined; + +export function setCache(acct: string, status: mastodon.v1.Status) { + cachedEntry = [acct, status] +} + +function getCache(acct: string, id: string) { + if (acct === cachedEntry?.[0] && id === cachedEntry?.[1].id) { + return cachedEntry[1] + } +} + const TootBottomSheet: Component = (props) => { const params = useParams<{ acct: string; id: string }>(); const navigate = useNavigate(); const allSession = useSessions(); + const acctText = () => decodeURIComponent(params.acct) const session = () => { - const [inputUsername, inputSite] = decodeURIComponent(params.acct).split( + const [inputUsername, inputSite] = acctText().split( "@", 2, ); @@ -34,7 +49,7 @@ const TootBottomSheet: Component = (props) => { }, ); - const toot = remoteToot; + const toot = () => remoteToot() ?? getCache(acctText(), params.id); const tootTitle = () => { const t = toot();