Skip to content

Commit

Permalink
Merge pull request #603 from ianmcorvidae/il-autoredirect
Browse files Browse the repository at this point in the history
When autolaunching an instant launch, redirect to the analysis landing page
  • Loading branch information
ianmcorvidae authored Oct 15, 2024
2 parents e883236 + ed3d405 commit 70aa6e0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/instantlaunches/InstantLaunchButtonWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import React, { useEffect, useCallback } from "react";

import { useMutation } from "react-query";

import { useRouter } from "next/router";

import NavigationConstants from "common/NavigationConstants";

import { useDefaultOutputDir } from "components/data/utils";
import withErrorAnnouncer from "components/error/withErrorAnnouncer";
import { getHost } from "components/utils/getHost";
Expand Down Expand Up @@ -51,21 +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 Down

0 comments on commit 70aa6e0

Please sign in to comment.