-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'filter-games' of https://github.com/Mauritz8/mobile int…
…o Mauritz8-filter-games
- Loading branch information
Showing
7 changed files
with
459 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:dartchess/dartchess.dart'; | ||
import 'package:fast_immutable_collections/fast_immutable_collections.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:lichess_mobile/src/model/common/perf.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'game_filter.freezed.dart'; | ||
part 'game_filter.g.dart'; | ||
|
||
@riverpod | ||
class GameFilter extends _$GameFilter { | ||
@override | ||
GameFilterState build({GameFilterState? filter}) { | ||
return filter ?? const GameFilterState(); | ||
} | ||
|
||
void setFilter(GameFilterState filter) => state = state.copyWith( | ||
perfs: filter.perfs, | ||
side: filter.side, | ||
); | ||
} | ||
|
||
@freezed | ||
class GameFilterState with _$GameFilterState { | ||
const GameFilterState._(); | ||
|
||
const factory GameFilterState({ | ||
@Default(ISet<Perf>.empty()) ISet<Perf> perfs, | ||
Side? side, | ||
}) = _GameFilterState; | ||
|
||
int get count { | ||
final fields = [perfs, side]; | ||
return fields | ||
.where((field) => field is Iterable ? field.isNotEmpty : field != null) | ||
.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.