From dde0c249f44effcb7da914c544308bda3f743576 Mon Sep 17 00:00:00 2001 From: thislight Date: Mon, 4 Nov 2024 17:09:20 +0800 Subject: [PATCH] useSignedInProfiles: removed - use useSessions() instead --- src/masto/acct.ts | 28 ---------------------------- src/settings/Settings.tsx | 11 +++++------ src/timelines/Home.tsx | 6 +++--- 3 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 src/masto/acct.ts diff --git a/src/masto/acct.ts b/src/masto/acct.ts deleted file mode 100644 index ff9d488..0000000 --- a/src/masto/acct.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Accessor, createResource } from "solid-js"; -import type { mastodon } from "masto"; -import { useSessions } from "./clients"; -import { updateAcctInf } from "../accounts/stores"; - -export function useSignedInProfiles() { - const sessions = useSessions(); - const [accessor, tools] = createResource(sessions, async (all) => { - return Promise.all( - all.map(async (x, i) => ({ ...x, inf: await updateAcctInf(i) })), - ); - }); - return [ - () => { - try { - const value = accessor(); - if (value) { - return value; - } - } catch (reason) { - console.error("useSignedInProfiles: update acct info failed", reason); - } - - return sessions().map((x) => ({ ...x, inf: x.account.inf })); - }, - tools, - ] as const; -} diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 0bb04d7..dd82f25 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -31,12 +31,10 @@ import { import { A, useNavigate } from "@solidjs/router"; import { Title } from "../material/typography.jsx"; import { css } from "solid-styled"; -import { useSignedInProfiles } from "../masto/acct.js"; import { signOut, type Account } from "../accounts/stores.js"; import { format } from "date-fns"; import { useStore } from "@nanostores/solid"; import { $settings } from "./stores.js"; -import { useRegisterSW } from "virtual:pwa-register/solid"; import { autoMatchLangTag, autoMatchRegion, @@ -46,6 +44,7 @@ import { import { type Template } from "@solid-primitives/i18n"; import BottomSheet from "../material/BottomSheet.jsx"; import { useServiceWorker } from "../platform/host.js"; +import { useSessions } from "../masto/clients.js"; type Strings = { ["lang.auto"]: Template<{ detected: string }>; @@ -64,7 +63,7 @@ const Settings: ParentComponent = (props) => { const { needRefresh, offlineReady } = useServiceWorker(); const dateFnLocale = useDateFnLocale(); - const [profiles] = useSignedInProfiles(); + const profiles = useSessions(); const doSignOut = (acct: Account) => { signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken); @@ -118,9 +117,9 @@ const Settings: ParentComponent = (props) => { - {({ account: acct, inf }) => ( -
    - {`@${inf?.username ?? "..."}@${new URL(acct.site).host}`} + {({ account: acct }) => ( +
      + {`@${acct.inf?.username ?? "..."}@${new URL(acct.site).host}`} {t("Notifications")} diff --git a/src/timelines/Home.tsx b/src/timelines/Home.tsx index f60eb35..99045bf 100644 --- a/src/timelines/Home.tsx +++ b/src/timelines/Home.tsx @@ -30,10 +30,10 @@ import { $settings } from "../settings/stores"; import { useStore } from "@nanostores/solid"; import { HeroSourceProvider, type HeroSource } from "../platform/anim"; import { useNavigate } from "@solidjs/router"; -import { useSignedInProfiles } from "../masto/acct"; import { setCache as setTootBottomSheetCache } from "./TootBottomSheet"; import TrendTimelinePanel from "./TrendTimelinePanel"; import TimelinePanel from "./TimelinePanel"; +import { useSessions } from "../masto/clients"; const Home: ParentComponent = (props) => { let panelList: HTMLDivElement; @@ -42,11 +42,11 @@ const Home: ParentComponent = (props) => { const settings$ = useStore($settings); - const [profiles] = useSignedInProfiles(); + const profiles = useSessions(); const profile = () => { const all = profiles(); if (all.length > 0) { - return all[0].inf; + return all[0].account.inf; } }; const client = () => {