Refined logs search function

This commit is contained in:
keannu125 2023-03-10 21:47:11 +08:00
parent 5b5a699dd8
commit 9f0bbd7a66

View file

@ -28,7 +28,7 @@ export default function Logs() {
(state: OldSessionState) => state.old_session_checked.value (state: OldSessionState) => state.old_session_checked.value
); );
const [searchTerm, setSearchTerm] = useState(""); const [searchTerm, setSearchTerm] = useState("");
const [searchToday, setSearchToday] = useState(true); const [searchToday, setSearchToday] = useState("");
function getToday() { function getToday() {
const current = new Date(); const current = new Date();
const date = const date =
@ -84,11 +84,10 @@ export default function Logs() {
<Switch <Switch
style={{ flex: 1 }} style={{ flex: 1 }}
onClick={() => { onClick={() => {
setSearchToday(!searchToday); if (searchToday === "") {
if (searchTerm != getToday()) { setSearchToday(getToday());
setSearchTerm(getToday());
} else { } else {
setSearchTerm(""); setSearchToday("");
} }
}} }}
/> />
@ -112,7 +111,6 @@ export default function Logs() {
}} }}
value={searchTerm} value={searchTerm}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setSearchToday(false);
setSearchTerm(e.target.value); setSearchTerm(e.target.value);
}} }}
/> />
@ -145,9 +143,10 @@ export default function Logs() {
{logs.data {logs.data
.filter( .filter(
(Log: ProductLog) => (Log: ProductLog) =>
Log.name.toLowerCase().includes(searchTerm) || (Log.name.toLowerCase().includes(searchTerm) ||
Log.history_user.toLowerCase().includes(searchTerm) || Log.history_user.toLowerCase().includes(searchTerm) ||
Log.history_date.toLowerCase().includes(searchTerm) Log.history_date.toLowerCase().includes(searchTerm)) &&
Log.history_date.toLowerCase().includes(searchToday)
) )
.map((row: ProductLog, index: number) => ( .map((row: ProductLog, index: number) => (
<TableRow <TableRow