style: remove some verbose codes (#2741)

(cherry picked from commit 34141958eb)
This commit is contained in:
LongYinan
2023-06-09 14:55:41 +08:00
committed by himself65
parent 9a22b81069
commit bb1a48a2b5
5 changed files with 45 additions and 79 deletions

View File

@@ -27,7 +27,6 @@ async function dispatch<
>( >(
namespace: T, namespace: T,
functionName: F, functionName: F,
// @ts-expect-error
...args: Parameters<WithoutFirstParameter<MainIPCHandlerMap[T][F]>> ...args: Parameters<WithoutFirstParameter<MainIPCHandlerMap[T][F]>>
): // @ts-expect-error ): // @ts-expect-error
ReturnType<MainIPCHandlerMap[T][F]> { ReturnType<MainIPCHandlerMap[T][F]> {

View File

@@ -76,9 +76,7 @@ const NameWorkspaceContent = ({
placeholder={t['Set a Workspace name']()} placeholder={t['Set a Workspace name']()}
maxLength={64} maxLength={64}
minLength={0} minLength={0}
onChange={value => { onChange={setWorkspaceName}
setWorkspaceName(value);
}}
onCompositionStart={() => { onCompositionStart={() => {
isComposition.current = true; isComposition.current = true;
}} }}
@@ -90,9 +88,7 @@ const NameWorkspaceContent = ({
<Button <Button
data-testid="create-workspace-close-button" data-testid="create-workspace-close-button"
type="light" type="light"
onClick={() => { onClick={onClose}
onClose();
}}
> >
{t.Cancel()} {t.Cancel()}
</Button> </Button>
@@ -103,9 +99,7 @@ const NameWorkspaceContent = ({
opacity: !workspaceName ? 0.5 : 1, opacity: !workspaceName ? 0.5 : 1,
}} }}
type="primary" type="primary"
onClick={() => { onClick={handleCreateWorkspace}
handleCreateWorkspace();
}}
> >
{t.Create()} {t.Create()}
</Button> </Button>
@@ -137,20 +131,24 @@ const SetDBLocationContent = ({
const defaultDBLocation = useDefaultDBLocation(); const defaultDBLocation = useDefaultDBLocation();
const [opening, setOpening] = useState(false); const [opening, setOpening] = useState(false);
const handleSelectDBFileLocation = async () => { const handleSelectDBFileLocation = useCallback(() => {
if (opening) { if (opening) {
return; return;
} }
setOpening(true); setOpening(true);
const result = await window.apis?.dialog.selectDBFileLocation(); (async function () {
setOpening(false); const result = await window.apis?.dialog.selectDBFileLocation();
if (result?.filePath) { setOpening(false);
onConfirmLocation(result.filePath); if (result?.filePath) {
} else if (result?.error) { onConfirmLocation(result.filePath);
// @ts-expect-error: result.error is dynamic so the type is unknown } else if (result?.error) {
toast(t[result.error]()); // @ts-expect-error: result.error is dynamic so the type is unknown
} toast(t[result.error]());
}; }
})().catch(err => {
logger.error(err);
});
}, [onConfirmLocation, opening, t]);
return ( return (
<div className={style.content}> <div className={style.content}>
@@ -334,22 +332,32 @@ export const CreateWorkspaceModal = ({
] ]
); );
const onConfirmName = useCallback(
(name: string) => {
setWorkspaceName(name);
if (environment.isDesktop) {
setStep('set-syncing-mode');
} else {
// this will be the last step for web for now
// fix me later
createLocalWorkspace(name)
.then(id => {
onCreate(id);
})
.catch(err => {
logger.error(err);
});
}
},
[createLocalWorkspace, onCreate]
);
const nameWorkspaceNode = const nameWorkspaceNode =
step === 'name-workspace' ? ( step === 'name-workspace' ? (
<NameWorkspaceContent <NameWorkspaceContent
// go to previous step instead? // go to previous step instead?
onClose={onClose} onClose={onClose}
onConfirmName={async name => { onConfirmName={onConfirmName}
setWorkspaceName(name);
if (environment.isDesktop) {
setStep('set-syncing-mode');
} else {
// this will be the last step for web for now
// fix me later
const id = await createLocalWorkspace(name);
onCreate(id);
}
}}
/> />
) : null; ) : null;

View File

@@ -24,11 +24,7 @@ export const EnableAffineCloudModal: React.FC<EnableAffineCloudModalProps> = ({
<Modal open={open} onClose={onClose} data-testid="logout-modal"> <Modal open={open} onClose={onClose} data-testid="logout-modal">
<ModalWrapper width={560} height={292}> <ModalWrapper width={560} height={292}>
<Header> <Header>
<IconButton <IconButton onClick={onClose}>
onClick={() => {
onClose();
}}
>
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
</Header> </Header>
@@ -41,18 +37,11 @@ export const EnableAffineCloudModal: React.FC<EnableAffineCloudModalProps> = ({
data-testid="confirm-enable-affine-cloud-button" data-testid="confirm-enable-affine-cloud-button"
shape="round" shape="round"
type="primary" type="primary"
onClick={() => { onClick={onConfirm}
onConfirm();
}}
> >
{user ? t.Enable() : t['Sign in and Enable']()} {user ? t.Enable() : t['Sign in and Enable']()}
</StyleButton> </StyleButton>
<StyleButton <StyleButton shape="round" onClick={onClose}>
shape="round"
onClick={() => {
onClose();
}}
>
{t['Not now']()} {t['Not now']()}
</StyleButton> </StyleButton>
</div> </div>

View File

@@ -31,11 +31,7 @@ export const TmpDisableAffineCloudModal: React.FC<
> >
<ModalWrapper width={480}> <ModalWrapper width={480}>
<Header> <Header>
<IconButton <IconButton onClick={onClose}>
onClick={() => {
onClose();
}}
>
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
</Header> </Header>
@@ -69,13 +65,7 @@ export const TmpDisableAffineCloudModal: React.FC<
/> />
</StyleImage> </StyleImage>
<StyleButtonContainer> <StyleButtonContainer>
<StyleButton <StyleButton shape="round" type="primary" onClick={onClose}>
shape="round"
type="primary"
onClick={() => {
onClose();
}}
>
{t['Got it']()} {t['Got it']()}
</StyleButton> </StyleButton>
</StyleButtonContainer> </StyleButtonContainer>

View File

@@ -26,11 +26,7 @@ export const TransformWorkspaceToAffineModal: React.FC<
> >
<ModalWrapper width={560} height={292}> <ModalWrapper width={560} height={292}>
<Header> <Header>
<IconButton <IconButton onClick={onClose}>
onClick={() => {
onClose();
}}
>
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
</Header> </Header>
@@ -43,23 +39,7 @@ export const TransformWorkspaceToAffineModal: React.FC<
data-testid="confirm-enable-cloud-button" data-testid="confirm-enable-cloud-button"
shape="round" shape="round"
type="primary" type="primary"
onClick={async () => { onClick={onConform}
onConform();
// setLoading(true);
// if (user || (await login())) {
// if (currentWorkspace) {
// const workspace = await dataCenter.enableWorkspaceCloud(
// currentWorkspace
// );
// toast(t('Enabled success'));
//
// if (workspace) {
// router.push(`/workspace/${workspace.id}/setting`);
// }
// }
// }
// setLoading(false);
}}
> >
{user ? t['Enable']() : t['Sign in and Enable']()} {user ? t['Enable']() : t['Sign in and Enable']()}
</StyleButton> </StyleButton>