Skip to content

Commit

Permalink
Merge pull request #80 from trullse/feat/my-suggestions
Browse files Browse the repository at this point in the history
feat: my suggestions sort
  • Loading branch information
luffan authored Oct 14, 2024
2 parents a2d1d5d + fe3ca9a commit c9ec746
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
17 changes: 12 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand All @@ -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,
),
Expand All @@ -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,
),
Expand All @@ -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<String, Comment> _comments = <String, Comment>{
'1': Comment(
Expand Down Expand Up @@ -239,7 +247,6 @@ class MySuggestionDataSource implements SuggestionsDataSource {
_comments.removeWhere((_, comment) => comment.id == commentId);
}


@override
Future<void> addNotifyToUpdateUser(String suggestionId) async {
final modifiedSet = {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/presentation/localization/localization_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class LocalizationOptions {
final String sortBy;
final String numberOfLikes;
final String creationDate;
final String mySuggestions;

const LocalizationOptions(
this.locale, {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -173,6 +175,7 @@ class LocalizationOptions {
sortBy: 'Сортировать по',
numberOfLikes: 'Количеству лайков',
creationDate: 'Дате создания',
mySuggestions: 'Мои предложения',
);

factory LocalizationOptions.uk() => const LocalizationOptions(
Expand Down Expand Up @@ -231,5 +234,6 @@ class LocalizationOptions {
sortBy: 'Сортувати за',
numberOfLikes: 'Кількістю лайків',
creationDate: 'Датою створення',
mySuggestions: 'Мої пропозиції',
);
}
11 changes: 11 additions & 0 deletions lib/src/presentation/pages/suggestions/suggestions_state.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -177,6 +178,16 @@ extension SortTypeExtension on SortType {
SortType.upvotes => (a, b) => b.upvotesCount.compareTo(a.upvotesCount),
SortType.creationDate => (a, b) =>
b.creationTime.compareTo(a.creationTime),
SortType.userSuggestion => (a, b) {
if (a.authorId == i.userId && b.authorId != i.userId) {
return -1;
}
if (a.authorId != i.userId && b.authorId == i.userId) {
return 1;
}

return b.upvotesCount.compareTo(a.upvotesCount);
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class _SortingBottomSheetState extends State<SortingBottomSheet> {
),
verticalPadding: Dimensions.marginMiddle,
),
ClickableListItem(
title: Text(localization.mySuggestions, style: textStyle),
onClick: () => widget.onChanged(SortType.userSuggestion),
trailing: SuggestionsRadioButton(
selected: widget.value == SortType.userSuggestion,
),
verticalPadding: Dimensions.marginMiddle,
),
],
);
},
Expand Down
2 changes: 1 addition & 1 deletion lib/src/presentation/utils/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ typedef OnGetUserById = Future<SuggestionAuthor?> Function(String id);
typedef OnShareSuggestion = Future<void> Function(String id);

/// Sorting type values
enum SortType { upvotes, creationDate }
enum SortType { upvotes, creationDate, userSuggestion }

0 comments on commit c9ec746

Please sign in to comment.