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 { 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) => {
 | 
			
		|||
            <Divider />
 | 
			
		||||
          </ul>
 | 
			
		||||
          <For each={profiles()}>
 | 
			
		||||
            {({ account: acct, inf }) => (
 | 
			
		||||
              <ul data-site={acct.site} data-username={inf?.username}>
 | 
			
		||||
                <ListSubheader>{`@${inf?.username ?? "..."}@${new URL(acct.site).host}`}</ListSubheader>
 | 
			
		||||
            {({ account: acct }) => (
 | 
			
		||||
              <ul data-site={acct.site} data-username={acct.inf?.username}>
 | 
			
		||||
                <ListSubheader>{`@${acct.inf?.username ?? "..."}@${new URL(acct.site).host}`}</ListSubheader>
 | 
			
		||||
                <ListItemButton disabled>
 | 
			
		||||
                  <ListItemText>{t("Notifications")}</ListItemText>
 | 
			
		||||
                  <ListItemSecondaryAction>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 = () => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue