Skip to content

Commit

Permalink
Fix Minor UI Issues (#75)
Browse files Browse the repository at this point in the history
* Fix Minor UI Issues

* Fix Minor UI Issues
  • Loading branch information
cp-sneha-s authored Mar 14, 2024
1 parent 0619f8f commit c22be68
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
10 changes: 6 additions & 4 deletions lib/data/core/utils/date_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,17 @@ class DateFormatter {
}

String showAnniversaries(
{required DateTime dateOfJoining, required String name, int? number}) {
{required DateTime dateOfJoining,
required DateTime upcomingDate,
required String name,
int? number}) {
final today = DateTime.now().dateOnly;
final difference = dateOfJoining.difference(today);
int yearDifference = (difference.inDays / 365).floor().abs();
final upcomingAnniversaryDate = dateOfJoining.convertToUpcomingDay();
if (upcomingAnniversaryDate.isAtSameMomentAs(today)) {
if (upcomingDate.isAtSameMomentAs(today)) {
return _localization.present_anniversary_text(name, yearDifference);
} else {
return "${_localization.upcoming_anniversary_text(name, yearDifference)} ${getDateRepresentation(upcomingAnniversaryDate).toLowerCase()}!🎉";
return "${_localization.upcoming_anniversary_text(name, yearDifference)} ${getDateRepresentation(upcomingDate).toLowerCase()}!🎉";
}
}

Expand Down
23 changes: 15 additions & 8 deletions lib/ui/shared/events/bloc/celebrations_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,26 @@ class CelebrationsBloc extends Bloc<CelebrationEvent, CelebrationsState> {
final birthdate = e.dateOfBirth!.convertToUpcomingDay();
final Event event = Event(
name: e.name,
dateTime: DateUtils.dateOnly(birthdate),
dateTime: DateUtils.dateOnly(e.dateOfBirth!),
upcomingDate: DateUtils.dateOnly(birthdate),
imageUrl: e.imageUrl);
allBirthdayEvents.add(event);
}
final Event event = Event(
name: e.name,
dateTime: DateUtils.dateOnly(e.dateOfJoining),
imageUrl: e.imageUrl);
allAnniversaryEvents.add(event);
if (e.role != Role.admin) {
final upcomingDate = e.dateOfJoining.convertToUpcomingDay();
final Event event = Event(
name: e.name,
dateTime: DateUtils.dateOnly(e.dateOfJoining),
upcomingDate: DateUtils.dateOnly(upcomingDate),
imageUrl: e.imageUrl);
allAnniversaryEvents.add(event);
}
return e;
}).toList();
allBirthdayEvents.sort((a, b) => a.dateTime.compareTo(b.dateTime));
allAnniversaryEvents.sort((a, b) => a.dateTime.compareTo(b.dateTime));
allBirthdayEvents
.sort((a, b) => a.upcomingDate.compareTo(b.upcomingDate));
allAnniversaryEvents
.sort((a, b) => a.upcomingDate.compareTo(b.upcomingDate));

currentWeekBday = _getBirthdays();
currentWeekAnniversaries = _getAnniversaries();
Expand Down
6 changes: 4 additions & 2 deletions lib/ui/shared/events/celebrations_event_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class EventsList extends StatelessWidget {
? AllEventCard(
imageUrl: event.imageUrl,
name: event.name,
date: event.dateTime)
date: event.upcomingDate)
: CurrentWeekEventCard(
event: event, isAnniversary: isAnniversary);
}).toList(),
Expand Down Expand Up @@ -200,7 +200,9 @@ class CurrentWeekEventCard extends StatelessWidget {
Expanded(
child: Text(isAnniversary
? DateFormatter(context.l10n).showAnniversaries(
dateOfJoining: event.dateTime, name: event.name)
dateOfJoining: event.dateTime,
upcomingDate: event.upcomingDate,
name: event.name)
: DateFormatter(context.l10n).showBirthdays(
dateTime: event.dateTime, name: event.name))),
],
Expand Down
9 changes: 7 additions & 2 deletions lib/ui/shared/events/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ class Event extends Equatable {
final String name;
final String? imageUrl;
final DateTime dateTime;
final DateTime upcomingDate;

const Event({required this.name, required this.dateTime, this.imageUrl});
const Event(
{required this.name,
required this.dateTime,
this.imageUrl,
required this.upcomingDate});

@override
List<Object?> get props => [name, imageUrl, dateTime];
List<Object?> get props => [name, imageUrl, dateTime, upcomingDate];
}
6 changes: 4 additions & 2 deletions test/unit_test/shared/events/celebration_event_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ void main() {

Event event = Event(
name: employee1.name,
dateTime: employee1.dateOfBirth!.convertToUpcomingDay(),
dateTime: employee1.dateOfBirth!,
upcomingDate: employee1.dateOfBirth!.convertToUpcomingDay(),
imageUrl: employee1.imageUrl);
Event event2 = Event(
name: employee2.name,
dateTime: employee2.dateOfBirth!.convertToUpcomingDay(),
dateTime: employee2.dateOfBirth!,
upcomingDate: employee2.dateOfBirth!.convertToUpcomingDay(),
imageUrl: employee2.imageUrl);

setUp(() {
Expand Down

0 comments on commit c22be68

Please sign in to comment.