fix #340, refresh only device/sensor-data if open

This commit is contained in:
MichaelDvP
2022-01-31 10:23:10 +01:00
parent 3d1a050e22
commit 77df8cc69b

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>