mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 09:21:24 +08:00
feat: global avatar
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
|||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
import { useConfirm } from '@/providers/confirm-provider';
|
import { useConfirm } from '@/providers/confirm-provider';
|
||||||
import { toast } from '@/ui/toast';
|
import { toast } from '@/ui/toast';
|
||||||
|
import { stringToColour } from '@/utils';
|
||||||
interface LoginModalProps {
|
interface LoginModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -45,26 +46,7 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
|
|||||||
const data = getUserInfo();
|
const data = getUserInfo();
|
||||||
setUser(data);
|
setUser(data);
|
||||||
};
|
};
|
||||||
const stringToColour = function (str: string) {
|
|
||||||
str = str || 'affine';
|
|
||||||
let colour = '#';
|
|
||||||
let hash = 0;
|
|
||||||
// str to hash
|
|
||||||
for (
|
|
||||||
let i = 0;
|
|
||||||
i < str.length;
|
|
||||||
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
|
|
||||||
);
|
|
||||||
|
|
||||||
// int/hash to hex
|
|
||||||
for (
|
|
||||||
let i = 0;
|
|
||||||
i < 3;
|
|
||||||
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
|
|
||||||
);
|
|
||||||
|
|
||||||
return colour;
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Modal open={open} onClose={onClose}>
|
<Modal open={open} onClose={onClose}>
|
||||||
|
|||||||
+19
-3
@@ -1,9 +1,9 @@
|
|||||||
import { Avatar, WorkspaceName, SelectorWrapper } from './styles';
|
import { Avatar, WorkspaceName, SelectorWrapper } from './styles';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { AffineIcon } from '../icons/icons';
|
// import { AffineIcon } from '../icons/icons';
|
||||||
import { WorkspaceModal } from '@/components/workspace-modal';
|
import { WorkspaceModal } from '@/components/workspace-modal';
|
||||||
import { getActiveWorkspace, getWorkspaces } from '@/hooks/mock-data/mock';
|
import { getActiveWorkspace, getWorkspaces } from '@/hooks/mock-data/mock';
|
||||||
|
import { stringToColour } from '@/utils';
|
||||||
export const WorkspaceSelector = () => {
|
export const WorkspaceSelector = () => {
|
||||||
const [workspaceListShow, setWorkspaceListShow] = useState(false);
|
const [workspaceListShow, setWorkspaceListShow] = useState(false);
|
||||||
const [workspace, setWorkSpace] = useState(getActiveWorkspace());
|
const [workspace, setWorkSpace] = useState(getActiveWorkspace());
|
||||||
@@ -34,7 +34,23 @@ export const WorkspaceSelector = () => {
|
|||||||
data-testid="workspace-avatar"
|
data-testid="workspace-avatar"
|
||||||
src={workspace.avatar}
|
src={workspace.avatar}
|
||||||
>
|
>
|
||||||
<AffineIcon />
|
<div
|
||||||
|
style={{
|
||||||
|
float: 'left',
|
||||||
|
width: '28px',
|
||||||
|
height: '28px',
|
||||||
|
border: '1px solid #fff',
|
||||||
|
color: '#fff',
|
||||||
|
fontSize: '14px',
|
||||||
|
padding: '5px 0 0 5px;',
|
||||||
|
background: stringToColour(workspace?.name ?? 'AFFiNE'),
|
||||||
|
borderRadius: '50%',
|
||||||
|
textAlign: 'center',
|
||||||
|
lineHeight: '28px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(workspace?.name ?? 'AFFiNE').substring(0, 1)}
|
||||||
|
</div>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<WorkspaceName data-testid="workspace-name">
|
<WorkspaceName data-testid="workspace-name">
|
||||||
{workspace?.name ?? 'AFFiNE'}
|
{workspace?.name ?? 'AFFiNE'}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
export function stringToColour(str: string) {
|
||||||
|
str = str || 'affine';
|
||||||
|
let colour = '#';
|
||||||
|
let hash = 0;
|
||||||
|
// str to hash
|
||||||
|
for (
|
||||||
|
let i = 0;
|
||||||
|
i < str.length;
|
||||||
|
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
|
||||||
|
);
|
||||||
|
|
||||||
|
// int/hash to hex
|
||||||
|
for (
|
||||||
|
let i = 0;
|
||||||
|
i < 3;
|
||||||
|
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
|
||||||
|
);
|
||||||
|
|
||||||
|
return colour;
|
||||||
|
}
|
||||||
@@ -3,3 +3,5 @@ export { isDev } from './env';
|
|||||||
export * from './useragent';
|
export * from './useragent';
|
||||||
|
|
||||||
export * from './tools';
|
export * from './tools';
|
||||||
|
|
||||||
|
export * from './colors';
|
||||||
|
|||||||
Reference in New Issue
Block a user