mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fix #340, refresh only device/sensor-data if open
This commit is contained in:
@@ -98,12 +98,11 @@ const DashboardData: FC = () => {
|
||||
|
||||
const desktopWindow = useMediaQuery('(min-width:600px)');
|
||||
|
||||
const refreshData = () => {
|
||||
const refreshAllData = () => {
|
||||
if (analog || sensor || deviceValue) {
|
||||
return;
|
||||
}
|
||||
loadData();
|
||||
|
||||
if (sensorData) {
|
||||
fetchSensorData();
|
||||
} else if (selectedDevice) {
|
||||
@@ -111,6 +110,19 @@ const DashboardData: FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const refreshData = () => {
|
||||
if (analog || sensor || deviceValue) {
|
||||
return;
|
||||
}
|
||||
if (sensorData) {
|
||||
fetchSensorData();
|
||||
} else if (selectedDevice) {
|
||||
fetchDeviceData(selectedDevice);
|
||||
} else {
|
||||
loadData();
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => refreshData(), 60000);
|
||||
return () => {
|
||||
@@ -407,6 +419,7 @@ const DashboardData: FC = () => {
|
||||
};
|
||||
|
||||
const toggleDeviceData = (index: number) => {
|
||||
loadData();
|
||||
if (selectedDevice === index) {
|
||||
setSelectedDevice(undefined);
|
||||
} else {
|
||||
@@ -415,6 +428,7 @@ const DashboardData: FC = () => {
|
||||
};
|
||||
|
||||
const toggleSensorData = () => {
|
||||
loadData();
|
||||
if (sensorData) {
|
||||
setSensorData(undefined);
|
||||
} else {
|
||||
@@ -810,7 +824,7 @@ const DashboardData: FC = () => {
|
||||
{renderSensorDialog()}
|
||||
{renderAnalogDialog()}
|
||||
<ButtonRow>
|
||||
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshData}>
|
||||
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshAllData}>
|
||||
Refresh
|
||||
</Button>
|
||||
</ButtonRow>
|
||||
|
||||
Reference in New Issue
Block a user