import type { AffinePublicWorkspace, AffineWorkspace, LocalWorkspace, } from '@affine/workspace/type'; import type { Workspace } from '@blocksuite/store'; import * as RadixAvatar from '@radix-ui/react-avatar'; import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url'; import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name'; import clsx from 'clsx'; import type React from 'react'; import { avatarImageStyle, avatarStyle, avatarTextStyle } from './index.css'; 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; } export type WorkspaceAvatarProps = { size?: number; workspace: AffineWorkspace | LocalWorkspace | AffinePublicWorkspace | null; className?: string; }; export type BlockSuiteWorkspaceAvatar = Omit< WorkspaceAvatarProps, 'workspace' > & { workspace: Workspace; }; export const BlockSuiteWorkspaceAvatar: React.FC = ({ size, workspace, ...props }) => { const [avatar] = useBlockSuiteWorkspaceAvatarUrl(workspace); const [name] = useBlockSuiteWorkspaceName(workspace); return ( {name.substring(0, 1)} ); }; export const WorkspaceAvatar: React.FC = ({ size = 20, workspace, ...props }) => { if (workspace && 'blockSuiteWorkspace' in workspace) { return ( ); } return ( A ); };