mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
Merge pull request #347 from MichaelDvP/dev_340
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 desktopWindow = useMediaQuery('(min-width:600px)');
|
||||||
|
|
||||||
const refreshData = () => {
|
const refreshAllData = () => {
|
||||||
if (analog || sensor || deviceValue) {
|
if (analog || sensor || deviceValue) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadData();
|
loadData();
|
||||||
|
|
||||||
if (sensorData) {
|
if (sensorData) {
|
||||||
fetchSensorData();
|
fetchSensorData();
|
||||||
} else if (selectedDevice) {
|
} 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(() => {
|
useEffect(() => {
|
||||||
const timer = setInterval(() => refreshData(), 60000);
|
const timer = setInterval(() => refreshData(), 60000);
|
||||||
return () => {
|
return () => {
|
||||||
@@ -407,6 +419,7 @@ const DashboardData: FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleDeviceData = (index: number) => {
|
const toggleDeviceData = (index: number) => {
|
||||||
|
loadData();
|
||||||
if (selectedDevice === index) {
|
if (selectedDevice === index) {
|
||||||
setSelectedDevice(undefined);
|
setSelectedDevice(undefined);
|
||||||
} else {
|
} else {
|
||||||
@@ -415,6 +428,7 @@ const DashboardData: FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleSensorData = () => {
|
const toggleSensorData = () => {
|
||||||
|
loadData();
|
||||||
if (sensorData) {
|
if (sensorData) {
|
||||||
setSensorData(undefined);
|
setSensorData(undefined);
|
||||||
} else {
|
} else {
|
||||||
@@ -810,7 +824,7 @@ const DashboardData: FC = () => {
|
|||||||
{renderSensorDialog()}
|
{renderSensorDialog()}
|
||||||
{renderAnalogDialog()}
|
{renderAnalogDialog()}
|
||||||
<ButtonRow>
|
<ButtonRow>
|
||||||
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshData}>
|
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshAllData}>
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
</ButtonRow>
|
</ButtonRow>
|
||||||
|
|||||||
Reference in New Issue
Block a user