Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: make sure timeout is cleared on component unmount
  • Loading branch information
Parkreiner committed Jul 1, 2024
commit 901aa39c9a220d47618e20a713afd5dd90ca0497
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useTheme, type Interpolation, type Theme } from "@emotion/react";
import Skeleton from "@mui/material/Skeleton";
import { saveAs } from "file-saver";
import JSZip from "jszip";
import { useMemo, useState, type FC } from "react";
import { useMemo, useState, type FC, useRef, useEffect } from "react";
import { useQueries, useQuery } from "react-query";
import { agentLogs, buildLogs } from "api/queries/workspaces";
import type { Workspace, WorkspaceAgent } from "api/typesGenerated";
Expand Down Expand Up @@ -79,6 +79,15 @@ export const DownloadLogsDialog: FC<DownloadLogsDialogProps> = ({
const isLoadingFiles = downloadableFiles.some((f) => f.blob === undefined);
const [isDownloading, setIsDownloading] = useState(false);

const timeoutIdRef = useRef<number | undefined>(undefined);
useEffect(() => {
const clearTimeoutOnUnmount = () => {
window.clearTimeout(timeoutIdRef.current);
};

return clearTimeoutOnUnmount;
}, []);

return (
<ConfirmDialog
{...dialogProps}
Expand All @@ -96,10 +105,12 @@ export const DownloadLogsDialog: FC<DownloadLogsDialogProps> = ({
zip.file(f.name, f.blob);
}
});

const content = await zip.generateAsync({ type: "blob" });
download(content, `${workspace.name}-logs.zip`);
dialogProps.onClose();
setTimeout(() => {

timeoutIdRef.current = window.setTimeout(() => {
setIsDownloading(false);
}, theme.transitions.duration.leavingScreen);
} catch (error) {
Expand Down