mirror of
https://github.com/balzack/databag.git
synced 2025-05-04 15:35:16 +00:00
rendering identity data
This commit is contained in:
parent
e2e94cbee0
commit
c8a7d51106
@ -9,9 +9,47 @@
|
|||||||
|
|
||||||
.identity {
|
.identity {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 48px;
|
height: 64px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: var(--mantine-color-surface-4);
|
background: var(--mantine-color-surface-4);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 8px;
|
||||||
|
padding-right: 8px;
|
||||||
|
|
||||||
|
.image {
|
||||||
|
width: 48px;
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 8px;
|
||||||
|
padding-right: 8px;
|
||||||
|
|
||||||
|
.nameSet {
|
||||||
|
font-size: 20px;
|
||||||
|
text-wrap: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nameUnset {
|
||||||
|
font-size: 20px;
|
||||||
|
text-wrap: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
font-style: italic;
|
||||||
|
color: var(--mantine-color-text-9);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu {
|
.menu {
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import classes from './Identity.module.css';
|
import classes from './Identity.module.css';
|
||||||
import { useIdentity } from './useIdentity.hook';
|
import { useIdentity } from './useIdentity.hook';
|
||||||
import { Menu, Switch } from '@mantine/core';
|
import { Text, Image, Menu, Switch } from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconLogout,
|
IconLogout,
|
||||||
|
IconChevronRight,
|
||||||
IconSettings,
|
IconSettings,
|
||||||
IconAddressBook
|
IconAddressBook
|
||||||
} from '@tabler/icons-react'
|
} from '@tabler/icons-react'
|
||||||
import { modals } from '@mantine/modals';
|
import { modals } from '@mantine/modals';
|
||||||
|
import avatar from '../images/avatar.png'
|
||||||
|
|
||||||
export function Identity({ settings, contacts }: { settings: () => void, contacts: () => void }) {
|
export function Identity({ settings, contacts }: { settings: () => void, contacts: () => void }) {
|
||||||
const { state, actions } = useIdentity();
|
const { state, actions } = useIdentity();
|
||||||
@ -26,7 +28,19 @@ export function Identity({ settings, contacts }: { settings: () => void, contact
|
|||||||
return (
|
return (
|
||||||
<Menu shadow="md" position="right">
|
<Menu shadow="md" position="right">
|
||||||
<Menu.Target>
|
<Menu.Target>
|
||||||
<div className={classes.identity}>IDENTITY</div>
|
<div className={classes.identity}>
|
||||||
|
<Image radius="sm" className={classes.image} src={state.profile.imageSet ? state.imageUrl : avatar} />
|
||||||
|
<div className={classes.text}>
|
||||||
|
{ !state.profile.name && (
|
||||||
|
<Text className={classes.nameUnset}>{state.strings.name}</Text>
|
||||||
|
)}
|
||||||
|
{ state.profile.name && (
|
||||||
|
<Text className={classes.nameSet}>{state.profile.name}</Text>
|
||||||
|
)}
|
||||||
|
<Text className={classes.handle}>{`${state.profile.handle}${state.profile.node ? '/' + state.profile.node : ''}`}</Text>
|
||||||
|
</div>
|
||||||
|
<IconChevronRight className={classes.icon} />
|
||||||
|
</div>
|
||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
|
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
|
@ -9,6 +9,9 @@ export function useIdentity() {
|
|||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
all: false,
|
all: false,
|
||||||
strings: display.state.strings,
|
strings: display.state.strings,
|
||||||
|
profile: {} as Profile,
|
||||||
|
profileSet: false,
|
||||||
|
imageUrl: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@ -16,6 +19,22 @@ export function useIdentity() {
|
|||||||
setState((s) => ({ ...s, ...value }))
|
setState((s) => ({ ...s, ...value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const identity = app.state.session?.getIdentity();
|
||||||
|
if (!identity) {
|
||||||
|
console.log('session not set in identity hook');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const setProfile = (profile: Profile) => {
|
||||||
|
updateState({ profile, profileSet: true, imageUrl: identity.getProfileImageUrl() })
|
||||||
|
}
|
||||||
|
identity.addProfileListener(setProfile)
|
||||||
|
return () => {
|
||||||
|
identity.removeProfileListener(setProfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
setAll: (all: boolean) => {
|
setAll: (all: boolean) => {
|
||||||
updateState({ all });
|
updateState({ all });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user