Skip to content

Commit

Permalink
feat: Split Pirate Coins page #192
Browse files Browse the repository at this point in the history
  • Loading branch information
PetalCat committed Nov 20, 2023
1 parent d903c36 commit faa74d4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Env managment
lib/dart_define.gen.dart
# start of code generated by package:dart_define, DO NOT modify or remove these comments
dart_define.json
# end of code generated by package:dart_define, DO NOT modify or remove these comments


# l10n
lib/l10n/app_localizations*.dart
Expand Down Expand Up @@ -175,3 +173,8 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser


# start of code generated by package:dart_define, DO NOT modify or remove these comments
dart_define.json
dart_define.json
# end of code generated by package:dart_define, DO NOT modify or remove these comments
19 changes: 16 additions & 3 deletions lib/app/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import "../features/auth/presentation/auth_page/auth_page.dart";
import "../features/dashboard/presentation/dashboard_page/dashboard_page.dart";
import "../features/dashboard/presentation/wrapper_page/wrapper_page.dart";
import "../features/gpa_calculator/presentation/gpa_page/gpa_page.dart";
import "../features/pirate_coins/presentation/pirate_coins_page/pirate_coins_page.dart";
import '../features/pirate_coins/presentation/pirate_coins_page/pirate_coins_student_page.dart';
import '../features/pirate_coins/presentation/pirate_coins_page/pirate_coins_teacher_page.dart';
import "../features/pirate_coins/presentation/stats_page/stats_page.dart";

part "app_router.gr.dart";
Expand Down Expand Up @@ -42,8 +43,20 @@ class AppRouter extends _$AppRouter {
],
children: [
AutoRoute(
page: PirateCoinsRoute.page,
path: "pirate-coins",
page: PirateCoinsTeacherRoute.page,
path: "pirate-coins-teacher",
children: [
AutoRoute(
page: StatsRoute.page,
path: "stats",
title: (context, route) => "Stats",
),
],
title: (context, route) => "Pirate Coins",
),
AutoRoute(
page: PirateCoinsStudentRoute.page,
path: "pirate-coins-student",
children: [
AutoRoute(
page: StatsRoute.page,
Expand Down
3 changes: 2 additions & 1 deletion lib/features/dashboard/application/dashboard_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ List<Applet> get _applets {
image: appletsFolder.pirateCoins.path,
color: const Color.fromARGB(255, 122, 194, 129),
// TODO(lishaduck): figure out how to use routes to keep this type-safe.
location: "/pirate-coins",
location:
"/pirate-coins-student", //not sure how to make this dynamic based on account type
),
Applet(
image: appletsFolder.gpaCalculator.path,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/// This library contains the Pirate Coins feature's main page.
library;

import "package:auto_route/auto_route.dart";
import "package:flutter/material.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";

import "../../../../l10n/l10n.dart";
import "../../../../widgets/big_card/big_card.dart";
// import "../../../auth/domain/account_type.dart";
import "../../application/coins_service.dart";
import "../../domain/coins_model.dart";

/// The page located at `/pirate-coins`.
@RoutePage()
class PirateCoinsStudentPage extends ConsumerWidget {
/// Create a new instance of [PirateCoinsStudentPage].
const PirateCoinsStudentPage({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
// final accountType = ref.watch(accountTypeProvider).valueOrNull;

return const Center(
/// If the user is not a teacher, redirect them to the student page.
child: _StudentView(),
);
}
}

class _StudentView extends ConsumerWidget {
const _StudentView({
// Temporary ignore, see <dart-lang/sdk#49025>.
// ignore: unused_element
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final data = ref.watch(currentUserCoinsProvider);

return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_ViewCoins(data: data),
],
);
}
}

class _ViewCoins extends StatelessWidget {
const _ViewCoins({
required this.data,
// Temporary ignore, see <dart-lang/sdk#49025>.
// ignore: unused_element
super.key,
});

final AsyncValue<CoinsModel> data;

@override
Widget build(BuildContext context) {
final l10n = context.l10n;

return Padding(
padding: const EdgeInsets.all(8),
child: switch (data) {
AsyncData(:final value) => BigCard("${value.coins.coins}"),
AsyncError(:final error) => BigCard(l10n.error("$error")),
AsyncLoading() => Column(
children: [
const CircularProgressIndicator(),
Text(l10n.loading),
],
),
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ import "../../domain/coins_model.dart";

/// The page located at `/pirate-coins`.
@RoutePage()
class PirateCoinsPage extends ConsumerWidget {
/// Create a new instance of [PirateCoinsPage].
const PirateCoinsPage({super.key});
class PirateCoinsTeacherPage extends ConsumerWidget {
/// Create a new instance of [PirateCoinsTeacherPage].
const PirateCoinsTeacherPage({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final accountType = ref.watch(accountTypeProvider).valueOrNull;

return Center(
/// If the user is not a teacher, redirect them to the student page.
child: switch (accountType) {
AccountType.student => const _StudentView(),
_ => const _TeacherView(),
Expand Down

0 comments on commit faa74d4

Please sign in to comment.