Merge pull request #347 from MichaelDvP/dev_340

fix #340, refresh only device/sensor-data if open
This commit is contained in:
Proddy
2022-02-05 12:48:18 +01:00
committed by GitHub

View File

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