This commit is contained in:
@@ -29,6 +29,32 @@ function DailyReportContent() {
|
||||
const [forecastWeather, setForecastWeather] = useState<WeatherData | null>(null)
|
||||
const [forecastWeatherLoading, setForecastWeatherLoading] = useState(false)
|
||||
|
||||
// Map summary param to chart key
|
||||
const paramToChartKey = useCallback((param: string): string => {
|
||||
const mapping: Record<string, string> = {
|
||||
temperature: 'temp',
|
||||
humidity: 'hum',
|
||||
gas: 'gas',
|
||||
soil: 'soil',
|
||||
lux: 'lux',
|
||||
}
|
||||
return mapping[param] || param
|
||||
}, [])
|
||||
|
||||
// Handle card click: switch to charts tab and scroll to chart
|
||||
const handleCardClick = useCallback((param: string) => {
|
||||
const chartKey = paramToChartKey(param)
|
||||
setActiveTab('charts')
|
||||
|
||||
// Wait for tab to switch and chart to render, then scroll
|
||||
setTimeout(() => {
|
||||
const chartElement = document.getElementById(`chart-${chartKey}`)
|
||||
if (chartElement) {
|
||||
chartElement.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
}, 100)
|
||||
}, [paramToChartKey])
|
||||
|
||||
const deviceId = Number(searchParams.get('deviceId') ?? '1')
|
||||
const dateParam = searchParams.get('date') ?? formatPersianDate(getCurrentPersianYear(), getCurrentPersianMonth(), getCurrentPersianDay())
|
||||
|
||||
@@ -217,7 +243,7 @@ function DailyReportContent() {
|
||||
className="md:mx-0 mx-[-1rem] md:rounded-xl rounded-none"
|
||||
>
|
||||
{{
|
||||
summary: <SummaryTab temperature={temp} humidity={hum} soil={soil} gas={gas} lux={lux} forecastWeather={forecastWeather} forecastWeatherLoading={forecastWeatherLoading} />,
|
||||
summary: <SummaryTab temperature={temp} humidity={hum} soil={soil} gas={gas} lux={lux} forecastWeather={forecastWeather} forecastWeatherLoading={forecastWeatherLoading} onCardClick={handleCardClick} />,
|
||||
charts: (
|
||||
<Suspense fallback={<Loading message="در حال بارگذاری نمودارها..." />}>
|
||||
<ChartsTab sortedTelemetry={sortedTelemetry} dataGaps={dataGaps} />
|
||||
|
||||
Reference in New Issue
Block a user