TODO: 推翻整个项目重新建立根基
This commit is contained in:
31
client/ui/AvatarMySelf.tsx
Normal file
31
client/ui/AvatarMySelf.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { UserMySelf } from "lingchair-client-protocol"
|
||||
import useAsyncEffect from "../utils/useAsyncEffect.ts"
|
||||
import Avatar from "./Avatar.tsx"
|
||||
import getClient from "../getClient.ts"
|
||||
|
||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||
avatarRef?: React.LegacyRef<HTMLElement>
|
||||
}
|
||||
export default function AvatarMySelf({
|
||||
avatarRef,
|
||||
...props
|
||||
}: Args) {
|
||||
if (!avatarRef) avatarRef = React.useRef<HTMLElement>(null)
|
||||
const [args, setArgs] = React.useState<{
|
||||
text: string,
|
||||
src: string,
|
||||
}>({
|
||||
text: '',
|
||||
src: '',
|
||||
})
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
const mySelf = await UserMySelf.getMySelfOrThrow(getClient())
|
||||
setArgs({
|
||||
text: mySelf.getNickName(),
|
||||
src: getClient().getUrlForFileByHash(mySelf.getAvatarFileHash(), '')!
|
||||
})
|
||||
})
|
||||
|
||||
return <Avatar avatarRef={avatarRef} {...props} {...args}></Avatar>
|
||||
}
|
||||
Reference in New Issue
Block a user