From 9f0bbd7a6698f81d31cf49fe43d31b41191b2abc Mon Sep 17 00:00:00 2001 From: keannu125 Date: Fri, 10 Mar 2023 21:47:11 +0800 Subject: [PATCH] Refined logs search function --- src/Routes/Logs/Logs.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Routes/Logs/Logs.tsx b/src/Routes/Logs/Logs.tsx index 621dab1..5ab5a68 100644 --- a/src/Routes/Logs/Logs.tsx +++ b/src/Routes/Logs/Logs.tsx @@ -28,7 +28,7 @@ export default function Logs() { (state: OldSessionState) => state.old_session_checked.value ); const [searchTerm, setSearchTerm] = useState(""); - const [searchToday, setSearchToday] = useState(true); + const [searchToday, setSearchToday] = useState(""); function getToday() { const current = new Date(); const date = @@ -84,11 +84,10 @@ export default function Logs() { { - setSearchToday(!searchToday); - if (searchTerm != getToday()) { - setSearchTerm(getToday()); + if (searchToday === "") { + setSearchToday(getToday()); } else { - setSearchTerm(""); + setSearchToday(""); } }} /> @@ -112,7 +111,6 @@ export default function Logs() { }} value={searchTerm} onChange={(e: React.ChangeEvent) => { - setSearchToday(false); setSearchTerm(e.target.value); }} /> @@ -145,9 +143,10 @@ export default function Logs() { {logs.data .filter( (Log: ProductLog) => - Log.name.toLowerCase().includes(searchTerm) || - Log.history_user.toLowerCase().includes(searchTerm) || - Log.history_date.toLowerCase().includes(searchTerm) + (Log.name.toLowerCase().includes(searchTerm) || + Log.history_user.toLowerCase().includes(searchTerm) || + Log.history_date.toLowerCase().includes(searchTerm)) && + Log.history_date.toLowerCase().includes(searchToday) ) .map((row: ProductLog, index: number) => (