RegularToot: open profile
This commit is contained in:
parent
d4093aaf5c
commit
49e1731cdb
2 changed files with 48 additions and 11 deletions
|
@ -49,7 +49,8 @@ export type Session = {
|
|||
client: mastodon.rest.Client;
|
||||
};
|
||||
|
||||
const Context = /* @__PURE__ */ createContext<Accessor<readonly Readonly<Session>[]>>();
|
||||
const Context =
|
||||
/* @__PURE__ */ createContext<Accessor<readonly Readonly<Session>[]>>();
|
||||
|
||||
export const Provider = Context.Provider;
|
||||
|
||||
|
@ -77,7 +78,9 @@ function useSessionsRaw() {
|
|||
return store;
|
||||
}
|
||||
|
||||
const DefaultSessionContext = /* @__PURE__ */ createContext<Accessor<number>>(() => 0)
|
||||
const DefaultSessionContext = /* @__PURE__ */ createContext<Accessor<number>>(
|
||||
() => 0,
|
||||
);
|
||||
|
||||
export const DefaultSessionProvider = DefaultSessionContext.Provider;
|
||||
|
||||
|
@ -87,14 +90,14 @@ export const DefaultSessionProvider = DefaultSessionContext.Provider;
|
|||
* 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)
|
||||
const sessions = useSessions();
|
||||
const sessionIndex = useContext(DefaultSessionContext);
|
||||
|
||||
return () => {
|
||||
if (sessions().length > 0) {
|
||||
return sessions()[sessionIndex()]
|
||||
return sessions()[sessionIndex()];
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +117,7 @@ export function useDefaultSession() {
|
|||
* unauthorised client for the site. This client may not available for some operations.
|
||||
*/
|
||||
export function useSessionForAcctStr(acct: Accessor<string>) {
|
||||
const allSessions = useSessions()
|
||||
const allSessions = useSessions();
|
||||
|
||||
return createMemo(() => {
|
||||
const [inputUsername, inputSite] = acct().split("@", 2);
|
||||
|
@ -132,4 +135,6 @@ export function useSessionForAcctStr(acct: Accessor<string>) {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
export function makeAcctText(session: Session) {
|
||||
return `${session.account.inf?.username}@${session.account.site}`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue