Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter by task type assignments screen #129

Merged
merged 7 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"build": "nest build",
"format": "prettier -w \"src/**/*.ts\"",
"format:check": "prettier -c \"src/**/*.ts\"",
"start": "nest start",
"dev": "dotenv -e .env nest start -- --watch",
"start:debug": "nest start -- --debug --watch",
"pm2:start": "dotenv -e .env pm2 -- start dist/src/main.js",
Expand Down
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
3 changes: 2 additions & 1 deletion frontend/lib/fetch/assignment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Future<List<Assignment>> fetchAssignments({required int groupId}) async {
}
}

void updateAssignmentState(int assignmentId, bool newAssignmentState) async {
Future<void> updateAssignmentState(
int assignmentId, bool newAssignmentState) async {
var assignmentState = newAssignmentState ? "pending" : 'completed';
var apiBaseUrl = getApiBaseUrl();
final response = await authenticatedClient.post(
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: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.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";
}
}
275 changes: 183 additions & 92 deletions frontend/lib/widgets/assignments/assignments_widget.dart

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions frontend/lib/widgets/task_type_switch.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import 'package:flatshare/const.dart';
import 'package:flatshare/models/task.dart';
import 'package:flutter/material.dart';

class TaskTypeSwitch extends StatefulWidget {
const TaskTypeSwitch(
{super.key,
required this.selectedTaskType,
required this.onTaskTypeSelect});

final TaskType selectedTaskType;
final Function(TaskType) onTaskTypeSelect;

@override
State<StatefulWidget> createState() => TaskTypeSwitchState();
}

class TaskTypeSwitchState extends State<TaskTypeSwitch> {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: Colors.grey[300]),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Row(
children: [
Expanded(
child: ElevatedButton(
style: ButtonStyle(
foregroundColor: WidgetStateProperty.all(
widget.selectedTaskType == TaskType.recurring
? Colors.white
: Colors.black),
backgroundColor: WidgetStateProperty.all<Color>(
widget.selectedTaskType == TaskType.recurring
? Colors.blueAccent
: Colors.grey.shade300),
textStyle: WidgetStateProperty.all<TextStyle>(
TextStyle(
fontWeight:
widget.selectedTaskType == TaskType.recurring
? FontWeight.bold
: FontWeight.normal,
),
),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
elevation: WidgetStateProperty.all(generalElevation)),
onPressed: () {
widget.onTaskTypeSelect(TaskType.recurring);
},
child: const Text("Recurring Tasks"))),
const SizedBox(width: 4),
Expanded(
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
widget.selectedTaskType == TaskType.oneOff
? Colors.blueAccent
: Colors.grey.shade300),
foregroundColor: WidgetStateProperty.all(
widget.selectedTaskType == TaskType.oneOff
? Colors.white
: Colors.black),
textStyle: WidgetStateProperty.all<TextStyle>(
TextStyle(
fontWeight:
widget.selectedTaskType == TaskType.oneOff
? FontWeight.bold
: FontWeight.normal,
),
),
shape:
WidgetStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
)),
onPressed: () {
widget.onTaskTypeSelect(TaskType.oneOff);
},
child: const Text("One-Time Tasks"))),
],
),
),
),
);
}
}
88 changes: 10 additions & 78 deletions frontend/lib/widgets/tasks/tasks_overview_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flatshare/const.dart';
import 'package:flatshare/models/task.dart';
import 'package:flatshare/providers/task.dart';
import 'package:flatshare/providers/task_group.dart';
import 'package:flatshare/widgets/task_type_switch.dart';
import 'package:flatshare/widgets/tasks/task_group_list.dart';
import 'package:flatshare/widgets/tasks/task_list.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,7 +16,7 @@ class TasksOverviewWidget extends StatefulWidget {
}

class TasksOverviewWidgetState extends State<TasksOverviewWidget> {
TaskType filterBy = TaskType.recurring;
TaskType filterByTaskType = TaskType.recurring;

@override
void initState() {
Expand All @@ -35,86 +36,17 @@ class TasksOverviewWidgetState extends State<TasksOverviewWidget> {
return Padding(
padding: const EdgeInsets.all(generalRootPadding),
child: Column(children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: Colors.grey[300]),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Row(
children: [
Expanded(
child: ElevatedButton(
style: ButtonStyle(
foregroundColor: WidgetStateProperty.all(
filterBy == TaskType.recurring
? Colors.white
: Colors.black),
backgroundColor: WidgetStateProperty.all<Color>(
filterBy == TaskType.recurring
? Colors.blueAccent
: Colors.grey.shade300),
textStyle: WidgetStateProperty.all<TextStyle>(
TextStyle(
fontWeight: filterBy == TaskType.recurring
? FontWeight.bold
: FontWeight.normal,
),
),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
elevation:
WidgetStateProperty.all(generalElevation)),
onPressed: () {
setState(() {
filterBy = TaskType.recurring;
});
},
child: const Text("Recurring Tasks"))),
const SizedBox(width: 4),
Expanded(
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
filterBy == TaskType.oneOff
? Colors.blueAccent
: Colors.grey.shade300),
foregroundColor: WidgetStateProperty.all(
filterBy == TaskType.oneOff
? Colors.white
: Colors.black),
textStyle: WidgetStateProperty.all<TextStyle>(
TextStyle(
fontWeight: filterBy == TaskType.oneOff
? FontWeight.bold
: FontWeight.normal,
),
),
shape: WidgetStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
)),
onPressed: () {
setState(() {
filterBy = TaskType.oneOff;
});
},
child: const Text("One-Time Tasks"))),
],
),
),
),
TaskTypeSwitch(
selectedTaskType: filterByTaskType,
onTaskTypeSelect: (taskType) {
setState(() {
filterByTaskType = taskType;
});
},
),
const SizedBox(height: 20),
Expanded(
child: filterBy == TaskType.recurring
child: filterByTaskType == TaskType.recurring
? TaskGroupList(taskGroups: taskGroups)
: TaskList(
tasks: oneTimeTasks,
Expand Down
Loading