Skip to content

Commit 3b93f8f

Browse files
committed
frontend/devices: write sorted devices to state
This fixes the issue where the notes were being assigned to random devices fix #201
1 parent 6fbd3b1 commit 3b93f8f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

frontend/src/pages/devices.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class DeviceList extends Component<{}, DeviceListState> {
117117
}
118118
stateDevices.push(state_charger);
119119
}
120-
this.setState({ devices: stateDevices });
120+
this.setSortedDevices(stateDevices);
121121
} catch (e) {
122122
const error = `${e}`;
123123
if (error.indexOf("Network") !== -1) {
@@ -204,8 +204,7 @@ export class DeviceList extends Component<{}, DeviceListState> {
204204
}
205205
}
206206

207-
getSortedDevices() {
208-
const devices = [...this.state.devices];
207+
setSortedDevices(devices: StateDevice[]) {
209208
devices.sort((a, b) => {
210209
let sortColumn = this.state.sortColumn;
211210
if (sortColumn === "none") {
@@ -238,7 +237,7 @@ export class DeviceList extends Component<{}, DeviceListState> {
238237
return ret * -1;
239238
}
240239
});
241-
return devices;
240+
this.setState({ devices });
242241
}
243242

244243
handleDelete = (device: StateDevice) => {
@@ -296,7 +295,7 @@ export class DeviceList extends Component<{}, DeviceListState> {
296295
render() {
297296
const { t } = useTranslation("", { useSuspense: false, keyPrefix: "chargers" });
298297
const { route } = useLocation();
299-
const devices = this.getSortedDevices();
298+
const devices = this.state.devices;
300299

301300
const handleConnect = async (device: StateDevice) => {
302301
await this.connect_to_charger(device, route);

0 commit comments

Comments
 (0)