Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1280: When switching dashboard, similar box should be refreshed #1283

Merged
merged 7 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions front/src/components/boxs/camera/Camera.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,29 @@ const CameraBox = ({ children, ...props }) => (
</div>
);

@connect('session,DashboardBoxDataCamera,DashboardBoxStatusCamera', actions)
class CameraBoxComponent extends Component {
refreshData = () => {
this.props.getCameraImage(this.props.box, this.props.x, this.props.y);
};
updateDeviceStateWebsocket = payload =>
this.props.deviceFeatureWebsocketEvent(this.props.box, this.props.x, this.props.y, payload);

componentDidMount() {
this.props.getCameraImage(this.props.box, this.props.x, this.props.y);

this.refreshData();
this.props.session.dispatcher.addListener(
WEBSOCKET_MESSAGE_TYPES.DEVICE.NEW_STRING_STATE,
this.updateDeviceStateWebsocket
);
}

componentDidUpdate(previousProps) {
const cameraChanged = get(previousProps, 'box.camera') !== get(this.props, 'box.camera');
const nameChanged = get(previousProps, 'box.name') !== get(this.props, 'box.name');
if (cameraChanged || nameChanged) {
this.refreshData();
}
}

componentWillUnmount() {
this.props.session.dispatcher.removeListener(
WEBSOCKET_MESSAGE_TYPES.DEVICE.NEW_STRING_STATE,
Expand All @@ -61,4 +70,4 @@ class CameraBoxComponent extends Component {
}
}

export default CameraBoxComponent;
export default connect('session,DashboardBoxDataCamera,DashboardBoxStatusCamera', actions)(CameraBoxComponent);
19 changes: 16 additions & 3 deletions front/src/components/boxs/device-in-room/DevicesInRoomsBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,28 @@ const RoomCard = ({ children, ...props }) => {
);
};

@connect('session,user,DashboardBoxDataDevicesInRoom,DashboardBoxStatusDevicesInRoom', actions)
class DevicesInRoomComponent extends Component {
refreshData = () => {
this.props.getDevicesInRoom(this.props.box, this.props.x, this.props.y);
};
updateDeviceStateWebsocket = payload => this.props.deviceFeatureWebsocketEvent(this.props.x, this.props.y, payload);

componentDidMount() {
this.props.getDevicesInRoom(this.props.box, this.props.x, this.props.y);
this.refreshData();
this.props.session.dispatcher.addListener(
WEBSOCKET_MESSAGE_TYPES.DEVICE.NEW_STATE,
this.updateDeviceStateWebsocket
);
}

componentDidUpdate(previousProps) {
const roomChanged = get(previousProps, 'box.room') !== get(this.props, 'box.room');
const deviceFeaturesChanged = get(previousProps, 'box.device_features') !== get(this.props, 'box.device_features');
if (roomChanged || deviceFeaturesChanged) {
this.refreshData();
}
}

componentWillUnmount() {
this.props.session.dispatcher.removeListener(
WEBSOCKET_MESSAGE_TYPES.DEVICE.NEW_STATE,
Expand Down Expand Up @@ -121,4 +131,7 @@ class DevicesInRoomComponent extends Component {
}
}

export default DevicesInRoomComponent;
export default connect(
'session,user,DashboardBoxDataDevicesInRoom,DashboardBoxStatusDevicesInRoom',
actions
)(DevicesInRoomComponent);
19 changes: 16 additions & 3 deletions front/src/components/boxs/room-humidity/RoomHumidity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ const RoomHumidityBox = ({ children, ...props }) => (
</div>
);

@connect('DashboardBoxDataHumidityInRoom,DashboardBoxStatusHumidityInRoom', actions)
class RoomHumidityBoxComponent extends Component {
componentDidMount() {
refreshData = () => {
this.props.getHumidityInRoom(this.props.box, this.props.x, this.props.y);
};

componentDidMount() {
this.refreshData();
}

componentDidUpdate(previousProps) {
const roomChanged = get(previousProps, 'box.room') !== get(this.props, 'box.room');
if (roomChanged) {
this.refreshData();
}
}

render(props, {}) {
Expand All @@ -56,4 +66,7 @@ class RoomHumidityBoxComponent extends Component {
}
}

export default RoomHumidityBoxComponent;
export default connect(
'DashboardBoxDataHumidityInRoom,DashboardBoxStatusHumidityInRoom',
actions
)(RoomHumidityBoxComponent);
19 changes: 16 additions & 3 deletions front/src/components/boxs/room-temperature/RoomTemperature.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ const RoomTemperatureBox = ({ children, ...props }) => (
</div>
);

@connect('DashboardBoxDataTemperatureInRoom,DashboardBoxStatusTemperatureInRoom', actions)
class RoomTemperatureBoxComponent extends Component {
componentDidMount() {
refreshData = () => {
this.props.getTemperatureInRoom(this.props.box, this.props.x, this.props.y);
};

componentDidMount() {
this.refreshData();
}

componentDidUpdate(previousProps) {
const roomChanged = get(previousProps, 'box.room') !== get(this.props, 'box.room');
if (roomChanged) {
this.refreshData();
}
}

render(props, {}) {
Expand All @@ -47,4 +57,7 @@ class RoomTemperatureBoxComponent extends Component {
}
}

export default RoomTemperatureBoxComponent;
export default connect(
'DashboardBoxDataTemperatureInRoom,DashboardBoxStatusTemperatureInRoom',
actions
)(RoomTemperatureBoxComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ class EditUserPresence extends Component {

render(props, { users, selectedUsers, loading }) {
return (
<UserPresenceBox users={users} selectedUsers={selectedUsers} loading={loading} updateUsers={this.updateUsers} />
<UserPresenceBox
{...props}
users={users}
selectedUsers={selectedUsers}
loading={loading}
updateUsers={this.updateUsers}
/>
);
}
}
Expand Down
22 changes: 16 additions & 6 deletions front/src/components/boxs/user-presence/UserPresence.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import get from 'get-value';
import { Text } from 'preact-i18n';
import { RequestStatus } from '../../../utils/consts';
import update from 'immutability-helper';
Expand Down Expand Up @@ -150,14 +151,23 @@ class UserPresenceComponent extends Component {
});
}
};

componentDidMount() {
this.getUsersWithPresence();
this.props.session.dispatcher.addListener(WEBSOCKET_MESSAGE_TYPES.USER_PRESENCE.BACK_HOME, payload =>
this.userChanged(payload)
);
this.props.session.dispatcher.addListener(WEBSOCKET_MESSAGE_TYPES.USER_PRESENCE.LEFT_HOME, payload =>
this.userChanged(payload)
);
this.props.session.dispatcher.addListener(WEBSOCKET_MESSAGE_TYPES.USER_PRESENCE.BACK_HOME, this.userChanged);
this.props.session.dispatcher.addListener(WEBSOCKET_MESSAGE_TYPES.USER_PRESENCE.LEFT_HOME, this.userChanged);
}

componentDidUpdate(previousProps) {
const usersChanged = get(previousProps, 'box.users') !== get(this.props, 'box.users');
if (usersChanged) {
this.getUsersWithPresence();
}
}

componentWillUnmount() {
this.props.session.dispatcher.removeListener(WEBSOCKET_MESSAGE_TYPES.USER_PRESENCE.BACK_HOME, this.userChanged);
this.props.session.dispatcher.removeListener(WEBSOCKET_MESSAGE_TYPES.USER_PRESENCE.LEFT_HOME, this.userChanged);
}

render(props, { usersWithPresence, dashboardUserPresenceGetUsersStatus }) {
Expand Down
28 changes: 23 additions & 5 deletions front/src/components/boxs/weather/WeatherBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,31 @@ const WeatherBox = ({ children, ...props }) => (
</div>
);

@connect('DashboardBoxDataWeather,DashboardBoxStatusWeather,user', actions)
class WeatherBoxComponent extends Component {
componentDidMount() {
// get the weather
refreshData = () => {
this.props.getWeather(this.props.box, this.props.x, this.props.y);
};
componentDidMount() {
this.refreshData();
// refresh weather every interval
setInterval(() => this.props.getWeather(this.props.box, this.props.x, this.props.y), BOX_REFRESH_INTERVAL_MS);
this.interval = setInterval(() => this.refreshData, BOX_REFRESH_INTERVAL_MS);
}

componentDidUpdate(previousProps) {
const houseChanged = get(previousProps, 'box.house') !== get(this.props, 'box.house');
const advancedWeatherChanged =
get(previousProps, 'box.modes.advancedWeather') !== get(this.props, 'box.modes.advancedWeather');
const dailyForecastChanged =
get(previousProps, 'box.modes.dailyForecast') !== get(this.props, 'box.modes.dailyForecast');
const hourlyForecastChanged =
get(previousProps, 'box.modes.hourlyForecast') !== get(this.props, 'box.modes.hourlyForecast');
if (houseChanged || advancedWeatherChanged || dailyForecastChanged || hourlyForecastChanged) {
this.refreshData();
}
}

componentWillUnmount() {
clearInterval(this.interval);
}

render(props, {}) {
Expand Down Expand Up @@ -314,4 +332,4 @@ class WeatherBoxComponent extends Component {
}
}

export default WeatherBoxComponent;
export default connect('DashboardBoxDataWeather,DashboardBoxStatusWeather,user', actions)(WeatherBoxComponent);