Skip to content

Commit

Permalink
fix(core): creating multiple workspaces with consecutive clicks (#6259)
Browse files Browse the repository at this point in the history
Closes #6213
  • Loading branch information
fundon committed Mar 23, 2024
1 parent 62a6075 commit 7e16168
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface ModalProps {
}

interface NameWorkspaceContentProps extends ConfirmModalProps {
loading: boolean;
onConfirmName: (
name: string,
workspaceFlavour: WorkspaceFlavour,
Expand All @@ -50,6 +51,7 @@ const shouldEnableCloud =
!runtimeConfig.allowLocalWorkspace && !environment.isDesktop;

const NameWorkspaceContent = ({
loading,
onConfirmName,
...props
}: NameWorkspaceContentProps) => {
Expand Down Expand Up @@ -108,7 +110,7 @@ const NameWorkspaceContent = ({
cancelText={t['com.affine.nameWorkspace.button.cancel']()}
confirmButtonOptions={{
type: 'primary',
disabled: !workspaceName,
disabled: !workspaceName || loading,
['data-testid' as string]: 'create-workspace-create-button',
children: t['com.affine.nameWorkspace.button.create'](),
}}
Expand Down Expand Up @@ -180,6 +182,7 @@ export const CreateWorkspaceModal = ({
const [step, setStep] = useState<CreateWorkspaceStep>();
const t = useAFFiNEI18N();
const workspaceManager = useService(WorkspaceManager);
const [loading, setLoading] = useState(false);

// todo: maybe refactor using xstate?
useLayoutEffect(() => {
Expand Down Expand Up @@ -224,6 +227,9 @@ export const CreateWorkspaceModal = ({

const onConfirmName = useAsyncCallback(
async (name: string, workspaceFlavour: WorkspaceFlavour) => {
if (loading) return;
setLoading(true);

// this will be the last step for web for now
// fix me later
if (runtimeConfig.enablePreloading) {
Expand All @@ -247,8 +253,10 @@ export const CreateWorkspaceModal = ({
);
onCreate(id);
}

setLoading(false);
},
[onCreate, workspaceManager]
[loading, onCreate, workspaceManager]
);

const onOpenChange = useCallback(
Expand All @@ -259,9 +267,11 @@ export const CreateWorkspaceModal = ({
},
[onClose]
);

if (step === 'name-workspace') {
return (
<NameWorkspaceContent
loading={loading}
open={mode !== false && !!step}
onOpenChange={onOpenChange}
onConfirmName={onConfirmName}
Expand Down

0 comments on commit 7e16168

Please sign in to comment.