Skip to content

Commit

Permalink
Sort by connected gear
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 5, 2024
1 parent 7439d8b commit 1e9c605
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions lib/Frontend/pages/action_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,51 @@ class _ActionSelectorState extends ConsumerState<ActionSelector> {
Map<ActionCategory, Set<BaseAction>> actionsCatMap = {};
List<ActionCategory> catList = [];
List<BaseAction> selected = [];
Set<DeviceType> knownDeviceTypes = {};

@override
void initState() {
super.initState();
actionsCatMap = ref.read(getAllActionsProvider(widget.actionSelectorInfo.deviceType));
catList = actionsCatMap.keys.toList();
selected = widget.actionSelectorInfo.selectedActions;
}

@override
Widget build(BuildContext context) {
Set<DeviceType> knownDeviceTypes = ref
.watch(knownDevicesProvider)
knownDeviceTypes = ref
.read(knownDevicesProvider)
.values
.map(
(e) => e.baseDeviceDefinition.deviceType,
)
.toSet();
actionsCatMap = Map.fromEntries(
ref.read(getAllActionsProvider(widget.actionSelectorInfo.deviceType)).entries.sorted(
(a, b) {
int first = a.value
.map(
(e) => e.deviceCategory,
)
.flattened
.toSet()
.intersection(knownDeviceTypes)
.isNotEmpty
? 1
: -1;
int second = b.value
.map(
(e) => e.deviceCategory,
)
.flattened
.toSet()
.intersection(knownDeviceTypes)
.isNotEmpty
? 1
: -1;
return second.compareTo(first);
},
),
);
selected = widget.actionSelectorInfo.selectedActions;
catList = actionsCatMap.keys.toList();
}

@override
Widget build(BuildContext context) {
return Scaffold(
primary: true,
appBar: AppBar(
Expand Down

0 comments on commit 1e9c605

Please sign in to comment.