From 0c3453989ed077b61b0e4b9a271b0a863fb7baed Mon Sep 17 00:00:00 2001 From: Aliaksei Date: Wed, 2 Oct 2024 15:29:18 +0300 Subject: [PATCH 1/5] add sort by 'My suggestions' --- .../localization/localization_options.dart | 4 ++++ .../pages/suggestions/suggestions_state.dart | 12 ++++++++++++ .../widgets/bottom_sheets/sorting_bottom_sheet.dart | 8 ++++++++ lib/src/presentation/utils/typedefs.dart | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/src/presentation/localization/localization_options.dart b/lib/src/presentation/localization/localization_options.dart index 62ebbbb..1aac79d 100644 --- a/lib/src/presentation/localization/localization_options.dart +++ b/lib/src/presentation/localization/localization_options.dart @@ -54,6 +54,7 @@ class LocalizationOptions { final String sortBy; final String numberOfLikes; final String creationDate; + final String mySuggestions; const LocalizationOptions( this.locale, { @@ -112,6 +113,7 @@ class LocalizationOptions { this.sortBy = 'Sort by', this.numberOfLikes = 'Number of likes', this.creationDate = 'Creation date', + this.mySuggestions = 'My suggestions', }); factory LocalizationOptions.en() => const LocalizationOptions('en'); @@ -173,6 +175,7 @@ class LocalizationOptions { sortBy: 'Сортировать по', numberOfLikes: 'Количеству лайков', creationDate: 'Дате создания', + mySuggestions: 'Мои предложения', ); factory LocalizationOptions.uk() => const LocalizationOptions( @@ -231,5 +234,6 @@ class LocalizationOptions { sortBy: 'Сортувати за', numberOfLikes: 'Кількістю лайків', creationDate: 'Датою створення', + mySuggestions: 'Мої пропозиції', ); } diff --git a/lib/src/presentation/pages/suggestions/suggestions_state.dart b/lib/src/presentation/pages/suggestions/suggestions_state.dart index 6850c06..a0d56ba 100644 --- a/lib/src/presentation/pages/suggestions/suggestions_state.dart +++ b/lib/src/presentation/pages/suggestions/suggestions_state.dart @@ -1,5 +1,6 @@ import 'package:equatable/equatable.dart'; import 'package:suggest_a_feature/src/domain/entities/suggestion.dart'; +import 'package:suggest_a_feature/src/presentation/di/injector.dart'; import 'package:suggest_a_feature/src/presentation/utils/typedefs.dart'; class SuggestionsState extends Equatable { @@ -136,6 +137,17 @@ extension SortTypeExtension on SortType { SortType.upvotes => (a, b) => b.upvotesCount.compareTo(a.upvotesCount), SortType.creationDate => (a, b) => b.creationTime.compareTo(a.creationTime), + SortType.mySuggestions => (a, b) { + if (a.authorId == i.userId && b.authorId == i.userId) { + return b.upvotesCount.compareTo(a.upvotesCount); + } else if (a.authorId == i.userId) { + return -1; + } else if (b.authorId == i.userId) { + return 1; + } else { + return b.upvotesCount.compareTo(a.upvotesCount); + } + } }; } } diff --git a/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart b/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart index 56aa83f..9aff216 100644 --- a/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart +++ b/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart @@ -57,6 +57,14 @@ class _SortingBottomSheetState extends State { ), verticalPadding: Dimensions.marginMiddle, ), + ClickableListItem( + title: Text(localization.mySuggestions, style: textStyle), + onClick: () => widget.onChanged(SortType.mySuggestions), + trailing: SuggestionsRadioButton( + selected: widget.value == SortType.mySuggestions, + ), + verticalPadding: Dimensions.marginMiddle, + ), ], ); }, diff --git a/lib/src/presentation/utils/typedefs.dart b/lib/src/presentation/utils/typedefs.dart index 67a0c7e..cc2ea20 100644 --- a/lib/src/presentation/utils/typedefs.dart +++ b/lib/src/presentation/utils/typedefs.dart @@ -21,4 +21,4 @@ typedef OnSaveToGalleryCallback = Future Function(String url); typedef OnGetUserById = Future Function(String id); /// Sorting type values -enum SortType { upvotes, creationDate } +enum SortType { upvotes, creationDate, mySuggestions } From 43ef838d93aaea448ab227fb7f7d3e1af16ae51e Mon Sep 17 00:00:00 2001 From: Aliaksei Date: Wed, 2 Oct 2024 15:30:30 +0300 Subject: [PATCH 2/5] update example for sorting by 'My suggestions' --- example/lib/main.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 621983c..920b805 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -59,7 +59,7 @@ class MySuggestionDataSource implements SuggestionsDataSource { title: 'Hashtags', authorId: '1', isAnonymous: false, - creationTime: DateTime.now(), + creationTime: DateTime.now().subtract(const Duration(days: 3)), description: 'Ability to add and filter events with #hashtags', status: SuggestionStatus.requests, ), @@ -69,7 +69,7 @@ class MySuggestionDataSource implements SuggestionsDataSource { authorId: '2', isAnonymous: true, labels: const [SuggestionLabel.feature], - creationTime: DateTime.now(), + creationTime: DateTime.now().subtract(const Duration(days: 2)), description: 'Feature to import and export events', status: SuggestionStatus.requests, ), @@ -88,7 +88,7 @@ class MySuggestionDataSource implements SuggestionsDataSource { authorId: '4', isAnonymous: true, labels: const [SuggestionLabel.feature], - creationTime: DateTime.now(), + creationTime: DateTime.now().subtract(const Duration(days: 1)), description: 'Аbility to save video', status: SuggestionStatus.inProgress, ), @@ -105,11 +105,19 @@ class MySuggestionDataSource implements SuggestionsDataSource { '6': Suggestion( id: '6', title: 'Offline authorization', - authorId: '6', + authorId: '1', isAnonymous: false, creationTime: DateTime.now(), status: SuggestionStatus.completed, ), + '7': Suggestion( + id: '7', + title: 'Ability to add time', + authorId: '1', + isAnonymous: false, + creationTime: DateTime.now(), + status: SuggestionStatus.requests, + ), }; final Map _comments = { '1': Comment( @@ -239,7 +247,6 @@ class MySuggestionDataSource implements SuggestionsDataSource { _comments.removeWhere((_, comment) => comment.id == commentId); } - @override Future addNotifyToUpdateUser(String suggestionId) async { final modifiedSet = { From 19fcb9a3db7e982e1822856c75e4ea80aea1f0e8 Mon Sep 17 00:00:00 2001 From: Aliaksei Date: Wed, 2 Oct 2024 18:16:26 +0300 Subject: [PATCH 3/5] ref SortType value --- lib/src/presentation/pages/suggestions/suggestions_state.dart | 2 +- .../pages/widgets/bottom_sheets/sorting_bottom_sheet.dart | 4 ++-- lib/src/presentation/utils/typedefs.dart | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/presentation/pages/suggestions/suggestions_state.dart b/lib/src/presentation/pages/suggestions/suggestions_state.dart index a0d56ba..5905103 100644 --- a/lib/src/presentation/pages/suggestions/suggestions_state.dart +++ b/lib/src/presentation/pages/suggestions/suggestions_state.dart @@ -137,7 +137,7 @@ extension SortTypeExtension on SortType { SortType.upvotes => (a, b) => b.upvotesCount.compareTo(a.upvotesCount), SortType.creationDate => (a, b) => b.creationTime.compareTo(a.creationTime), - SortType.mySuggestions => (a, b) { + SortType.userSuggestion => (a, b) { if (a.authorId == i.userId && b.authorId == i.userId) { return b.upvotesCount.compareTo(a.upvotesCount); } else if (a.authorId == i.userId) { diff --git a/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart b/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart index 9aff216..5e60879 100644 --- a/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart +++ b/lib/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart @@ -59,9 +59,9 @@ class _SortingBottomSheetState extends State { ), ClickableListItem( title: Text(localization.mySuggestions, style: textStyle), - onClick: () => widget.onChanged(SortType.mySuggestions), + onClick: () => widget.onChanged(SortType.userSuggestion), trailing: SuggestionsRadioButton( - selected: widget.value == SortType.mySuggestions, + selected: widget.value == SortType.userSuggestion, ), verticalPadding: Dimensions.marginMiddle, ), diff --git a/lib/src/presentation/utils/typedefs.dart b/lib/src/presentation/utils/typedefs.dart index cc2ea20..5d26304 100644 --- a/lib/src/presentation/utils/typedefs.dart +++ b/lib/src/presentation/utils/typedefs.dart @@ -21,4 +21,4 @@ typedef OnSaveToGalleryCallback = Future Function(String url); typedef OnGetUserById = Future Function(String id); /// Sorting type values -enum SortType { upvotes, creationDate, mySuggestions } +enum SortType { upvotes, creationDate, userSuggestion } From 57ed34085324528a88765a51edf6c50cb523b0c4 Mon Sep 17 00:00:00 2001 From: Aliaksei Date: Wed, 2 Oct 2024 18:31:59 +0300 Subject: [PATCH 4/5] ref sort by user suggestion --- .../pages/suggestions/suggestions_state.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/presentation/pages/suggestions/suggestions_state.dart b/lib/src/presentation/pages/suggestions/suggestions_state.dart index 5905103..8e5545d 100644 --- a/lib/src/presentation/pages/suggestions/suggestions_state.dart +++ b/lib/src/presentation/pages/suggestions/suggestions_state.dart @@ -138,15 +138,15 @@ extension SortTypeExtension on SortType { SortType.creationDate => (a, b) => b.creationTime.compareTo(a.creationTime), SortType.userSuggestion => (a, b) { - if (a.authorId == i.userId && b.authorId == i.userId) { - return b.upvotesCount.compareTo(a.upvotesCount); - } else if (a.authorId == i.userId) { + if (a.authorId == i.userId) { + if (b.authorId == i.userId) { + return b.upvotesCount.compareTo(a.upvotesCount); + } return -1; } else if (b.authorId == i.userId) { return 1; - } else { - return b.upvotesCount.compareTo(a.upvotesCount); } + return b.upvotesCount.compareTo(a.upvotesCount); } }; } From fe3ca9a55ed4dfd82a0346ea71745ddeda82316b Mon Sep 17 00:00:00 2001 From: Aliaksei Date: Thu, 3 Oct 2024 19:16:47 +0300 Subject: [PATCH 5/5] ref sorting by user's suggestions --- .../pages/suggestions/suggestions_state.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/presentation/pages/suggestions/suggestions_state.dart b/lib/src/presentation/pages/suggestions/suggestions_state.dart index 8e5545d..15bad36 100644 --- a/lib/src/presentation/pages/suggestions/suggestions_state.dart +++ b/lib/src/presentation/pages/suggestions/suggestions_state.dart @@ -138,14 +138,13 @@ extension SortTypeExtension on SortType { SortType.creationDate => (a, b) => b.creationTime.compareTo(a.creationTime), SortType.userSuggestion => (a, b) { - if (a.authorId == i.userId) { - if (b.authorId == i.userId) { - return b.upvotesCount.compareTo(a.upvotesCount); - } + if (a.authorId == i.userId && b.authorId != i.userId) { return -1; - } else if (b.authorId == i.userId) { + } + if (a.authorId != i.userId && b.authorId == i.userId) { return 1; } + return b.upvotesCount.compareTo(a.upvotesCount); } };