Skip to content

Commit

Permalink
feat(review): added next available review indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
SethCohen committed Apr 3, 2023
1 parent 7d99506 commit 6486dce
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/lib/features/review/reviews_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../common/utils/data_provider.dart';
import '../authentication/google_provider.dart';
import 'review_model.dart';

class ReviewPage extends StatefulWidget {
Expand All @@ -24,7 +26,41 @@ class _ReviewPageState extends State<ReviewPage> {
_decks = context.watch<DataProvider>().reviews;

if (_decks.isEmpty) {
return const Center(child: Text('Nothing left to review! Good work!'));
// TODO cleanup
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('No reviews available. Please come back again later.'),
StreamBuilder(
stream: _getNextReview(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}

if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}

if (snapshot.data!.docs.isEmpty) {
return const Text(
'Please do a lesson first to get a review.');
}

final card =
snapshot.data!.docs.first.data() as Map<String, dynamic>;

final formattedDate = (card['nextReview'] as Timestamp)
.toDate()
.toLocal()
.toString();

return Text('Next Review: $formattedDate');
}),
],
));
}

final allCards = _decks.values.expand((element) => element).toList();
Expand Down Expand Up @@ -68,4 +104,15 @@ class _ReviewPageState extends State<ReviewPage> {
},
);
}

Stream<QuerySnapshot> _getNextReview() {
final currentUser = context.read<GoogleSignInProvider>().user;

return FirebaseFirestore.instance
.collectionGroup('cards')
.where('userId', isEqualTo: currentUser!.uid)
.orderBy('nextReview', descending: false)
.limit(1)
.snapshots();
}
}

0 comments on commit 6486dce

Please sign in to comment.