Skip to content

Commit 2dcada8

Browse files
committed
Cleaned up protected routes and stats page
1 parent 36006f2 commit 2dcada8

File tree

4 files changed

+142
-166
lines changed

4 files changed

+142
-166
lines changed

client/lib/router/router.dart

Lines changed: 85 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,6 @@ GoRouter router(Ref ref) {
115115
);
116116
},
117117
routes: [
118-
GoRoute(
119-
name: AppRoute.leaderboard.name,
120-
path: AppRoute.leaderboard.path,
121-
pageBuilder: (context, state) => _buildTransitionPage(
122-
key: state.pageKey,
123-
child: DeferredWidget(
124-
libraryKey: AppRoute.leaderboard.path,
125-
libraryLoader: leaderboard.loadLibrary,
126-
builder: (context) => leaderboard.LeaderboardView(),
127-
),
128-
),
129-
),
130118
GoRoute(
131119
name: AppRoute.calendar.name,
132120
path: AppRoute.calendar.path,
@@ -152,87 +140,112 @@ GoRouter router(Ref ref) {
152140
),
153141
),
154142

155-
// Protected Admin routes
143+
// Protected Routes
156144
GoRoute(
157145
path: _protectedRoute,
158146
redirect: (context, state) {
159-
if (!isLoggedIn && roles.hasPermission(Role.ADMIN)) {
147+
if (!isLoggedIn) {
160148
return AppRoute.login.path;
161149
}
162150
return null;
163151
},
164152
routes: [
165153
GoRoute(
166-
name: AppRoute.setup.name,
167-
path: AppRoute.setup.path,
154+
name: AppRoute.leaderboard.name,
155+
path: AppRoute.leaderboard.path,
168156
pageBuilder: (context, state) => _buildTransitionPage(
169157
key: state.pageKey,
170158
child: DeferredWidget(
171-
libraryKey: AppRoute.setup.path,
172-
libraryLoader: setup.loadLibrary,
173-
builder: (context) => setup.SetupView(),
159+
libraryKey: AppRoute.leaderboard.path,
160+
libraryLoader: leaderboard.loadLibrary,
161+
builder: (context) => leaderboard.LeaderboardView(),
174162
),
175163
),
176164
),
165+
166+
// Protected Admin routes
177167
GoRoute(
178-
name: AppRoute.users.name,
179-
path: AppRoute.users.path,
180-
pageBuilder: (context, state) => _buildTransitionPage(
181-
key: state.pageKey,
182-
child: DeferredWidget(
183-
libraryKey: AppRoute.users.path,
184-
libraryLoader: users.loadLibrary,
185-
builder: (context) => users.UsersView(),
168+
path: '/admin',
169+
redirect: (context, state) {
170+
if (!isLoggedIn && roles.hasPermission(Role.ADMIN)) {
171+
return AppRoute.login.path;
172+
}
173+
return null;
174+
},
175+
routes: [
176+
GoRoute(
177+
name: AppRoute.setup.name,
178+
path: AppRoute.setup.path,
179+
pageBuilder: (context, state) => _buildTransitionPage(
180+
key: state.pageKey,
181+
child: DeferredWidget(
182+
libraryKey: AppRoute.setup.path,
183+
libraryLoader: setup.loadLibrary,
184+
builder: (context) => setup.SetupView(),
185+
),
186+
),
186187
),
187-
),
188-
),
189-
GoRoute(
190-
name: AppRoute.team.name,
191-
path: AppRoute.team.path,
192-
pageBuilder: (context, state) => _buildTransitionPage(
193-
key: state.pageKey,
194-
child: DeferredWidget(
195-
libraryKey: AppRoute.team.path,
196-
libraryLoader: team.loadLibrary,
197-
builder: (context) => team.TeamView(),
188+
GoRoute(
189+
name: AppRoute.users.name,
190+
path: AppRoute.users.path,
191+
pageBuilder: (context, state) => _buildTransitionPage(
192+
key: state.pageKey,
193+
child: DeferredWidget(
194+
libraryKey: AppRoute.users.path,
195+
libraryLoader: users.loadLibrary,
196+
builder: (context) => users.UsersView(),
197+
),
198+
),
198199
),
199-
),
200-
),
201-
GoRoute(
202-
name: AppRoute.sessions.name,
203-
path: AppRoute.sessions.path,
204-
pageBuilder: (context, state) => _buildTransitionPage(
205-
key: state.pageKey,
206-
child: DeferredWidget(
207-
libraryKey: AppRoute.sessions.path,
208-
libraryLoader: sessions.loadLibrary,
209-
builder: (context) => sessions.SessionView(),
200+
GoRoute(
201+
name: AppRoute.team.name,
202+
path: AppRoute.team.path,
203+
pageBuilder: (context, state) => _buildTransitionPage(
204+
key: state.pageKey,
205+
child: DeferredWidget(
206+
libraryKey: AppRoute.team.path,
207+
libraryLoader: team.loadLibrary,
208+
builder: (context) => team.TeamView(),
209+
),
210+
),
210211
),
211-
),
212-
),
213-
GoRoute(
214-
name: AppRoute.locations.name,
215-
path: AppRoute.locations.path,
216-
pageBuilder: (context, state) => _buildTransitionPage(
217-
key: state.pageKey,
218-
child: DeferredWidget(
219-
libraryKey: AppRoute.locations.path,
220-
libraryLoader: locations.loadLibrary,
221-
builder: (context) => locations.LocationsView(),
212+
GoRoute(
213+
name: AppRoute.sessions.name,
214+
path: AppRoute.sessions.path,
215+
pageBuilder: (context, state) => _buildTransitionPage(
216+
key: state.pageKey,
217+
child: DeferredWidget(
218+
libraryKey: AppRoute.sessions.path,
219+
libraryLoader: sessions.loadLibrary,
220+
builder: (context) => sessions.SessionView(),
221+
),
222+
),
222223
),
223-
),
224-
),
225-
GoRoute(
226-
name: AppRoute.stats.name,
227-
path: AppRoute.stats.path,
228-
pageBuilder: (context, state) => _buildTransitionPage(
229-
key: state.pageKey,
230-
child: DeferredWidget(
231-
libraryKey: AppRoute.stats.path,
232-
libraryLoader: stats.loadLibrary,
233-
builder: (context) => stats.StatsView(),
224+
GoRoute(
225+
name: AppRoute.locations.name,
226+
path: AppRoute.locations.path,
227+
pageBuilder: (context, state) => _buildTransitionPage(
228+
key: state.pageKey,
229+
child: DeferredWidget(
230+
libraryKey: AppRoute.locations.path,
231+
libraryLoader: locations.loadLibrary,
232+
builder: (context) => locations.LocationsView(),
233+
),
234+
),
234235
),
235-
),
236+
GoRoute(
237+
name: AppRoute.stats.name,
238+
path: AppRoute.stats.path,
239+
pageBuilder: (context, state) => _buildTransitionPage(
240+
key: state.pageKey,
241+
child: DeferredWidget(
242+
libraryKey: AppRoute.stats.path,
243+
libraryLoader: stats.loadLibrary,
244+
builder: (context) => stats.StatsView(),
245+
),
246+
),
247+
),
248+
],
236249
),
237250
],
238251
),

client/lib/views/calendar/calendar_table.dart

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
33
import 'package:time_keeper/generated/db/db.pb.dart';
44
import 'package:time_keeper/models/session_status.dart';
55
import 'package:time_keeper/providers/location_provider.dart';
6-
import 'package:time_keeper/providers/team_member_provider.dart';
76
import 'package:time_keeper/utils/formatting.dart';
87
import 'package:time_keeper/utils/time.dart';
9-
import 'package:time_keeper/views/sessions/session_detail_dialog.dart';
10-
import 'package:time_keeper/widgets/member_count.dart';
118
import 'package:time_keeper/widgets/status_chip.dart';
129
import 'package:time_keeper/widgets/tables/base_table.dart';
1310

@@ -19,7 +16,6 @@ class CalendarTable extends ConsumerWidget {
1916
@override
2017
Widget build(BuildContext context, WidgetRef ref) {
2118
final locations = ref.watch(locationsProvider);
22-
final teamMembers = ref.watch(teamMembersProvider);
2319
final theme = Theme.of(context);
2420

2521
return BaseTable(
@@ -43,25 +39,17 @@ class CalendarTable extends ConsumerWidget {
4339
BaseTableCell(
4440
child: Text('Location', style: TextStyle(color: Colors.white)),
4541
),
46-
BaseTableCell(
47-
child: Text('Members', style: TextStyle(color: Colors.white)),
48-
),
4942
BaseTableCell(
5043
child: Text('Status', style: TextStyle(color: Colors.white)),
5144
),
52-
BaseTableCell(
53-
child: Text('', style: TextStyle(color: Colors.white)),
54-
),
5545
],
5646
rows: sessions.map((entry) {
57-
final id = entry.key;
5847
final session = entry.value;
5948
final start = session.startTime.toDateTime();
6049
final end = session.endTime.toDateTime();
6150
final duration = end.difference(start);
6251
final locationName =
6352
locations[session.locationId]?.location ?? session.locationId;
64-
final memberCount = session.memberSessions.length;
6553
final status = getSessionStatus(session);
6654

6755
return BaseTableRow(
@@ -73,32 +61,7 @@ class CalendarTable extends ConsumerWidget {
7361
),
7462
BaseTableCell(child: Text(formatDuration(duration))),
7563
BaseTableCell(child: Text(locationName)),
76-
BaseTableCell(
77-
child: MemberCount(
78-
total: memberCount,
79-
status: status,
80-
session: session,
81-
),
82-
),
8364
BaseTableCell(child: SessionStatusChip(status: status)),
84-
BaseTableCell(
85-
child: IconButton(
86-
icon: Icon(
87-
Icons.visibility,
88-
color: theme.colorScheme.primary,
89-
size: 20,
90-
),
91-
tooltip: 'View details',
92-
onPressed: () => showSessionDetailDialog(
93-
context,
94-
ref,
95-
sessionId: id,
96-
session: session,
97-
locations: locations,
98-
teamMembers: teamMembers,
99-
),
100-
),
101-
),
10265
],
10366
);
10467
}).toList(),

client/lib/views/sessions/session_detail_dialog.dart

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -65,69 +65,69 @@ void showSessionDetailDialog(
6565
else
6666
ConstrainedBox(
6767
constraints: const BoxConstraints(maxHeight: 300),
68-
child: ListView.builder(
69-
shrinkWrap: true,
70-
itemCount: memberSessions.length,
71-
itemBuilder: (context, index) {
72-
final ms = memberSessions[index];
73-
final member = teamMembers[ms.teamMemberId];
74-
final name = member != null
75-
? '${member.firstName} ${member.lastName}'
76-
: ms.teamMemberId;
68+
child: SingleChildScrollView(
69+
child: Column(
70+
mainAxisSize: MainAxisSize.min,
71+
children: memberSessions.map((ms) {
72+
final member = teamMembers[ms.teamMemberId];
73+
final name = member != null
74+
? '${member.firstName} ${member.lastName}'
75+
: ms.teamMemberId;
7776

78-
final checkIn = ms.hasCheckInTime()
79-
? formatTime(ms.checkInTime.toDateTime())
80-
: '\u2014';
81-
final checkOut = ms.hasCheckOutTime()
82-
? formatTime(ms.checkOutTime.toDateTime())
83-
: '\u2014';
77+
final checkIn = ms.hasCheckInTime()
78+
? formatTime(ms.checkInTime.toDateTime())
79+
: '\u2014';
80+
final checkOut = ms.hasCheckOutTime()
81+
? formatTime(ms.checkOutTime.toDateTime())
82+
: '\u2014';
8483

85-
Duration? memberDuration;
86-
if (ms.hasCheckInTime() && ms.hasCheckOutTime()) {
87-
memberDuration = ms.checkOutTime.toDateTime().difference(
88-
ms.checkInTime.toDateTime(),
89-
);
90-
}
84+
Duration? memberDuration;
85+
if (ms.hasCheckInTime() && ms.hasCheckOutTime()) {
86+
memberDuration = ms.checkOutTime.toDateTime().difference(
87+
ms.checkInTime.toDateTime(),
88+
);
89+
}
9190

92-
return Padding(
93-
padding: const EdgeInsets.symmetric(vertical: 4),
94-
child: Row(
95-
children: [
96-
Icon(
97-
ms.hasCheckOutTime()
98-
? Icons.check_circle
99-
: Icons.radio_button_checked,
100-
size: 16,
101-
color: ms.hasCheckOutTime()
102-
? Colors.grey
103-
: Colors.green,
104-
),
105-
const SizedBox(width: 8),
106-
Expanded(child: Text(name)),
107-
Text(
108-
'$checkIn - $checkOut',
109-
style: TextStyle(
110-
color: Theme.of(
111-
context,
112-
).colorScheme.onSurfaceVariant,
113-
fontSize: 13,
91+
return Padding(
92+
padding: const EdgeInsets.symmetric(vertical: 4),
93+
child: Row(
94+
children: [
95+
Icon(
96+
ms.hasCheckOutTime()
97+
? Icons.check_circle
98+
: Icons.radio_button_checked,
99+
size: 16,
100+
color: ms.hasCheckOutTime()
101+
? Colors.grey
102+
: Colors.green,
114103
),
115-
),
116-
if (memberDuration != null) ...[
117-
const SizedBox(width: 12),
104+
const SizedBox(width: 8),
105+
Expanded(child: Text(name)),
118106
Text(
119-
formatDuration(memberDuration),
107+
'$checkIn - $checkOut',
120108
style: TextStyle(
121-
fontWeight: FontWeight.w500,
109+
color: Theme.of(
110+
context,
111+
).colorScheme.onSurfaceVariant,
122112
fontSize: 13,
123-
color: Theme.of(context).colorScheme.primary,
124113
),
125114
),
115+
if (memberDuration != null) ...[
116+
const SizedBox(width: 12),
117+
Text(
118+
formatDuration(memberDuration),
119+
style: TextStyle(
120+
fontWeight: FontWeight.w500,
121+
fontSize: 13,
122+
color: Theme.of(context).colorScheme.primary,
123+
),
124+
),
125+
],
126126
],
127-
],
128-
),
129-
);
130-
},
127+
),
128+
);
129+
}).toList(),
130+
),
131131
),
132132
),
133133
],

0 commit comments

Comments
 (0)