From 7dc3729bece1c0e2c4ad135f3eea96c02bf8e794 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Fri, 10 Mar 2023 23:52:20 +0800 Subject: [PATCH] Moved get date today to separate component --- src/Components/LogsPage/GetToday/GetToday.tsx | 11 +++++++++++ src/Routes/Logs/Logs.tsx | 14 ++------------ 2 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 src/Components/LogsPage/GetToday/GetToday.tsx diff --git a/src/Components/LogsPage/GetToday/GetToday.tsx b/src/Components/LogsPage/GetToday/GetToday.tsx new file mode 100644 index 0000000..be17d04 --- /dev/null +++ b/src/Components/LogsPage/GetToday/GetToday.tsx @@ -0,0 +1,11 @@ +export default function GetToday() { + const current = new Date(); + const date = + ("0" + (current.getMonth() + 1)).slice(-2) + + "-" + + ("0" + current.getDate()).slice(-2) + + "-" + + current.getFullYear(); + console.log("Today is " + date); + return date; +} diff --git a/src/Routes/Logs/Logs.tsx b/src/Routes/Logs/Logs.tsx index 5ab5a68..7376047 100644 --- a/src/Routes/Logs/Logs.tsx +++ b/src/Routes/Logs/Logs.tsx @@ -21,6 +21,7 @@ import { } from "../../Interfaces/Interfaces"; import { useState } from "react"; import { useSelector } from "react-redux"; +import GetToday from "../../Components/LogsPage/GetToday/GetToday"; export default function Logs() { const logs = useQuery("logs", GetLogs, { retry: 0 }); @@ -29,17 +30,6 @@ export default function Logs() { ); const [searchTerm, setSearchTerm] = useState(""); const [searchToday, setSearchToday] = useState(""); - function getToday() { - const current = new Date(); - const date = - ("0" + (current.getMonth() + 1)).slice(-2) + - "-" + - ("0" + current.getDate()).slice(-2) + - "-" + - current.getFullYear(); - console.log("Today is " + date); - return date; - } if (logs.isLoading || !old_session_checked) { return (
@@ -85,7 +75,7 @@ export default function Logs() { style={{ flex: 1 }} onClick={() => { if (searchToday === "") { - setSearchToday(getToday()); + setSearchToday(GetToday()); } else { setSearchToday(""); }