Skip to content

Commit

Permalink
Set a landingUrl state value and move the autolaunch navigation into …
Browse files Browse the repository at this point in the history
…the useEffect after opening the VICE analysis URL
  • Loading branch information
ianmcorvidae committed Oct 14, 2024
1 parent 656e2f2 commit ed3d405
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/instantlaunches/InstantLaunchButtonWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,30 @@ function InstantLaunchButtonWrapper(props) {
React.useState(false);
const [runErrorDetails, setRunErrorDetails] = React.useState(null);
const [ilUrl, setIlUrl] = React.useState();
const [landingUrl, setLandingUrl] = React.useState();

const router = useRouter();
const { t } = useTranslation("launch");

React.useEffect(() => {
if (ilUrl) {
if (ilUrl && landingUrl) {
window.open(`${getHost()}${ilUrl}`);
setIlUrl(null);
setOpen(false);
if (autolaunch) {
// go to the analysis landing, not keeping this page in browser history
router.replace(landingUrl);
}
}
}, [ilUrl]);
}, [ilUrl, landingUrl, autolaunch, router]);

const { mutate: launch } = useMutation(instantlyLaunch, {
onSuccess: (listing) => {
if (listing.analyses.length > 0) {
const analysis = listing.analyses[0];
setLandingUrl(
`/${NavigationConstants.ANALYSES}/${analysis?.id}`
);
if (analysis.interactive_urls?.length > 0) {
setIlUrl(
`${constants.VICE_LOADING_PAGE}/${encodeURIComponent(
Expand All @@ -80,12 +88,6 @@ function InstantLaunchButtonWrapper(props) {
} else {
setOpen(false);
}
if (autolaunch) {
// go to the analysis landing, not keeping this page in browser history
router.replace(
`/${NavigationConstants.ANALYSES}/${analysis?.id}`
);
}
} else {
setOpen(false);
}
Expand Down

0 comments on commit ed3d405

Please sign in to comment.