Skip to content

Commit

Permalink
Remove forgotten sorting logic that was left in the provider
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Dec 10, 2024
1 parent ac9f535 commit 524c016
Showing 1 changed file with 7 additions and 41 deletions.
48 changes: 7 additions & 41 deletions lib/src/model/broadcast/broadcast_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,14 @@ Future<BroadcastTournament> broadcastTournament(
);
}

enum BroadcastPlayersSortingTypes { player, elo, score }

@riverpod
class BroadcastPlayers extends _$BroadcastPlayers {
@override
Future<IList<BroadcastPlayerExtended>> build(
BroadcastTournamentId tournamentId,
) async {
final players = ref.withClient(
(client) => BroadcastRepository(client).getPlayers(tournamentId),
);

return players;
}

void sort(BroadcastPlayersSortingTypes sortingType, [bool reverse = false]) {
if (!state.hasValue) return;

final compare = switch (sortingType) {
BroadcastPlayersSortingTypes.player =>
(BroadcastPlayerExtended a, BroadcastPlayerExtended b) =>
a.name.compareTo(b.name),
BroadcastPlayersSortingTypes.elo =>
(BroadcastPlayerExtended a, BroadcastPlayerExtended b) {
if (a.rating == null) return -1;
if (b.rating == null) return 1;
return b.rating!.compareTo(a.rating!);
},
BroadcastPlayersSortingTypes.score =>
(BroadcastPlayerExtended a, BroadcastPlayerExtended b) {
if (a.score == null) return -1;
if (b.score == null) return 1;
return b.score!.compareTo(a.score!);
}
};

state = AsyncData(
reverse
? state.requireValue.sortReversed(compare)
: state.requireValue.sort(compare),
);
}
Future<IList<BroadcastPlayerExtended>> broadcastPlayers(
Ref ref,
BroadcastTournamentId tournamentId,
) {
return ref.withClient(
(client) => BroadcastRepository(client).getPlayers(tournamentId),
);
}

@Riverpod(keepAlive: true)
Expand Down

0 comments on commit 524c016

Please sign in to comment.