Skip to content

Commit

Permalink
feat: Add lessons comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0niel committed Jan 4, 2024
1 parent 275ffa6 commit d65d88d
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 117 deletions.
11 changes: 8 additions & 3 deletions lib/presentation/core/routes/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ GoRouter createRouter() => GoRouter(
path: 'details',
builder: (context, state) {
try {
final json = state.extra as Map<String, dynamic>;
final extra =
state.extra as (Map<String, dynamic>, DateTime);
return ScheduleDetailsPage(
lesson: LessonSchedulePart.fromJson(json),
lesson: LessonSchedulePart.fromJson(extra.$1),
selectedDate: extra.$2,
);
} catch (e) {
final extra =
state.extra as (LessonSchedulePart, DateTime);
return ScheduleDetailsPage(
lesson: state.extra as LessonSchedulePart,
lesson: extra.$1,
selectedDate: extra.$2,
);
}
},
Expand Down
90 changes: 9 additions & 81 deletions lib/presentation/widgets/feedback_modal.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:rtu_mirea_app/presentation/widgets/forms/text_input.dart';
import 'package:sentry/sentry.dart';

import '../theme.dart';
Expand Down Expand Up @@ -125,47 +126,11 @@ class _FeedbackBottomModalSheetState extends State<FeedbackBottomModalSheet> {
),
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
errorText: _emailErrorText,
errorStyle: AppTextStyle.captionL.copyWith(
color: AppTheme.colors.colorful07,
),
hintText: 'Введите email',
hintStyle: AppTextStyle.titleS.copyWith(
color: AppTheme.colors.deactive,
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.primary,
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.colorful07,
),
),
disabledBorder: border,
enabledBorder: border,
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.colorful07,
),
),
fillColor: AppTheme.colors.background01,
filled: true,
),
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.done,
style: AppTextStyle.titleS,
TextInput(
hintText: 'Введите email',
controller: _emailController,
errorText: _emailErrorText,
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 24),
Text(
Expand All @@ -175,48 +140,11 @@ class _FeedbackBottomModalSheetState extends State<FeedbackBottomModalSheet> {
),
),
const SizedBox(height: 8),
TextField(
keyboardType: TextInputType.multiline,
maxLines: 5,
TextInput(
hintText: 'Когда я нажимаю "Х" происходит "У"',
controller: _textController,
decoration: InputDecoration(
hintText: 'Когда я нажимаю "Х" происходит "У"',
hintStyle: AppTextStyle.bodyL.copyWith(
color: AppTheme.colors.deactive,
),
errorText: _textErrorText,
errorStyle: AppTextStyle.captionS.copyWith(
color: AppTheme.colors.colorful07,
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.primary,
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.colorful07,
),
),
disabledBorder: border,
enabledBorder: border,
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.colorful07,
),
),
fillColor: AppTheme.colors.background01,
filled: true,
),
textInputAction: TextInputAction.done,
style: AppTextStyle.bodyL,
errorText: _textErrorText,
maxLines: 5,
),
const SizedBox(height: 24),
PrimaryButton(
Expand Down
81 changes: 81 additions & 0 deletions lib/presentation/widgets/forms/text_input.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:rtu_mirea_app/presentation/theme.dart';
import 'package:rtu_mirea_app/presentation/typography.dart';

class TextInput extends StatelessWidget {
const TextInput({
Key? key,
this.hintText,
this.errorText,
this.controller,
this.keyboardType,
this.maxLines,
this.fillColor,
}) : super(key: key);

final String? hintText;
final String? errorText;
final TextEditingController? controller;
final TextInputType? keyboardType;
final int? maxLines;
final Color? fillColor;

@override
Widget build(BuildContext context) {
return TextField(
maxLines: maxLines,
decoration: InputDecoration(
errorText: errorText,
errorStyle: AppTextStyle.captionL.copyWith(
color: AppTheme.colors.colorful07,
),
hintText: hintText,
hintStyle: AppTextStyle.titleS.copyWith(
color: AppTheme.colors.deactive,
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.primary,
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.colorful07,
),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(
color: Colors.transparent,
width: 0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(
color: Colors.transparent,
width: 0,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.colors.colorful07,
),
),
fillColor: fillColor ?? AppTheme.colors.background01,
filled: true,
),
keyboardType: keyboardType,
textInputAction: TextInputAction.done,
style: AppTextStyle.titleS,
controller: controller,
);
}
}
35 changes: 35 additions & 0 deletions lib/schedule/bloc/schedule_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:bloc_concurrency/bloc_concurrency.dart';
import 'package:equatable/equatable.dart';
import 'package:get/get.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:schedule_repository/schedule_repository.dart';
Expand Down Expand Up @@ -32,10 +33,44 @@ class ScheduleBloc extends HydratedBloc<ScheduleEvent, ScheduleState> {
on<SetSelectedSchedule>(_onSetSelectedSchedule);
on<DeleteSchedule>(_onRemoveSavedSchedule);
on<ScheduleSetEmptyLessonsDisplaying>(_onSetEmptyLessonsDisplaying);
on<SetLessonComment>(_onSetLessonComment);
}

final ScheduleRepository _scheduleRepository;

Future<void> _onSetLessonComment(
SetLessonComment event,
Emitter<ScheduleState> emit,
) async {
final comment = state.comments.firstWhereOrNull(
(comment) =>
event.comment.lessonDate == comment.lessonDate &&
event.comment.lessonBells == comment.lessonBells,
);

if (event.comment.text.isEmpty && comment == null) {
return;
}

List<ScheduleComment> updatedComments = state.comments
.where(
(element) =>
element.lessonDate != event.comment.lessonDate ||
element.lessonBells != event.comment.lessonBells,
)
.toList();

if (event.comment.text.isNotEmpty) {
updatedComments.add(event.comment);
}

emit(
state.copyWith(
comments: updatedComments,
),
);
}

Future<void> _onSetEmptyLessonsDisplaying(
ScheduleSetEmptyLessonsDisplaying event,
Emitter<ScheduleState> emit,
Expand Down
5 changes: 5 additions & 0 deletions lib/schedule/bloc/schedule_bloc.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/schedule/bloc/schedule_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ abstract class ScheduleEvent extends Equatable {
const ScheduleEvent();
}

class SetLessonComment extends ScheduleEvent {
const SetLessonComment({
required this.comment,
});

final ScheduleComment comment;

@override
List<Object> get props => [comment];
}

class ScheduleRequested extends ScheduleEvent {
const ScheduleRequested({
required this.group,
Expand Down
8 changes: 8 additions & 0 deletions lib/schedule/bloc/schedule_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ScheduleState extends Equatable {
this.teachersSchedule = const [],
this.groupsSchedule = const [],
this.isMiniature = false,
this.comments = const [],
this.showEmptyLessons = false,
this.selectedSchedule,
});
Expand All @@ -35,6 +36,10 @@ class ScheduleState extends Equatable {

final List<(UID, Group, List<SchedulePart>)> groupsSchedule;

/// Comments attached to certain lessons at certain times (dates and
/// [LessonBells]).
final List<ScheduleComment> comments;

/// Miniature display mode for lesson cards.
final bool isMiniature;

Expand All @@ -53,6 +58,7 @@ class ScheduleState extends Equatable {
SelectedSchedule? selectedSchedule,
bool? isMiniature,
bool? showEmptyLessons,
List<ScheduleComment>? comments,
}) {
return ScheduleState(
status: status ?? this.status,
Expand All @@ -62,6 +68,7 @@ class ScheduleState extends Equatable {
selectedSchedule: selectedSchedule ?? this.selectedSchedule,
isMiniature: isMiniature ?? this.isMiniature,
showEmptyLessons: showEmptyLessons ?? this.showEmptyLessons,
comments: comments ?? this.comments,
);
}

Expand All @@ -76,6 +83,7 @@ class ScheduleState extends Equatable {
isMiniature,
selectedSchedule,
showEmptyLessons,
comments,
];
}

Expand Down
1 change: 1 addition & 0 deletions lib/schedule/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export 'selected_schedule.dart';
export 'selected_classroom_schedule.dart';
export 'selected_group_schedule.dart';
export 'selected_teacher_schedule.dart';
export 'schedule_comment.dart';
Loading

0 comments on commit d65d88d

Please sign in to comment.