Profile: add current default account into menu

This commit is contained in:
thislight 2024-11-04 15:57:53 +08:00
parent 02d883e53b
commit a0811ed6c4
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E

View file

@ -10,6 +10,7 @@ import {
onCleanup, onCleanup,
Show, Show,
type Component, type Component,
createMemo,
} from "solid-js"; } from "solid-js";
import Scaffold from "../material/Scaffold"; import Scaffold from "../material/Scaffold";
import { import {
@ -137,6 +138,17 @@ const Profile: Component = () => {
recentTootChunk.loading || recentTootChunk.loading ||
(recentTootFilter().pinned && pinnedTootChunk.loading); (recentTootFilter().pinned && pinnedTootChunk.loading);
const sessionDisplayName = createMemo(() =>
resolveCustomEmoji(
session().account?.inf?.displayName || "",
session().account?.inf?.emojis ?? [],
),
);
const useSessionDisplayName = (e: HTMLElement) => {
createRenderEffect(() => (e.innerHTML = sessionDisplayName()));
};
return ( return (
<Scaffold <Scaffold
topbar={ topbar={
@ -191,6 +203,17 @@ const Profile: Component = () => {
document.getElementById(menuButId)!.getBoundingClientRect() document.getElementById(menuButId)!.getBoundingClientRect()
} }
> >
<Show when={session().account}>
<MenuItem>
<ListItemAvatar>
<Avatar src={session().account?.inf?.avatar} />
</ListItemAvatar>
<ListItemText secondary={"Default account"}>
<span ref={useSessionDisplayName}></span>
</ListItemText>
{/* <ArrowRight /> // for future */}
</MenuItem>
</Show>
<Show when={session().account && profile()}> <Show when={session().account && profile()}>
<Show <Show
when={isCurrentSessionProfile()} when={isCurrentSessionProfile()}
@ -283,7 +306,7 @@ const Profile: Component = () => {
height: "100%", height: "100%",
}} }}
crossOrigin="anonymous" crossOrigin="anonymous"
onLoad={async (event) => { onLoad={(event) => {
const ins = new FastAverageColor(); const ins = new FastAverageColor();
const colors = ins.getColor(event.currentTarget); const colors = ins.getColor(event.currentTarget);
setBannerSampledColors({ setBannerSampledColors({
@ -301,16 +324,7 @@ const Profile: Component = () => {
<Avatar src={session().account?.inf?.avatar}></Avatar> <Avatar src={session().account?.inf?.avatar}></Avatar>
</ListItemAvatar> </ListItemAvatar>
<ListItemText> <ListItemText>
<span <span ref={useSessionDisplayName}></span>
ref={(e) =>
createRenderEffect(() => {
e.innerHTML = resolveCustomEmoji(
session().account?.inf?.displayName || "",
session().account?.inf?.emojis ?? [],
);
})
}
></span>
<span>'s Home</span> <span>'s Home</span>
</ListItemText> </ListItemText>
</MenuItem> </MenuItem>