Skip to content

Commit 62a2cc6

Browse files
committed
frontend/devices: fix sorting
1 parent 43c4f0d commit 62a2cc6

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

frontend/src/pages/devices.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,41 @@ export class DeviceList extends Component<{}, DeviceListState> {
187187
}
188188

189189
setSort(column: SortColumn) {
190+
let newSortColumn: SortColumn;
191+
let newSortSequence: "asc" | "desc";
192+
190193
if (this.state.sortColumn !== column) {
191-
this.setState({ ...this.state, sortColumn: column, sortSequence: "asc" });
194+
newSortColumn = column;
195+
newSortSequence = "asc";
192196
} else if (this.state.sortSequence === "asc") {
193-
this.setState({ ...this.state, sortSequence: "desc" });
197+
newSortColumn = column;
198+
newSortSequence = "desc";
194199
} else {
195-
this.setState({ ...this.state, sortColumn: "none", sortSequence: "asc" });
200+
newSortColumn = "none";
201+
newSortSequence = "asc";
196202
}
203+
204+
this.setState({
205+
...this.state,
206+
sortColumn: newSortColumn,
207+
sortSequence: newSortSequence
208+
}, () => {
209+
this.setSortedDevices([...this.state.devices]);
210+
});
197211
}
198212

199213
setMobileSort(column: SortColumn) {
214+
let newSortColumn: SortColumn;
215+
200216
if (this.state.sortColumn !== column) {
201-
this.setState({ sortColumn: column });
217+
newSortColumn = column;
202218
} else {
203-
this.setState({ sortColumn: "none" });
219+
newSortColumn = "none";
204220
}
221+
222+
this.setState({ sortColumn: newSortColumn }, () => {
223+
this.setSortedDevices([...this.state.devices]);
224+
});
205225
}
206226

207227
setSortedDevices(devices: StateDevice[]) {
@@ -346,7 +366,10 @@ export class DeviceList extends Component<{}, DeviceListState> {
346366
sortColumn={this.state.sortColumn}
347367
sortSequence={this.state.sortSequence}
348368
onMobileSort={(column) => this.setMobileSort(column)}
349-
onSortSequenceChange={(sequence) => this.setState({ sortSequence: sequence })}
369+
onSortSequenceChange={(sequence) => this.setState({ sortSequence: sequence }, () => {
370+
// Re-sort the devices after state update
371+
this.setSortedDevices([...this.state.devices]);
372+
})}
350373
onConnect={handleConnect}
351374
onDelete={this.handleDelete}
352375
onEditNote={this.handleEditNote}

0 commit comments

Comments
 (0)