From eb2d3d5d40d546751ea41edd0ed5b13caf674f83 Mon Sep 17 00:00:00 2001 From: tzhangchi Date: Fri, 6 Jan 2023 01:04:52 +0800 Subject: [PATCH] feat: add letter avatar --- .../src/components/create-workspace/index.tsx | 4 +- .../src/components/workspace-modal/index.tsx | 63 +++++++++++-------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/packages/app/src/components/create-workspace/index.tsx b/packages/app/src/components/create-workspace/index.tsx index 2faeb60e97..3814d2449e 100644 --- a/packages/app/src/components/create-workspace/index.tsx +++ b/packages/app/src/components/create-workspace/index.tsx @@ -9,7 +9,7 @@ interface ICloseParams { } interface ModalProps { open: boolean; - onClose: (opts?: ICloseParams) => void; + onClose: (opts: ICloseParams) => void; } export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => { @@ -28,7 +28,7 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => { top={6} right={6} onClick={() => { - onClose(); + onClose({}); }} /> diff --git a/packages/app/src/components/workspace-modal/index.tsx b/packages/app/src/components/workspace-modal/index.tsx index c1d4402f92..affc9492ec 100644 --- a/packages/app/src/components/workspace-modal/index.tsx +++ b/packages/app/src/components/workspace-modal/index.tsx @@ -45,6 +45,26 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => { const data = getUserInfo(); 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 (
@@ -74,45 +94,37 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => { key={index} > - - - - + {(item.name || 'AFFiNE').substring(0, 1)} +
{item.name || 'untitled'} @@ -121,7 +133,7 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => { {(item.workspaceType === 'local' || @@ -255,7 +267,6 @@ const WorkspaceItem = styled('div')({ cursor: 'pointer', padding: '8px', border: '1px solid #eee', - fontWeight: 'bold', ':hover': { background: '#eee', },