useSignedInProfiles: removed
- use useSessions() instead
This commit is contained in:
parent
832a59031a
commit
dde0c249f4
3 changed files with 8 additions and 37 deletions
|
@ -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;
|
|
||||||
}
|
|
|
@ -31,12 +31,10 @@ import {
|
||||||
import { A, useNavigate } from "@solidjs/router";
|
import { A, useNavigate } from "@solidjs/router";
|
||||||
import { Title } from "../material/typography.jsx";
|
import { Title } from "../material/typography.jsx";
|
||||||
import { css } from "solid-styled";
|
import { css } from "solid-styled";
|
||||||
import { useSignedInProfiles } from "../masto/acct.js";
|
|
||||||
import { signOut, type Account } from "../accounts/stores.js";
|
import { signOut, type Account } from "../accounts/stores.js";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { useStore } from "@nanostores/solid";
|
import { useStore } from "@nanostores/solid";
|
||||||
import { $settings } from "./stores.js";
|
import { $settings } from "./stores.js";
|
||||||
import { useRegisterSW } from "virtual:pwa-register/solid";
|
|
||||||
import {
|
import {
|
||||||
autoMatchLangTag,
|
autoMatchLangTag,
|
||||||
autoMatchRegion,
|
autoMatchRegion,
|
||||||
|
@ -46,6 +44,7 @@ import {
|
||||||
import { type Template } from "@solid-primitives/i18n";
|
import { type Template } from "@solid-primitives/i18n";
|
||||||
import BottomSheet from "../material/BottomSheet.jsx";
|
import BottomSheet from "../material/BottomSheet.jsx";
|
||||||
import { useServiceWorker } from "../platform/host.js";
|
import { useServiceWorker } from "../platform/host.js";
|
||||||
|
import { useSessions } from "../masto/clients.js";
|
||||||
|
|
||||||
type Strings = {
|
type Strings = {
|
||||||
["lang.auto"]: Template<{ detected: string }>;
|
["lang.auto"]: Template<{ detected: string }>;
|
||||||
|
@ -64,7 +63,7 @@ const Settings: ParentComponent = (props) => {
|
||||||
const { needRefresh, offlineReady } = useServiceWorker();
|
const { needRefresh, offlineReady } = useServiceWorker();
|
||||||
const dateFnLocale = useDateFnLocale();
|
const dateFnLocale = useDateFnLocale();
|
||||||
|
|
||||||
const [profiles] = useSignedInProfiles();
|
const profiles = useSessions();
|
||||||
|
|
||||||
const doSignOut = (acct: Account) => {
|
const doSignOut = (acct: Account) => {
|
||||||
signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken);
|
signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken);
|
||||||
|
@ -118,9 +117,9 @@ const Settings: ParentComponent = (props) => {
|
||||||
<Divider />
|
<Divider />
|
||||||
</ul>
|
</ul>
|
||||||
<For each={profiles()}>
|
<For each={profiles()}>
|
||||||
{({ account: acct, inf }) => (
|
{({ account: acct }) => (
|
||||||
<ul data-site={acct.site} data-username={inf?.username}>
|
<ul data-site={acct.site} data-username={acct.inf?.username}>
|
||||||
<ListSubheader>{`@${inf?.username ?? "..."}@${new URL(acct.site).host}`}</ListSubheader>
|
<ListSubheader>{`@${acct.inf?.username ?? "..."}@${new URL(acct.site).host}`}</ListSubheader>
|
||||||
<ListItemButton disabled>
|
<ListItemButton disabled>
|
||||||
<ListItemText>{t("Notifications")}</ListItemText>
|
<ListItemText>{t("Notifications")}</ListItemText>
|
||||||
<ListItemSecondaryAction>
|
<ListItemSecondaryAction>
|
||||||
|
|
|
@ -30,10 +30,10 @@ import { $settings } from "../settings/stores";
|
||||||
import { useStore } from "@nanostores/solid";
|
import { useStore } from "@nanostores/solid";
|
||||||
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 { setCache as setTootBottomSheetCache } from "./TootBottomSheet";
|
import { setCache as setTootBottomSheetCache } from "./TootBottomSheet";
|
||||||
import TrendTimelinePanel from "./TrendTimelinePanel";
|
import TrendTimelinePanel from "./TrendTimelinePanel";
|
||||||
import TimelinePanel from "./TimelinePanel";
|
import TimelinePanel from "./TimelinePanel";
|
||||||
|
import { useSessions } from "../masto/clients";
|
||||||
|
|
||||||
const Home: ParentComponent = (props) => {
|
const Home: ParentComponent = (props) => {
|
||||||
let panelList: HTMLDivElement;
|
let panelList: HTMLDivElement;
|
||||||
|
@ -42,11 +42,11 @@ const Home: ParentComponent = (props) => {
|
||||||
|
|
||||||
const settings$ = useStore($settings);
|
const settings$ = useStore($settings);
|
||||||
|
|
||||||
const [profiles] = useSignedInProfiles();
|
const profiles = useSessions();
|
||||||
const profile = () => {
|
const profile = () => {
|
||||||
const all = profiles();
|
const all = profiles();
|
||||||
if (all.length > 0) {
|
if (all.length > 0) {
|
||||||
return all[0].inf;
|
return all[0].account.inf;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const client = () => {
|
const client = () => {
|
||||||
|
|
Loading…
Reference in a new issue