Skip to content

Commit

Permalink
feat: added visual diff for (un)completed lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
SethCohen committed Feb 16, 2023
1 parent aa0bf7f commit e872ffc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/lib/pages/lessons_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class _LessonsPageState extends State<LessonsPage> {
final lessons = snapshot1.data!.docs;
final progress = snapshot2.data!.docs;

final progressCompletion = progress.map((element) {
final data = element.data() as Map<String, dynamic>;
return {
'id': element.id,
'complete': data['complete'],
};
}).toList();

return ListView.builder(
itemCount: lessons.length,
itemBuilder: (context, index) {
Expand All @@ -45,13 +53,16 @@ class _LessonsPageState extends State<LessonsPage> {
.set({"complete": false});
}

// TODO if lesson is complete, change trailing icon color to green
// TODO is lesson is in progress, change trailing icon color to yellow
// TODO if lesson is not complete, change trailing icon color to red
return Card(
child: ListTile(
title: Text(lessonTitle),
trailing: const Icon(Icons.check),
trailing: progressCompletion.firstWhere((element) =>
element['id'] == lessonId)['complete']
? const Icon(Icons.check_circle_outline,
color: Colors.green)
: const Icon(Icons.check_circle_outline,
color: Colors.red),
onTap: () => Navigator.pushNamed(
context,
'/lesson',
Expand Down
22 changes: 21 additions & 1 deletion src/lib/widgets/lesson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,27 @@ class _LessonState extends State<Lesson> {
void _incrementCardIndex() {
setState(() {
if (_currentCardIndex == _cardsLength - 1) {
// TODO mark lesson as complete in database
final user = FirebaseAuth.instance.currentUser!;
final arguments = (ModalRoute.of(context)?.settings.arguments ??
<String, dynamic>{}) as Map;
final currentLesson = arguments['lesson'] as QueryDocumentSnapshot;
FirebaseFirestore.instance
.collection('users')
.doc(user.uid)
.collection('progress')
.doc(currentLesson.id)
.get()
.then((value) {
if (!value.data()!['complete']) {
FirebaseFirestore.instance
.collection('users')
.doc(user.uid)
.collection('progress')
.doc(currentLesson.id)
.update({'complete': true});
}
});

Navigator.pop(context);
} else {
_currentCardIndex++;
Expand Down

0 comments on commit e872ffc

Please sign in to comment.