Skip to content

Commit

Permalink
pull dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alesiaradkevich committed Aug 1, 2023
2 parents 06b9d80 + f765755 commit 5f981c0
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 72 deletions.
3 changes: 3 additions & 0 deletions assets/arrow_down_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion lib/src/presentation/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"commentHint": "Your comment…",
"publish": "Publish",
"add": "Add",
"eventPhotosRestriction": "You can attach up to 10 photos 🖼️"
"eventPhotosRestriction": "You can attach up to 10 photos 🖼️",
"sortBy": "Sort by",
"numberOfLikes": "Number of likes",
"creationDate": "Creation date"
}
5 changes: 4 additions & 1 deletion lib/src/presentation/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"commentHint": "Ваш комментарий…",
"publish": "Опубликовать",
"add": "Добавить",
"eventPhotosRestriction": "Вы можете прикрепить до 10 фото 🖼️"
"eventPhotosRestriction": "Вы можете прикрепить до 10 фото 🖼️",
"sortBy": "Сортировать по",
"numberOfLikes": "Количеству лайков",
"creationDate": "Дате создания"
}
5 changes: 4 additions & 1 deletion lib/src/presentation/l10n/app_uk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"commentHint": "Ваш коментар…",
"publish": "Опублікувати",
"add": "Додати",
"eventPhotosRestriction": "Ви можете прикріпити до 10 фото 🖼️"
"eventPhotosRestriction": "Ви можете прикріпити до 10 фото 🖼️",
"sortBy": "Сортувати за",
"numberOfLikes": "Кількістю лайків",
"creationDate": "Датою створення"
}
19 changes: 18 additions & 1 deletion lib/src/presentation/l10n/suggestions_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart' as intl;

import 'package:suggest_a_feature/src/presentation/l10n/suggestions_localizations_en.dart';
import 'package:suggest_a_feature/src/presentation/l10n/suggestions_localizations_ru.dart';
import 'package:suggest_a_feature/src/presentation/l10n/suggestions_localizations_uk.dart';
Expand Down Expand Up @@ -402,6 +401,24 @@ abstract class SuggestionsLocalizations {
/// In en, this message translates to:
/// **'You can attach up to 10 photos 🖼️'**
String get eventPhotosRestriction;

/// No description provided for @sortBy.
///
/// In en, this message translates to:
/// **'Sort by'**
String get sortBy;

/// No description provided for @numberOfLikes.
///
/// In en, this message translates to:
/// **'Number of likes'**
String get numberOfLikes;

/// No description provided for @creationDate.
///
/// In en, this message translates to:
/// **'Creation date'**
String get creationDate;
}

class _SuggestionsLocalizationsDelegate
Expand Down
15 changes: 13 additions & 2 deletions lib/src/presentation/l10n/suggestions_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class SuggestionsLocalizationsEn extends SuggestionsLocalizations {
String get delete => 'Delete suggestion';

@override
String get deletionQuestion => 'Are you sure you want to delete the suggestion?';
String get deletionQuestion =>
'Are you sure you want to delete the suggestion?';

@override
String get deletionPhotoQuestion => 'Are you sure you want to delete this photo?';
String get deletionPhotoQuestion =>
'Are you sure you want to delete this photo?';

@override
String get title => 'Briefly describe your suggestion';
Expand Down Expand Up @@ -155,4 +157,13 @@ class SuggestionsLocalizationsEn extends SuggestionsLocalizations {

@override
String get eventPhotosRestriction => 'You can attach up to 10 photos 🖼️';

@override
String get sortBy => 'Sort by';

@override
String get numberOfLikes => 'Number of likes';

@override
String get creationDate => 'Creation date';
}
15 changes: 13 additions & 2 deletions lib/src/presentation/l10n/suggestions_localizations_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class SuggestionsLocalizationsRu extends SuggestionsLocalizations {
String get delete => 'Удалить предложение';

@override
String get deletionQuestion => 'Вы действительно хотите удалить это предложение?';
String get deletionQuestion =>
'Вы действительно хотите удалить это предложение?';

@override
String get deletionPhotoQuestion => 'Вы действительно хотите удалить это фото?';
String get deletionPhotoQuestion =>
'Вы действительно хотите удалить это фото?';

@override
String get title => 'Кратко опишите ваше предложение';
Expand Down Expand Up @@ -155,4 +157,13 @@ class SuggestionsLocalizationsRu extends SuggestionsLocalizations {

@override
String get eventPhotosRestriction => 'Вы можете прикрепить до 10 фото 🖼️';

@override
String get sortBy => 'Сортировать по';

@override
String get numberOfLikes => 'Количеству лайков';

@override
String get creationDate => 'Дате создания';
}
9 changes: 9 additions & 0 deletions lib/src/presentation/l10n/suggestions_localizations_uk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,13 @@ class SuggestionsLocalizationsUk extends SuggestionsLocalizations {

@override
String get eventPhotosRestriction => 'Ви можете прикріпити до 10 фото 🖼️';

@override
String get sortBy => 'Сортувати за';

@override
String get numberOfLikes => 'Кількістю лайків';

@override
String get creationDate => 'Датою створення';
}
48 changes: 42 additions & 6 deletions lib/src/presentation/pages/suggestions/suggestions_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:suggest_a_feature/src/domain/data_interfaces/suggestion_repository.dart';
import 'package:suggest_a_feature/src/domain/entities/suggestion.dart';
Expand All @@ -18,7 +19,7 @@ class SuggestionsCubit extends Cubit<SuggestionsState> {
completed: [],
declined: [],
duplicated: [],
isCreateBottomSheetOpened: false,
sortType: SortType.likes,
),
) {
_init();
Expand All @@ -40,7 +41,7 @@ class SuggestionsCubit extends Cubit<SuggestionsState> {
}

Future<void> _onNewSuggestions(List<Suggestion> suggestions) async {
suggestions.sort((a, b) => b.upvotesCount.compareTo(a.upvotesCount));
suggestions.sort(state.sortType.sortFunction);

emit(
state.newState(
Expand Down Expand Up @@ -87,12 +88,47 @@ class SuggestionsCubit extends Cubit<SuggestionsState> {
: _suggestionRepository.upvote(suggestion.id);
}

void openCreateBottomSheet() =>
emit(state.newState(isCreateBottomSheetOpened: true));
void openCreateBottomSheet() => emit(
CreateState(
requests: state.requests,
inProgress: state.inProgress,
completed: state.completed,
declined: state.declined,
duplicated: state.duplicated,
sortType: state.sortType,
activeTab: state.activeTab,
),
);

void closeCreateBottomSheet() =>
emit(state.newState(isCreateBottomSheetOpened: false));
void closeBottomSheet() => emit(
SuggestionsState(
requests: state.requests,
inProgress: state.inProgress,
completed: state.completed,
declined: state.declined,
duplicated: state.duplicated,
sortType: state.sortType,
),
);

void changeActiveTab(SuggestionStatus activeTab) =>
emit(state.newState(activeTab: activeTab));

void openSortingBottomSheet() => emit(
SortingState(
requests: state.requests,
inProgress: state.inProgress,
completed: state.completed,
declined: state.declined,
duplicated: state.duplicated,
sortType: state.sortType,
),
);

void onSortTypeChanged(SortType sortType) {
if (sortType != state.sortType) {
emit(state.newState(sortType: sortType));
_onNewSuggestions(_suggestionRepository.suggestions);
}
}
}
26 changes: 21 additions & 5 deletions lib/src/presentation/pages/suggestions/suggestions_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:suggest_a_feature/src/presentation/pages/suggestions/widgets/sug
import 'package:suggest_a_feature/src/presentation/pages/suggestions/widgets/suggestions_tab_bar.dart';
import 'package:suggest_a_feature/src/presentation/pages/theme/suggestions_theme.dart';
import 'package:suggest_a_feature/src/presentation/pages/widgets/appbar_widget.dart';
import 'package:suggest_a_feature/src/presentation/pages/widgets/bottom_sheets/sorting_bottom_sheet.dart';
import 'package:suggest_a_feature/src/presentation/pages/widgets/fab.dart';
import 'package:suggest_a_feature/src/presentation/utils/assets_strings.dart';
import 'package:suggest_a_feature/src/presentation/utils/context_utils.dart';
Expand Down Expand Up @@ -92,9 +93,9 @@ class _SuggestionsPageState extends State<SuggestionsPage> {
child: SuggestionsCubitScope(
child: BlocBuilder<SuggestionsCubit, SuggestionsState>(
buildWhen: (previous, current) =>
previous.isCreateBottomSheetOpened !=
current.isCreateBottomSheetOpened ||
previous.activeTab != current.activeTab,
previous.type != current.type ||
previous.activeTab != current.activeTab ||
previous.sortType != current.sortType,
builder: (context, state) {
final cubit = context.read<SuggestionsCubit>();
return Stack(
Expand Down Expand Up @@ -126,12 +127,18 @@ class _SuggestionsPageState extends State<SuggestionsPage> {
],
),
),
if (state.isCreateBottomSheetOpened)
if (state is CreateState)
_BottomSheet(
onSaveToGallery: widget.onSaveToGallery,
onUploadMultiplePhotos: widget.onUploadMultiplePhotos,
onCloseBottomSheet: cubit.closeCreateBottomSheet,
onCloseBottomSheet: cubit.closeBottomSheet,
),
if (state is SortingState)
SortingBottomSheet(
closeBottomSheet: cubit.closeBottomSheet,
value: state.sortType,
onChanged: cubit.onSortTypeChanged,
)
],
);
},
Expand Down Expand Up @@ -198,6 +205,8 @@ class _MainContentState extends State<_MainContent>
userId: widget.userId,
onVote: context.read<SuggestionsCubit>().vote,
tabController: _tabController,
openSortingBottomSheet:
context.read<SuggestionsCubit>().openSortingBottomSheet,
),
],
),
Expand Down Expand Up @@ -246,12 +255,14 @@ class _TabBarView extends StatelessWidget {
final OnUploadMultiplePhotosCallback? onUploadMultiplePhotos;
final void Function(SuggestionStatus status, int i) onVote;
final String userId;
final VoidCallback openSortingBottomSheet;

const _TabBarView({
required this.tabController,
required this.onGetUserById,
required this.userId,
required this.onVote,
required this.openSortingBottomSheet,
this.onSaveToGallery,
this.onUploadMultiplePhotos,
});
Expand Down Expand Up @@ -279,6 +290,7 @@ class _TabBarView extends StatelessWidget {
onUploadMultiplePhotos: onUploadMultiplePhotos,
userId: userId,
vote: (i) => onVote(SuggestionStatus.requests, i),
openSortingBottomSheet: openSortingBottomSheet,
),
SuggestionList(
status: SuggestionStatus.inProgress,
Expand All @@ -289,6 +301,7 @@ class _TabBarView extends StatelessWidget {
onUploadMultiplePhotos: onUploadMultiplePhotos,
userId: userId,
vote: (i) => onVote(SuggestionStatus.inProgress, i),
openSortingBottomSheet: openSortingBottomSheet,
),
SuggestionList(
status: SuggestionStatus.completed,
Expand All @@ -299,6 +312,7 @@ class _TabBarView extends StatelessWidget {
onUploadMultiplePhotos: onUploadMultiplePhotos,
userId: userId,
vote: (i) => onVote(SuggestionStatus.completed, i),
openSortingBottomSheet: openSortingBottomSheet,
),
SuggestionList(
status: SuggestionStatus.declined,
Expand All @@ -309,6 +323,7 @@ class _TabBarView extends StatelessWidget {
onUploadMultiplePhotos: onUploadMultiplePhotos,
userId: userId,
vote: (i) => onVote(SuggestionStatus.declined, i),
openSortingBottomSheet: openSortingBottomSheet,
),
SuggestionList(
status: SuggestionStatus.duplicated,
Expand All @@ -319,6 +334,7 @@ class _TabBarView extends StatelessWidget {
onUploadMultiplePhotos: onUploadMultiplePhotos,
userId: userId,
vote: (i) => onVote(SuggestionStatus.duplicated, i),
openSortingBottomSheet: openSortingBottomSheet,
),
],
),
Expand Down
Loading

0 comments on commit 5f981c0

Please sign in to comment.