Profile: first prototype

This commit is contained in:
thislight 2024-10-18 19:15:35 +08:00
parent 54db6d4fbe
commit 664c1568d0
7 changed files with 474 additions and 80 deletions

View file

@ -4,7 +4,6 @@ import {
createMemo,
createRenderEffect,
createResource,
Signal,
useContext,
} from "solid-js";
import { Account } from "../accounts/stores";
@ -78,6 +77,26 @@ function useSessionsRaw() {
return store;
}
const DefaultSessionContext = /* @__PURE__ */ createContext<Accessor<number>>(() => 0)
export const DefaultSessionProvider = DefaultSessionContext.Provider;
/**
* Return the default session (the first session).
*
* This function may return `undefined`, but it will try to redirect the user to the sign in.
*/
export function useDefaultSession() {
const sessions = useSessions()
const sessionIndex = useContext(DefaultSessionContext)
return () => {
if (sessions().length > 0) {
return sessions()[sessionIndex()]
}
}
}
/**
* Get a session for the specific acct string.
*
@ -98,7 +117,6 @@ export function useSessionForAcctStr(acct: Accessor<string>) {
const allSessions = useSessions()
return createMemo(() => {
const parts = acct().split("@", 2)
const [inputUsername, inputSite] = acct().split("@", 2);
const authedSession = allSessions().find(
(x) =>
@ -113,3 +131,5 @@ export function useSessionForAcctStr(acct: Accessor<string>) {
);
});
}