Skip to content

Commit

Permalink
♻️ Implement hook instead
Browse files Browse the repository at this point in the history
  • Loading branch information
AmandaElvkull committed Feb 2, 2024
1 parent 16f3739 commit 4c25ac8
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions src/components/Navigation/TopBar/Resources/TransferToAppDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useEffect, useState } from 'react';
import React, { FC } from 'react';

import {
Button,
Expand All @@ -10,6 +10,7 @@ import {
import { close } from '@equinor/eds-icons';

import AnimatedCheckmark from 'src/components/Feedback/AnimatedCheckmark';
import { useFakeProgress } from 'src/hooks';
import { spacings } from 'src/style';
import string from 'src/utils/string';

Expand Down Expand Up @@ -64,41 +65,12 @@ interface PortalTransitProps {

const TransferToAppDialog: FC<PortalTransitProps> = ({
onClose,

applicationName,
url,
}) => {
const [finished, setFinished] = useState(false);
const [progress, setProgress] = useState(0);

const handleOnChangeApplication = useCallback((url: string) => {
window.open(url, '_self');
}, []);

useEffect(() => {
const timer = setInterval(() => {
setProgress((oldProgress) => {
if (oldProgress === 100) {
setFinished(true);
return 100;
}
const diff = Math.random() * 15;
return Math.min(oldProgress + diff, 100);
});
}, 250);

return () => {
clearInterval(timer);
};
}, []);

useEffect(() => {
if (finished) {
setTimeout(() => {
handleOnChangeApplication(url);
}, 4000);
}
}, [finished, handleOnChangeApplication, url]);
const { finished, progress } = useFakeProgress({
onDone: () => window.open(url, '_self'),
});

return (
<>
Expand Down

0 comments on commit 4c25ac8

Please sign in to comment.