mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
refactor: create public component for workspace avatar
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
import { stringToColour } from '@/utils';
|
||||||
|
|
||||||
|
interface IWorkspaceAvatar {
|
||||||
|
size: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const WorkspaceAvatar = (props: IWorkspaceAvatar) => {
|
||||||
|
const size = props.size || 20;
|
||||||
|
const sizeStr = size + 'px';
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: sizeStr,
|
||||||
|
height: sizeStr,
|
||||||
|
border: '1px solid #fff',
|
||||||
|
color: '#fff',
|
||||||
|
fontSize: Math.ceil(0.5 * size) + 'px',
|
||||||
|
background: stringToColour(props.name || 'AFFiNE'),
|
||||||
|
borderRadius: '50%',
|
||||||
|
textAlign: 'center',
|
||||||
|
lineHeight: sizeStr,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(props.name || 'AFFiNE').substring(0, 1)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -21,7 +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';
|
import { WorkspaceAvatar } from '@/components/workspace-avatar';
|
||||||
interface LoginModalProps {
|
interface LoginModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -82,18 +82,9 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
|
|||||||
marginTop: '6px',
|
marginTop: '6px',
|
||||||
marginLeft: '10px',
|
marginLeft: '10px',
|
||||||
marginRight: '10px',
|
marginRight: '10px',
|
||||||
width: '50px',
|
|
||||||
height: '50px',
|
|
||||||
border: '1px solid #fff',
|
|
||||||
color: '#fff',
|
|
||||||
fontSize: '22px',
|
|
||||||
background: stringToColour(item.name || 'AFFiNE'),
|
|
||||||
borderRadius: '50%',
|
|
||||||
textAlign: 'center',
|
|
||||||
lineHeight: '50px',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(item.name || 'AFFiNE').substring(0, 1)}
|
<WorkspaceAvatar size={50} name={item.name} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
User,
|
User,
|
||||||
Workspace,
|
Workspace,
|
||||||
} from '@/hooks/mock-data/mock';
|
} from '@/hooks/mock-data/mock';
|
||||||
import { stringToColour } from '@/utils';
|
import { WorkspaceAvatar } from '@/components/workspace-avatar';
|
||||||
export const GeneralPage = ({ workspace }: { workspace: Workspace }) => {
|
export const GeneralPage = ({ workspace }: { workspace: Workspace }) => {
|
||||||
const { currentWorkspace, refreshWorkspacesMeta } = useAppState();
|
const { currentWorkspace, refreshWorkspacesMeta } = useAppState();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -85,19 +85,11 @@ export const GeneralPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
float: 'left',
|
float: 'left',
|
||||||
width: '60px',
|
|
||||||
height: '60px',
|
|
||||||
border: '1px solid #fff',
|
|
||||||
color: '#fff',
|
|
||||||
fontSize: '26px',
|
|
||||||
background: stringToColour(workspace?.name ?? 'AFFiNE'),
|
|
||||||
borderRadius: '50%',
|
|
||||||
textAlign: 'center',
|
|
||||||
lineHeight: '60px',
|
|
||||||
marginRight: '5px',
|
marginRight: '5px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(workspace?.name ?? 'AFFiNE').substring(0, 1)}
|
<WorkspaceAvatar size={60} name={workspace.name} />
|
||||||
</div>
|
</div>
|
||||||
<Upload
|
<Upload
|
||||||
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"
|
accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ enum ActiveTab {
|
|||||||
'members' = 'members',
|
'members' = 'members',
|
||||||
'publish' = 'publish',
|
'publish' = 'publish',
|
||||||
'sync' = 'sync',
|
'sync' = 'sync',
|
||||||
|
'export' = 'export',
|
||||||
}
|
}
|
||||||
|
|
||||||
type SettingTabProps = {
|
type SettingTabProps = {
|
||||||
@@ -125,9 +126,9 @@ const WorkspaceSettingTab = ({ activeTab, onTabChange }: SettingTabProps) => {
|
|||||||
</WorkspaceSettingTagItem>
|
</WorkspaceSettingTagItem>
|
||||||
|
|
||||||
<WorkspaceSettingTagItem
|
<WorkspaceSettingTagItem
|
||||||
isActive={activeTab === ActiveTab.publish}
|
isActive={activeTab === ActiveTab.export}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onTabChange && onTabChange(ActiveTab.publish);
|
onTabChange && onTabChange(ActiveTab.export);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StyledSettingTagIconContainer>
|
<StyledSettingTagIconContainer>
|
||||||
|
|||||||
+2
-11
@@ -2,8 +2,8 @@ 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 { WorkspaceAvatar } from '@/components/workspace-avatar';
|
||||||
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());
|
||||||
@@ -37,18 +37,9 @@ export const WorkspaceSelector = () => {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
float: 'left',
|
float: 'left',
|
||||||
width: '28px',
|
|
||||||
height: '28px',
|
|
||||||
border: '1px solid #fff',
|
|
||||||
color: '#fff',
|
|
||||||
fontSize: '14px',
|
|
||||||
background: stringToColour(workspace?.name ?? 'AFFiNE'),
|
|
||||||
borderRadius: '50%',
|
|
||||||
textAlign: 'center',
|
|
||||||
lineHeight: '28px',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(workspace?.name ?? 'AFFiNE').substring(0, 1)}
|
<WorkspaceAvatar size={28} name={workspace.name} />
|
||||||
</div>
|
</div>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<WorkspaceName data-testid="workspace-name">
|
<WorkspaceName data-testid="workspace-name">
|
||||||
|
|||||||
Reference in New Issue
Block a user