From 1f2299b2ac42ac0bd29668999136db11d10de449 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Wed, 4 Nov 2020 17:17:49 +0800
Subject: feat: Click on alert makes alert not auto dismiss.

---
 FrontEnd/src/app/views/common/alert/AlertHost.tsx | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'FrontEnd/src/app/views/common/alert/AlertHost.tsx')

diff --git a/FrontEnd/src/app/views/common/alert/AlertHost.tsx b/FrontEnd/src/app/views/common/alert/AlertHost.tsx
index c74f18e2..f50e41ad 100644
--- a/FrontEnd/src/app/views/common/alert/AlertHost.tsx
+++ b/FrontEnd/src/app/views/common/alert/AlertHost.tsx
@@ -22,6 +22,8 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => {
 
   const { t } = useTranslation();
 
+  const timerTag = React.useRef<number | null>(null);
+
   React.useEffect(() => {
     const tag =
       dismissTime === "never"
@@ -29,6 +31,7 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => {
         : typeof dismissTime === "number"
         ? window.setTimeout(props.close, dismissTime)
         : window.setTimeout(props.close, 5000);
+    timerTag.current = tag;
     return () => {
       if (tag != null) {
         window.clearTimeout(tag);
@@ -40,6 +43,12 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => {
     <Alert
       className="m-3"
       variant={alert.type ?? "primary"}
+      onClick={() => {
+        const { current: tag } = timerTag;
+        if (tag != null) {
+          window.clearTimeout(tag);
+        }
+      }}
       onClose={props.close}
       dismissible
     >
-- 
cgit v1.2.3

