fix: datacenter type error

This commit is contained in:
DiamondThree 2023-01-09 23:55:34 +08:00
parent c1261e7977
commit 833df7be3c
5 changed files with 321 additions and 316 deletions

View File

@ -34,6 +34,7 @@ export const MembersPage = ({ workspace }: { workspace: Workspace }) => {
const [members, setMembers] = useState<[{ name: string; email: string }]>([
{ name: 'affine', email: 'tttt' },
]);
console.log('setMembers: ', setMembers);
const { user, login, updateWorkspaceMeta } = useTemporaryHelper();
const { confirm } = useConfirm();
// const refreshMembers = useCallback(() => {
@ -51,7 +52,7 @@ export const MembersPage = ({ workspace }: { workspace: Workspace }) => {
// });
// }, [workspace.id]);
const setMembersList = () => {
setMembers([]);
// setMembers([]);
// const members = getMembers(workspace.id);
// members && setMembers(members);
};

View File

@ -1,180 +1,181 @@
import { InformationIcon, LogOutIcon } from '@blocksuite/icons';
import { styled } from '@/styles';
import { Divider } from '@/ui/divider';
import { useAppState } from '@/providers/app-state-provider';
import { SelectorPopperContainer } from './styles';
import {
PrivateWorkspaceItem,
WorkspaceItem,
CreateWorkspaceItem,
ListItem,
LoginItem,
} from './WorkspaceItem';
import { WorkspaceSetting } from '@/components/workspace-setting';
import { useCallback, useEffect, useState } from 'react';
import { WorkspaceType } from '@affine/datacenter';
import { useModal } from '@/providers/GlobalModalProvider';
// import { InformationIcon, LogOutIcon } from '@blocksuite/icons';
// import { styled } from '@/styles';
// import { Divider } from '@/ui/divider';
// import { useAppState } from '@/providers/app-state-provider';
// import { SelectorPopperContainer } from './styles';
// import {
// PrivateWorkspaceItem,
// WorkspaceItem,
// CreateWorkspaceItem,
// ListItem,
// LoginItem,
// } from './WorkspaceItem';
// import { WorkspaceSetting } from '@/components/workspace-setting';
// import { useCallback, useEffect, useState } from 'react';
// import { Workspace } from '@affine/datacenter';
// import { useModal } from '@/providers/GlobalModalProvider';
export type WorkspaceDetails = Record<
string,
{ memberCount: number; owner: { id: string; name: string } }
>;
// export type WorkspaceDetails = Record<
// string,
// { memberCount: number; owner: { id: string; name: string } }
// >;
type SelectorPopperContentProps = {
isShow: boolean;
};
// type SelectorPopperContentProps = {
// isShow: boolean;
// };
export const SelectorPopperContent = ({
isShow,
}: SelectorPopperContentProps) => {
const { user, workspacesMeta, refreshWorkspacesMeta } = useAppState();
const [settingWorkspaceId, setSettingWorkspaceId] = useState<string | null>(
null
);
const [workSpaceDetails, setWorkSpaceDetails] = useState<WorkspaceDetails>(
{}
);
const { triggerContactModal } = useModal();
// export const SelectorPopperContent = ({
// isShow,
// }: SelectorPopperContentProps) => {
// const { user, workspacesMeta, refreshWorkspacesMeta } = useAppState();
// const [settingWorkspaceId, setSettingWorkspaceId] = useState<string | null>(
// null
// );
// const [workSpaceDetails, setWorkSpaceDetails] = useState<WorkspaceDetails>(
// {}
// );
// const { triggerContactModal } = useModal();
const handleClickSettingWorkspace = (workspaceId: string) => {
setSettingWorkspaceId(workspaceId);
};
const handleCloseWorkSpace = () => {
setSettingWorkspaceId(null);
};
const settingWorkspace = settingWorkspaceId
? workspacesMeta.find(workspace => workspace.id === settingWorkspaceId)
: undefined;
// const handleClickSettingWorkspace = (workspaceId: string) => {
// setSettingWorkspaceId(workspaceId);
// };
// const handleCloseWorkSpace = () => {
// setSettingWorkspaceId(null);
// };
// const settingWorkspace = settingWorkspaceId
// ? workspacesMeta.find(workspace => workspace.id === settingWorkspaceId)
// : undefined;
const refreshDetails = useCallback(async () => {
const workspaceDetailList = await Promise.all(
workspacesMeta.map(async ({ id, type }) => {
if (user) {
if (type === WorkspaceType.Private) {
return { id, member_count: 1, owner: user };
} else {
// const dc = await getDataCenter();
// const data = await dc.apis.getWorkspaceDetail({ id });
// return { id, ...data } || { id, member_count: 0, owner: user };
}
}
})
);
const workSpaceDetails: WorkspaceDetails = {};
workspaceDetailList.forEach(details => {
if (details) {
const { id, member_count, owner } = details;
if (!owner) return;
workSpaceDetails[id] = {
memberCount: member_count || 1,
owner: {
id: owner.id,
name: owner.name,
},
};
}
});
setWorkSpaceDetails(workSpaceDetails);
}, [user, workspacesMeta]);
// const refreshDetails = useCallback(async () => {
// const workspaceDetailList = await Promise.all(
// workspacesMeta.map(async ({ id, type }) => {
// if (user) {
// if (type === WorkspaceType.Private) {
// return { id, member_count: 1, owner: user };
// } else {
// // const dc = await getDataCenter();
// // const data = await dc.apis.getWorkspaceDetail({ id });
// // return { id, ...data } || { id, member_count: 0, owner: user };
// }
// }
// })
// );
// const workSpaceDetails: WorkspaceDetails = {};
// workspaceDetailList.forEach(details => {
// if (details) {
// const { id, member_count, owner } = details;
// if (!owner) return;
// workSpaceDetails[id] = {
// memberCount: member_count || 1,
// owner: {
// id: owner.id,
// name: owner.name,
// },
// };
// }
// });
// setWorkSpaceDetails(workSpaceDetails);
// }, [user, workspacesMeta]);
useEffect(() => {
if (isShow) {
setSettingWorkspaceId(null);
refreshWorkspacesMeta();
refreshDetails();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isShow]);
// useEffect(() => {
// if (isShow) {
// setSettingWorkspaceId(null);
// refreshWorkspacesMeta();
// refreshDetails();
// }
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [isShow]);
return !user ? (
<SelectorPopperContainer placement="bottom-start">
<LoginItem />
<StyledDivider />
<ListItem
icon={<InformationIcon />}
name="About AFFiNE"
onClick={() => triggerContactModal()}
/>
</SelectorPopperContainer>
) : (
<SelectorPopperContainer placement="bottom-start">
<PrivateWorkspaceItem
privateWorkspaceId={
workspacesMeta.find(
workspace => workspace.type === WorkspaceType.Private
)?.id
}
/>
<StyledDivider />
<WorkspaceGroupTitle>Workspace</WorkspaceGroupTitle>
<WorkspaceWrapper>
{workspacesMeta.map(workspace => {
return workspace.type !== WorkspaceType.Private ? (
<WorkspaceItem
type={workspace.type}
key={workspace.id}
id={workspace.id}
icon={`loading...`}
onClickSetting={handleClickSettingWorkspace}
name={`loading...`}
memberCount={workSpaceDetails[workspace.id]?.memberCount || 1}
/>
) : null;
})}
</WorkspaceWrapper>
<CreateWorkspaceItem />
{settingWorkspace ? (
<WorkspaceSetting
isShow={false}
onClose={handleCloseWorkSpace}
// workspace={settingWorkspace}
// owner={
// (settingWorkspaceId &&
// workSpaceDetails[settingWorkspaceId]?.owner) || {
// id: user.id,
// name: user.name,
// }
// }
/>
) : null}
<StyledDivider />
<ListItem
icon={<InformationIcon />}
name="About AFFiNE"
onClick={() => triggerContactModal()}
/>
<ListItem
icon={<LogOutIcon />}
name="Sign out"
onClick={() => {
console.log('Sign out');
// FIXME: remove token from local storage and reload the page
localStorage.removeItem('affine_token');
window.location.reload();
}}
/>
</SelectorPopperContainer>
);
};
// return !user ? (
// <SelectorPopperContainer placement="bottom-start">
// <LoginItem />
// <StyledDivider />
// <ListItem
// icon={<InformationIcon />}
// name="About AFFiNE"
// onClick={() => triggerContactModal()}
// />
// </SelectorPopperContainer>
// ) : (
// <SelectorPopperContainer placement="bottom-start">
// <PrivateWorkspaceItem
// privateWorkspaceId={
// workspacesMeta.find(
// workspace => workspace.type === WorkspaceType.Private
// )?.id
// }
// />
// <StyledDivider />
// <WorkspaceGroupTitle>Workspace</WorkspaceGroupTitle>
// <WorkspaceWrapper>
// {workspacesMeta.map(workspace => {
// return workspace.type !== WorkspaceType.Private ? (
// <WorkspaceItem
// type={workspace.type}
// key={workspace.id}
// id={workspace.id}
// icon={`loading...`}
// onClickSetting={handleClickSettingWorkspace}
// name={`loading...`}
// memberCount={workSpaceDetails[workspace.id]?.memberCount || 1}
// />
// ) : null;
// })}
// </WorkspaceWrapper>
// <CreateWorkspaceItem />
// {settingWorkspace ? (
// <WorkspaceSetting
// isShow={false}
// onClose={handleCloseWorkSpace}
// // workspace={settingWorkspace}
// // owner={
// // (settingWorkspaceId &&
// // workSpaceDetails[settingWorkspaceId]?.owner) || {
// // id: user.id,
// // name: user.name,
// // }
// // }
// />
// ) : null}
// <StyledDivider />
// <ListItem
// icon={<InformationIcon />}
// name="About AFFiNE"
// onClick={() => triggerContactModal()}
// />
// <ListItem
// icon={<LogOutIcon />}
// name="Sign out"
// onClick={() => {
// console.log('Sign out');
// // FIXME: remove token from local storage and reload the page
// localStorage.removeItem('affine_token');
// window.location.reload();
// }}
// />
// </SelectorPopperContainer>
// );
// };
const StyledDivider = styled(Divider)({
margin: '8px 12px',
width: 'calc(100% - 24px)',
});
// const StyledDivider = styled(Divider)({
// margin: '8px 12px',
// width: 'calc(100% - 24px)',
// });
const WorkspaceGroupTitle = styled('div')(({ theme }) => {
return {
color: theme.colors.iconColor,
fontSize: theme.font.sm,
lineHeight: '30px',
height: '30px',
padding: '0 12px',
};
});
// const WorkspaceGroupTitle = styled('div')(({ theme }) => {
// return {
// color: theme.colors.iconColor,
// fontSize: theme.font.sm,
// lineHeight: '30px',
// height: '30px',
// padding: '0 12px',
// };
// });
const WorkspaceWrapper = styled('div')(() => {
return {
maxHeight: '200px',
overflow: 'auto',
};
});
// const WorkspaceWrapper = styled('div')(() => {
// return {
// maxHeight: '200px',
// overflow: 'auto',
// };
// });
export default {};

View File

@ -1,60 +1,61 @@
import { styled } from '@/styles';
import { useAppState } from '@/providers/app-state-provider';
import {
WorkspaceItemAvatar,
PrivateWorkspaceWrapper,
WorkspaceItemContent,
} from './styles';
import { useRouter } from 'next/router';
// import { styled } from '@/styles';
// import { useAppState } from '@/providers/app-state-provider';
// import {
// WorkspaceItemAvatar,
// PrivateWorkspaceWrapper,
// WorkspaceItemContent,
// } from './styles';
// import { useRouter } from 'next/router';
type PrivateWorkspaceItemProps = {
privateWorkspaceId?: string;
};
// type PrivateWorkspaceItemProps = {
// privateWorkspaceId?: string;
// };
export const PrivateWorkspaceItem = ({
privateWorkspaceId,
}: PrivateWorkspaceItemProps) => {
const { user } = useAppState();
const router = useRouter();
const handleClick = () => {
if (privateWorkspaceId) {
router.push(`/workspace/${privateWorkspaceId}`);
}
};
if (user) {
const Username = user.name;
return (
<PrivateWorkspaceWrapper onClick={handleClick}>
<WorkspaceItemAvatar alt={Username} src={user.avatar_url}>
{Username}
</WorkspaceItemAvatar>
<WorkspaceItemContent>
<Name title={Username}>{Username}</Name>
<Email title={user.email}>{user.email}</Email>
</WorkspaceItemContent>
</PrivateWorkspaceWrapper>
);
}
return null;
};
// export const PrivateWorkspaceItem = ({
// privateWorkspaceId,
// }: PrivateWorkspaceItemProps) => {
// const { user } = useAppState();
// const router = useRouter();
// const handleClick = () => {
// if (privateWorkspaceId) {
// router.push(`/workspace/${privateWorkspaceId}`);
// }
// };
// if (user) {
// const Username = user.name;
// return (
// <PrivateWorkspaceWrapper onClick={handleClick}>
// <WorkspaceItemAvatar alt={Username} src={user.avatar_url}>
// {Username}
// </WorkspaceItemAvatar>
// <WorkspaceItemContent>
// <Name title={Username}>{Username}</Name>
// <Email title={user.email}>{user.email}</Email>
// </WorkspaceItemContent>
// </PrivateWorkspaceWrapper>
// );
// }
// return null;
// };
const Name = styled('div')(({ theme }) => {
return {
color: theme.colors.quoteColor,
fontSize: theme.font.base,
fontWeight: 500,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
});
// const Name = styled('div')(({ theme }) => {
// return {
// color: theme.colors.quoteColor,
// fontSize: theme.font.base,
// fontWeight: 500,
// overflow: 'hidden',
// textOverflow: 'ellipsis',
// whiteSpace: 'nowrap',
// };
// });
const Email = styled('div')(({ theme }) => {
return {
color: theme.colors.iconColor,
fontSize: theme.font.sm,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
});
// const Email = styled('div')(({ theme }) => {
// return {
// color: theme.colors.iconColor,
// fontSize: theme.font.sm,
// overflow: 'hidden',
// textOverflow: 'ellipsis',
// whiteSpace: 'nowrap',
// };
// });
export default {};

View File

@ -1,96 +1,98 @@
import { useRouter } from 'next/router';
import { styled } from '@/styles';
import {
WorkspaceItemAvatar,
WorkspaceItemWrapper,
WorkspaceItemContent,
} from '../styles';
import { FooterSetting } from './FooterSetting';
import { FooterUsers } from './FooterUsers';
import { WorkspaceType } from '@affine/datacenter';
import { useAppState } from '@/providers/app-state-provider';
// import { useRouter } from 'next/router';
// import { styled } from '@/styles';
// import {
// WorkspaceItemAvatar,
// WorkspaceItemWrapper,
// WorkspaceItemContent,
// } from '../styles';
// import { FooterSetting } from './FooterSetting';
// import { FooterUsers } from './FooterUsers';
// import { WorkspaceType } from '@affine/datacenter';
// import { useAppState } from '@/providers/app-state-provider';
interface WorkspaceItemProps {
id: string;
name: string;
icon: string;
type: WorkspaceType;
memberCount: number;
onClickSetting?: (workspaceId: string) => void;
}
// interface WorkspaceItemProps {
// id: string;
// name: string;
// icon: string;
// type: WorkspaceType;
// memberCount: number;
// onClickSetting?: (workspaceId: string) => void;
// }
export const WorkspaceItem = ({
id,
name,
icon,
type,
onClickSetting,
memberCount,
}: WorkspaceItemProps) => {
const router = useRouter();
// export const WorkspaceItem = ({
// id,
// name,
// icon,
// type,
// onClickSetting,
// memberCount,
// }: WorkspaceItemProps) => {
// const router = useRouter();
const { currentWorkspaceId } = useAppState();
// const { currentWorkspaceId } = useAppState();
const handleClickSetting = async () => {
onClickSetting && onClickSetting(id);
};
// const handleClickSetting = async () => {
// onClickSetting && onClickSetting(id);
// };
return (
<StyledWrapper
onClick={() => {
router.push(`/workspace/${id}`);
}}
canSet={
type !== WorkspaceType.Private && currentWorkspaceId === String(id)
}
>
<WorkspaceItemAvatar alt={name} src={icon}>
{name.charAt(0)}
</WorkspaceItemAvatar>
<WorkspaceItemContent>
<Name title={name}>{name}</Name>
</WorkspaceItemContent>
<Footer>
<FooterUsers memberCount={memberCount} />
<FooterSetting onClick={handleClickSetting} />
</Footer>
</StyledWrapper>
);
};
// return (
// <StyledWrapper
// onClick={() => {
// router.push(`/workspace/${id}`);
// }}
// canSet={
// type !== WorkspaceType.Private && currentWorkspaceId === String(id)
// }
// >
// <WorkspaceItemAvatar alt={name} src={icon}>
// {name.charAt(0)}
// </WorkspaceItemAvatar>
// <WorkspaceItemContent>
// <Name title={name}>{name}</Name>
// </WorkspaceItemContent>
// <Footer>
// <FooterUsers memberCount={memberCount} />
// <FooterSetting onClick={handleClickSetting} />
// </Footer>
// </StyledWrapper>
// );
// };
const Name = styled('div')(({ theme }) => {
return {
color: theme.colors.quoteColor,
fontSize: theme.font.sm,
fontWeight: 400,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
});
// const Name = styled('div')(({ theme }) => {
// return {
// color: theme.colors.quoteColor,
// fontSize: theme.font.sm,
// fontWeight: 400,
// overflow: 'hidden',
// textOverflow: 'ellipsis',
// whiteSpace: 'nowrap',
// };
// });
const StyledWrapper = styled(WorkspaceItemWrapper)<{ canSet: boolean }>(
({ canSet }) => {
return {
'& .footer-setting': {
display: 'none',
},
':hover .footer-users': {
display: canSet ? 'none' : '',
},
':hover .footer-setting': {
display: canSet ? 'block' : 'none',
},
};
}
);
// const StyledWrapper = styled(WorkspaceItemWrapper)<{ canSet: boolean }>(
// ({ canSet }) => {
// return {
// '& .footer-setting': {
// display: 'none',
// },
// ':hover .footer-users': {
// display: canSet ? 'none' : '',
// },
// ':hover .footer-setting': {
// display: canSet ? 'block' : 'none',
// },
// };
// }
// );
const Footer = styled('div')({
width: '42px',
flex: '0 42px',
fontSize: '20px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginLeft: '12px',
});
// const Footer = styled('div')({
// width: '42px',
// flex: '0 42px',
// fontSize: '20px',
// display: 'flex',
// alignItems: 'center',
// justifyContent: 'center',
// marginLeft: '12px',
// });
export default {};

View File

@ -26,5 +26,5 @@ const _initializeDataCenter = () => {
export const getDataCenter = _initializeDataCenter();
export type { AccessTokenMessage } from './provider/affine/apis';
export type { WorkspaceInfo } from './types';
export type { WorkspaceInfo as Workspace, User } from './types';
export { getLogger } from './logger';