Skip to content

Commit

Permalink
Dismiss persisted toast on prebuild detail page (gitpod-io#19515)
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh authored Mar 7, 2024
1 parent e50a0d8 commit fbe03d4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions components/dashboard/src/prebuilds/detail/PrebuildDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BreadcrumbNav } from "@podkit/breadcrumbs/BreadcrumbNav";
import { Text } from "@podkit/typography/Text";
import { Button } from "@podkit/buttons/Button";
import { FC, Suspense, useEffect, useMemo, useState } from "react";
import { Redirect, useParams } from "react-router";
import { Redirect, useHistory, useParams } from "react-router";
import { CircleSlash, Loader2Icon } from "lucide-react";
import dayjs from "dayjs";
import { usePrebuildLogsEmitter } from "../../data/prebuilds/prebuild-logs-emitter";
Expand Down Expand Up @@ -41,6 +41,8 @@ const formatDate = (date: dayjs.Dayjs): string => {
return date.format("MMM D, YYYY [at] h:mm A");
};

const PersistedToastID = "prebuild-logs-error";

interface Props {
prebuildId: string;
}
Expand All @@ -49,7 +51,8 @@ export const PrebuildDetailPage: FC = () => {

const { data: prebuild, isLoading: isInfoLoading, error, refetch } = usePrebuildQuery(prebuildId);

const { toast } = useToast();
const history = useHistory();
const { toast, dismissToast } = useToast();
const [currentPrebuild, setCurrentPrebuild] = useState<Prebuild | undefined>();
const [logNotFound, setLogNotFound] = useState(false);

Expand Down Expand Up @@ -77,6 +80,13 @@ export const PrebuildDetailPage: FC = () => {
};
}, [prebuildId]);

useEffect(() => {
history.listen(() => {
dismissToast(PersistedToastID);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
logEmitter.on("error", (err: Error) => {
if (err?.name === "AbortError") {
Expand All @@ -92,7 +102,7 @@ export const PrebuildDetailPage: FC = () => {
return;
}

toast("Fetching logs failed: " + err.message, { autoHide: false });
toast("Fetching logs failed: " + err.message, { autoHide: false, id: PersistedToastID });
});
}, [logEmitter, toast]);

Expand Down

0 comments on commit fbe03d4

Please sign in to comment.