TootBottomSheet: added cache
This commit is contained in:
parent
c0c5c8ee3b
commit
729eaa7901
2 changed files with 20 additions and 3 deletions
|
@ -43,6 +43,7 @@ import PullDownToRefresh from "./PullDownToRefresh";
|
||||||
import { HeroSourceProvider, type HeroSource } from "../platform/anim";
|
import { HeroSourceProvider, type HeroSource } from "../platform/anim";
|
||||||
import { useNavigate } from "@solidjs/router";
|
import { useNavigate } from "@solidjs/router";
|
||||||
import { useSignedInProfiles } from "../masto/acct";
|
import { useSignedInProfiles } from "../masto/acct";
|
||||||
|
import { setCache as setTootBottomSheetCache } from "./TootBottomSheet";
|
||||||
|
|
||||||
const TimelinePanel: Component<{
|
const TimelinePanel: Component<{
|
||||||
client: mastodon.rest.Client;
|
client: mastodon.rest.Client;
|
||||||
|
@ -288,6 +289,7 @@ const Home: ParentComponent = (props) => {
|
||||||
const rect = srcElement?.getBoundingClientRect();
|
const rect = srcElement?.getBoundingClientRect();
|
||||||
setHeroSrc((x) => Object.assign({}, x, { [BOTTOM_SHEET_HERO]: rect }));
|
setHeroSrc((x) => Object.assign({}, x, { [BOTTOM_SHEET_HERO]: rect }));
|
||||||
const acct = `${inf.username}@${p.account.site}`;
|
const acct = `${inf.username}@${p.account.site}`;
|
||||||
|
setTootBottomSheetCache(acct, toot);
|
||||||
navigate(`/${encodeURIComponent(acct)}/${toot.id}`);
|
navigate(`/${encodeURIComponent(acct)}/${toot.id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useNavigate, useParams } from "@solidjs/router";
|
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 Scaffold from "../material/Scaffold";
|
||||||
import TootThread from "./TootThread";
|
import TootThread from "./TootThread";
|
||||||
import { AppBar, IconButton, Toolbar } from "@suid/material";
|
import { AppBar, IconButton, Toolbar } from "@suid/material";
|
||||||
|
@ -9,13 +9,28 @@ 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";
|
||||||
import RegularToot from "./RegularToot";
|
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 TootBottomSheet: Component = (props) => {
|
||||||
const params = useParams<{ acct: string; id: string }>();
|
const params = useParams<{ acct: string; id: string }>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const allSession = useSessions();
|
const allSession = useSessions();
|
||||||
|
const acctText = () => decodeURIComponent(params.acct)
|
||||||
const session = () => {
|
const session = () => {
|
||||||
const [inputUsername, inputSite] = decodeURIComponent(params.acct).split(
|
const [inputUsername, inputSite] = acctText().split(
|
||||||
"@",
|
"@",
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
|
@ -34,7 +49,7 @@ const TootBottomSheet: Component = (props) => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const toot = remoteToot;
|
const toot = () => remoteToot() ?? getCache(acctText(), params.id);
|
||||||
|
|
||||||
const tootTitle = () => {
|
const tootTitle = () => {
|
||||||
const t = toot();
|
const t = toot();
|
||||||
|
|
Loading…
Reference in a new issue