Skip to content

Commit eb68e40

Browse files
committed
fix(frontend): fix some state and params issues
1 parent d9291dd commit eb68e40

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/components/modals/generic-confirm-dialog.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AlertDialogFooter,
77
AlertDialogHeader,
88
AlertDialogOverlay,
9+
AlertDialogProps,
910
Button,
1011
Checkbox,
1112
HStack,
@@ -15,9 +16,10 @@ import { t } from "i18next";
1516
import { useRef, useState } from "react";
1617
import { useLauncherConfig } from "@/contexts/config";
1718

18-
interface GenericConfirmDialogProps {
19-
isOpen: boolean;
20-
onClose: () => void;
19+
interface GenericConfirmDialogProps extends Omit<
20+
AlertDialogProps,
21+
"children" | "leastDestructiveRef"
22+
> {
2123
title: string;
2224
body: string | React.ReactElement;
2325
footerLeft?: React.ReactElement;
@@ -27,6 +29,7 @@ interface GenericConfirmDialogProps {
2729
onCancelCallback?: () => void;
2830
isAlert?: boolean;
2931
isLoading?: boolean;
32+
showCloseBtn?: boolean;
3033
showSuppressBtn?: boolean;
3134
suppressKey?: string;
3235
}
@@ -43,8 +46,10 @@ const GenericConfirmDialog: React.FC<GenericConfirmDialogProps> = ({
4346
onCancelCallback,
4447
isAlert = false,
4548
isLoading = false,
49+
showCloseBtn = true,
4650
showSuppressBtn = false,
4751
suppressKey,
52+
...props
4853
}) => {
4954
const cancelRef = useRef<HTMLButtonElement>(null);
5055
const { config, update } = useLauncherConfig();
@@ -74,11 +79,12 @@ const GenericConfirmDialog: React.FC<GenericConfirmDialogProps> = ({
7479
onClose={handleCancel}
7580
autoFocus={false}
7681
isCentered
82+
{...props}
7783
>
7884
<AlertDialogOverlay>
7985
<AlertDialogContent>
8086
<AlertDialogHeader>{title}</AlertDialogHeader>
81-
<AlertDialogCloseButton />
87+
{showCloseBtn && <AlertDialogCloseButton />}
8288
<AlertDialogBody>{body}</AlertDialogBody>
8389
<AlertDialogFooter>
8490
<HStack spacing={3}>

src/layouts/main-layout.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
4545

4646
const [bgImgSrc, setBgImgSrc] = useState<string>("");
4747
const isCheckedRunCount = useRef(false);
48+
const isCheckedLastRunStatus = useRef(false);
4849

4950
const {
5051
isOpen: isWelcomeAndTermsModalOpen,
@@ -63,17 +64,21 @@ const MainLayout = ({ children }: MainLayoutProps) => {
6364
title: t("UnavailableExePathAlertDialog.dialog.title"),
6465
body: t("UnavailableExePathAlertDialog.dialog.content"),
6566
btnCancel: t("UnavailableExePathAlertDialog.dialog.btnContinue"),
67+
onCancelCallback: () => update("runCount", config.runCount + 1), // because this dialog will skip the run count check
6668
btnOK: t("General.exit"),
67-
isAlert: true,
6869
onOKCallback: () => exit(0),
6970
footerLeft: (
7071
<HStack spacing={2}>
7172
<LuLanguages />
7273
<LanguageMenu placement="top" />
7374
</HStack>
7475
),
76+
isAlert: true,
77+
closeOnEsc: false,
78+
closeOnOverlayClick: false,
79+
showCloseBtn: false,
7580
});
76-
}, [openGenericConfirmDialog]);
81+
}, [config.runCount, openGenericConfirmDialog, update]);
7782

7883
const openLastExitedAbnormallyDialog = useCallback(() => {
7984
openGenericConfirmDialog({
@@ -132,11 +137,12 @@ const MainLayout = ({ children }: MainLayoutProps) => {
132137
}
133138

134139
// update `last_run_exited_normally` to false, will be updated when this run ends with normal exit.
135-
if (!config.mocked && !isCheckedRunCount.current && !isStandAlone) {
140+
if (!config.mocked && !isCheckedLastRunStatus.current && !isStandAlone) {
136141
if (!config.lastRunExitedNormally) {
137142
openLastExitedAbnormallyDialog();
138143
}
139144
update("lastRunExitedNormally", false);
145+
isCheckedLastRunStatus.current = true;
140146
}
141147

142148
// update run count, conditionally show some modals.

0 commit comments

Comments
 (0)