Skip to content

Commit

Permalink
Merge pull request #215 from ProximaEPFL/fix-challenge-repository
Browse files Browse the repository at this point in the history
Fix challenge repository crash when no available challenge
  • Loading branch information
gruvw authored May 3, 2024
2 parents 4236edc + 2eb2322 commit 6b9a59f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/services/database/challenge_repository_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ class ChallengeRepositoryService {

final Iterable<PostIdFirestore> possiblePosts =
await _inRangeUnsortedPosts(pos, excludedUser);

// The whereIn argument of the where method crashed
// if the query is empty for the real firestore. This
// cannot be tested with the mock firestore.
if (possiblePosts.isEmpty) return;

final Iterable<String> possiblePostsStringIds =
possiblePosts.map((post) => post.value);

Expand Down
16 changes: 11 additions & 5 deletions lib/views/home_content/challenge/challenge_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ class ChallengeList extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final asyncChallenges = ref.watch(challengeProvider);

Widget emptyChallenge = const Center(
child: Text("No challenge available here!"),
);

return CircularValue(
value: asyncChallenges,
builder: (context, challenges) {
return RefreshIndicator(
onRefresh: () => ref.read(challengeProvider.notifier).refresh(),
child: ListView(
children: challenges
.map((challenge) => ChallengeCard(challenge))
.toList(),
),
child: challenges.isEmpty
? emptyChallenge
: ListView(
children: challenges
.map((challenge) => ChallengeCard(challenge))
.toList(),
),
);
},
);
Expand Down

0 comments on commit 6b9a59f

Please sign in to comment.