From 8b1baae8cc7a1880d2098294c7c9a81e28672fe9 Mon Sep 17 00:00:00 2001 From: desartstudio95 Date: Thu, 7 May 2026 00:13:56 +0200 Subject: [PATCH] feat(SignalHistory): Add date filtering for signals Introduces start and end date input fields to the SignalHistory component, allowing users to filter displayed signals by date range. This improves the usability and relevance of historical signal data. --- src/components/SignalHistory.tsx | 60 ++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/src/components/SignalHistory.tsx b/src/components/SignalHistory.tsx index 93938f9..e026a4b 100644 --- a/src/components/SignalHistory.tsx +++ b/src/components/SignalHistory.tsx @@ -8,6 +8,8 @@ import { auth, db, handleFirestoreError, OperationType } from '../lib/firebase'; export const SignalHistory: React.FC = () => { const [signals, setSignals] = useState([]); const [loading, setLoading] = useState(true); + const [startDate, setStartDate] = useState(''); + const [endDate, setEndDate] = useState(''); useEffect(() => { if (!auth.currentUser) return; @@ -45,25 +47,71 @@ export const SignalHistory: React.FC = () => { ); } + const filteredSignals = signals.filter(signal => { + if (!startDate && !endDate) return true; + + const signalDate = new Date(signal.timestamp); + if (startDate) { + const start = new Date(startDate); + // We parse 'YYYY-MM-DD' dynamically. new Date('YYYY-MM-DD') returns midnight UTC. But let's be careful with local timezones. + const [year, month, day] = startDate.split('-').map(Number); + const localStart = new Date(year, month - 1, day, 0, 0, 0, 0); + if (signalDate < localStart) return false; + } + + if (endDate) { + const [year, month, day] = endDate.split('-').map(Number); + const localEnd = new Date(year, month - 1, day, 23, 59, 59, 999); + if (signalDate > localEnd) return false; + } + + return true; + }); + return (
-
+

Histórico de Sinais

- - {signals.length} Sinais - +
+
+ setStartDate(e.target.value)} + className="bg-transparent text-sm text-zinc-300 outline-none px-2 py-1 [color-scheme:dark]" + /> + - + setEndDate(e.target.value)} + className="bg-transparent text-sm text-zinc-300 outline-none px-2 py-1 [color-scheme:dark]" + /> + {(startDate || endDate) && ( + + )} +
+ + {filteredSignals.length} Sinais + +
- {signals.length === 0 ? ( + {filteredSignals.length === 0 ? (
Nenhum sinal encontrado. Comece realizando um novo scan.
) : ( - signals.map((signal) => ( + filteredSignals.map((signal) => (