Moved get date today to separate component

This commit is contained in:
keannu125 2023-03-10 23:52:20 +08:00
parent 9f0bbd7a66
commit 7dc3729bec
2 changed files with 13 additions and 12 deletions

View file

@ -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;
}

View file

@ -21,6 +21,7 @@ import {
} from "../../Interfaces/Interfaces"; } from "../../Interfaces/Interfaces";
import { useState } from "react"; import { useState } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import GetToday from "../../Components/LogsPage/GetToday/GetToday";
export default function Logs() { export default function Logs() {
const logs = useQuery("logs", GetLogs, { retry: 0 }); const logs = useQuery("logs", GetLogs, { retry: 0 });
@ -29,17 +30,6 @@ export default function Logs() {
); );
const [searchTerm, setSearchTerm] = useState(""); const [searchTerm, setSearchTerm] = useState("");
const [searchToday, setSearchToday] = 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) { if (logs.isLoading || !old_session_checked) {
return ( return (
<div> <div>
@ -85,7 +75,7 @@ export default function Logs() {
style={{ flex: 1 }} style={{ flex: 1 }}
onClick={() => { onClick={() => {
if (searchToday === "") { if (searchToday === "") {
setSearchToday(getToday()); setSearchToday(GetToday());
} else { } else {
setSearchToday(""); setSearchToday("");
} }