Skip to content

Commit

Permalink
feat: show only my assignments for assignments screen
Browse files Browse the repository at this point in the history
  • Loading branch information
invertedEcho committed Nov 8, 2024
1 parent 07d40d8 commit 422a65f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/src/assignment/assignment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
dbGetAssignmentsFromCurrentInterval,
} from 'src/db/functions/assignment';
import { AssignmentState } from 'src/db/schema';
import { AssignmentResponse } from 'src/types';
import { AssignmentResponse } from './types';

@Controller('assignments')
export class AssignmentController {
Expand Down
2 changes: 0 additions & 2 deletions backend/src/types.ts → backend/src/assignment/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: this has to go somewhere else

export type AssignmentResponse = {
id: number;
title: string;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/functions/assignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
or,
sql,
} from 'drizzle-orm';
import { AssignmentResponse } from 'src/types';
import { db } from '..';
import {
AssignmentState,
Expand All @@ -22,6 +21,7 @@ import {
} from '../schema';
import { z } from 'zod';
import { defaultPostgresIntervalSchema } from 'src/utils/interval';
import { AssignmentResponse } from 'src/assignment/types';

// FIXME: This function doesn't only return the assignments from the current interval, but just all assignments newer than `NOW()` minus
// the interval, so let there be a weekly recurring taskgroup, let it be wednesday , it would also return all assignments that are newer
Expand Down
8 changes: 8 additions & 0 deletions frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class _AppState extends State<App> {
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return Colors.blueAccent;
}
return Colors.white;
}),
),
),
darkTheme: ThemeData(brightness: Brightness.dark),
themeMode: ThemeMode.system);
Expand Down
5 changes: 5 additions & 0 deletions frontend/lib/models/assignment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ class Assignment {
taskGroupTitle: json['taskGroupTitle'] as String?,
);
}

@override
String toString() {
return "Assignment: $title ID: $id TaskGroupTitle: $taskGroupTitle";
}
}
34 changes: 31 additions & 3 deletions frontend/lib/widgets/assignments/assignments_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ class AssignmentsWidget extends StatefulWidget {
class AssignmentsWidgetState extends State<AssignmentsWidget> {
late Future<List<Assignment>> _assignmentsFuture;
TaskType filterByTaskType = TaskType.recurring;
bool showOnlyCurrentUserAssignments = true;
int? currentUserId;

// TODO: we should not do async operations in this method, as it could cause unneccessary rebuilds
@override
void didChangeDependencies() {
super.didChangeDependencies();
final userProvider = Provider.of<UserProvider>(context, listen: false);
currentUserId = userProvider.user?.userId;
UserGroup? userGroup = userProvider.userGroup;
final groupId = userGroup?.id;

Expand Down Expand Up @@ -68,8 +71,26 @@ class AssignmentsWidgetState extends State<AssignmentsWidget> {
});
},
),
ListTile(
title: const Text("Show only my assignments"),
onTap: () {
setState(() {
showOnlyCurrentUserAssignments =
!showOnlyCurrentUserAssignments;
});
},
trailing: SizedBox(
height: 24,
width: 24,
child: Checkbox(
value: showOnlyCurrentUserAssignments,
onChanged: (newValue) {
setState(() {
showOnlyCurrentUserAssignments = newValue ?? false;
});
}))),
const SizedBox(
height: 20,
height: 10,
),
Expanded(
child: FutureBuilder<List<Assignment>>(
Expand All @@ -86,13 +107,20 @@ class AssignmentsWidgetState extends State<AssignmentsWidget> {
Map<String, List<Assignment>> groupedAssignments = {};

if (filterByTaskType == TaskType.recurring) {
// print(snapshot.data);
final filteredAssignments = snapshot.data!.where(
(assignment) => assignment.taskGroupTitle != null);
(assignment) =>
assignment.taskGroupTitle != null &&
(!showOnlyCurrentUserAssignments ||
assignment.assigneeId == currentUserId));
groupedAssignments = groupBy(filteredAssignments,
(assignment) => assignment.taskGroupTitle!);
} else if (filterByTaskType == TaskType.oneOff) {
final filteredAssignments = snapshot.data!.where(
(assignment) => assignment.taskGroupTitle == null);
(assignment) =>
assignment.taskGroupTitle == null &&
(!showOnlyCurrentUserAssignments ||
assignment.assigneeId == currentUserId));
groupedAssignments = groupBy(filteredAssignments,
(assignment) => assignment.assigneeName);
}
Expand Down

0 comments on commit 422a65f

Please sign in to comment.