Skip to content

Commit

Permalink
fix: bug (labring#5390)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhiter authored Feb 21, 2025
1 parent 09262b5 commit 9338d7a
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import {
ModalCloseButton,
Progress
} from '@chakra-ui/react';
import { useCallback, useRef, useState } from 'react';
import { debounce } from 'lodash';
import { useTranslations } from 'next-intl';
import { useCallback, useEffect, useRef, useState, useMemo } from 'react';

import MyIcon from '../Icon';
import SshConnectModal from './SshConnectModal';
Expand Down Expand Up @@ -67,6 +68,8 @@ const JetBrainsGuideModal = ({
);

const handleConnectIDE = useCallback(async () => {
setOnConnecting(true);

const res = await fetch(
`https://data.services.jetbrains.com/products/releases?code=${selectedIDE.productCode}&type=release&latest=true&build=`,
{
Expand Down Expand Up @@ -110,9 +113,6 @@ const JetBrainsGuideModal = ({
if (progress) {
setProgress(progress);
}
if (progress && progress === 1) {
setOnConnecting(true);
}
},
signal: controller.signal
});
Expand All @@ -131,6 +131,17 @@ const JetBrainsGuideModal = ({
}
}, [selectedIDE, jetbrainsGuideData.devboxName, connectIDE, jetbrainsGuideData.workingDir]);

const debouncedHandleConnectIDE = useMemo(
() => debounce(handleConnectIDE, 3000),
[handleConnectIDE]
);

useEffect(() => {
return () => {
debouncedHandleConnectIDE.cancel();
};
}, [debouncedHandleConnectIDE]);

return (
<Box>
<Modal
Expand Down Expand Up @@ -318,7 +329,7 @@ const JetBrainsGuideModal = ({
borderColor: 'brightBlue.500'
}
}
onClick={handleConnectIDE}
onClick={debouncedHandleConnectIDE}
h={'36px'}
>
{onConnecting ? (
Expand Down

0 comments on commit 9338d7a

Please sign in to comment.