diff --git a/lib/features/discover/root/presentation/utils/utils.dart b/lib/features/discover/root/presentation/utils/utils.dart index c19702c3..acb134a9 100644 --- a/lib/features/discover/root/presentation/utils/utils.dart +++ b/lib/features/discover/root/presentation/utils/utils.dart @@ -5,81 +5,75 @@ import 'package:d_reader_flutter/shared/presentations/providers/common/search_pr import 'package:d_reader_flutter/shared/utils/utils.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -String _getSortByQueryString(SortByEnum selected, ScrollListType type) { - if (type == ScrollListType.comicList) { - if (selected == SortByEnum.likes) { - return 'sortTag=likes'; - } else if (selected == SortByEnum.rating) { - return 'sortTag=rating'; - } else if (selected == SortByEnum.readers) { - return 'sortTag=readers'; - } else if (selected == SortByEnum.viewers) { - return 'sortTag=viewers'; - } else if (selected == SortByEnum.published) { - return 'sortTag=published'; - } - } else if (type == ScrollListType.issueList) { - if (selected == SortByEnum.latest) { - return 'sortTag=latest'; - } else if (selected == SortByEnum.likes) { - return 'sortTag=likes'; - } else if (selected == SortByEnum.rating) { - return 'sortTag=rating'; - } else if (selected == SortByEnum.readers) { - return 'sortTag=readers'; - } else if (selected == SortByEnum.viewers) { - return 'sortTag=viewers'; - } - } else if (type == ScrollListType.creatorList) { - if (selected == SortByEnum.followers) { - return 'sortTag=followers'; - } +const String _genreSlugsKey = 'genreSlugs[]'; +const String _nameSubstringKey = 'nameSubstring'; +const String _sortOrderKey = 'sortOrder'; +const String _sortTagKey = 'sortTag'; +const String _filterTagKey = 'filterTag'; +const String _titleSubstringKey = 'titleSubstring'; + +String _prependQueryWithKey({required String key, required String value}) => + value.isNotEmpty ? '$key=$value' : ''; + +bool _isCreatorTagOnly(SortByEnum selected) => + selected == SortByEnum.followers || selected == SortByEnum.name; + +String _getSortTagValue(SortByEnum selected, ScrollListType type) { + final bool isCreatorListType = type == ScrollListType.creatorList; + + if (_isCreatorTagOnly(selected)) { + return isCreatorListType ? selected.value() : ''; + } + + if (isCreatorListType) { + return ''; } - return ''; + // special handling for comic filters when latest/published is selected + if (type == ScrollListType.comicList && selected == SortByEnum.latest) { + return SortByEnum.published.value(); + } + return selected.value(); } String getFilterQueryString(WidgetRef ref, ScrollListType scrollListType) { String search = ref.watch(searchProvider).search; final String genreTags = ref .read(selectedGenresProvider) - .map((genreSlug) => 'genreSlugs[]=$genreSlug') + .map((genreSlug) => '$_genreSlugsKey=$genreSlug') .join('&'); final FilterId? selectedFilter = ref.read(selectedFilterProvider); final SortByEnum? selectedSortBy = ref.read(selectedSortByProvider); final SortDirection selectedSortDirection = ref.read(sortDirectionProvider); - final String tagFilter = _filterPerType( - scrollListType: scrollListType, - selectedFilter: selectedFilter, + final String filterBy = _prependQueryWithKey( + key: _filterTagKey, + value: _filterPerType( + scrollListType: scrollListType, + selectedFilter: selectedFilter, + ), ); final String sortByFilter = selectedSortBy != null - ? _getSortByQueryString( - selectedSortBy, - scrollListType, + ? _prependQueryWithKey( + key: _sortTagKey, + value: _getSortTagValue( + selectedSortBy, + scrollListType, + ), ) : ''; final String sortDirection = getSortDirection(selectedSortDirection); final String common = - 'sortOrder=$sortDirection&${_adjustQueryString(genreTags)}${_adjustQueryString(sortByFilter)}${_adjustQueryString(tagFilter)}'; + '$_sortOrderKey=$sortDirection&${_adjustQueryString(genreTags)}${_adjustQueryString(sortByFilter)}${_adjustQueryString(filterBy)}'; final String query = scrollListType == ScrollListType.creatorList - ? '$common${'nameSubstring=$search'}' - : '$common${'titleSubstring=$search'}'; + ? '$common${'$_nameSubstringKey=$search'}' + : '$common${'$_titleSubstringKey=$search'}'; return query; } String _filterPerType({ required ScrollListType scrollListType, FilterId? selectedFilter, -}) { - if (selectedFilter == null) { - return ''; - } - if (scrollListType == ScrollListType.issueList) { - return selectedFilter == FilterId.free - ? 'filterTag=free' - : 'filterTag=popular'; - } - return selectedFilter == FilterId.popular ? 'filterTag=popular' : ''; -} +}) => + selectedFilter == null ? '' : selectedFilter.value(); String _adjustQueryString(String query) => query.isNotEmpty ? '$query&' : ''; diff --git a/lib/features/discover/root/presentation/widgets/filter/filter_bottom_sheet.dart b/lib/features/discover/root/presentation/widgets/filter/filter_bottom_sheet.dart index dd129d1a..ccb74862 100644 --- a/lib/features/discover/root/presentation/widgets/filter/filter_bottom_sheet.dart +++ b/lib/features/discover/root/presentation/widgets/filter/filter_bottom_sheet.dart @@ -25,7 +25,7 @@ class FilterBottomSheet extends ConsumerWidget { child: Padding( padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8), child: AppBar( - backgroundColor: ColorPalette.appBackgroundColor, + backgroundColor: Colors.transparent, elevation: 0, leading: Text( 'Filter', @@ -49,36 +49,36 @@ class FilterBottomSheet extends ConsumerWidget { padding: const EdgeInsets.all(12.0), child: ListView( children: [ + // dont show on creators tab ref.watch(tabBarProvider) != 2 ? Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SectionTitle( - title: ref.watch(tabBarProvider) == 0 - ? 'Show comics' - : 'Show issues', - ), + const SectionTitle(title: 'Show editions'), const SizedBox( height: 16, ), + // for comics we have popular filter only ref.watch(tabBarProvider) == 0 - ? const FilterContainer( - id: FilterId.popular, text: 'Popular') - : const Row( + ? FilterContainer( + id: FilterId.popular, + text: FilterId.popular.displayText(), + ) + : Row( children: [ Expanded( child: FilterContainer( id: FilterId.free, - text: 'Free to read', + text: FilterId.free.displayText(), ), ), - SizedBox( + const SizedBox( width: 8, ), Expanded( child: FilterContainer( id: FilterId.popular, - text: 'Popular', + text: FilterId.popular.displayText(), ), ), ], diff --git a/lib/features/discover/root/presentation/widgets/menus/sort_menu.dart b/lib/features/discover/root/presentation/widgets/menus/sort_menu.dart index 3e774727..8133b365 100644 --- a/lib/features/discover/root/presentation/widgets/menus/sort_menu.dart +++ b/lib/features/discover/root/presentation/widgets/menus/sort_menu.dart @@ -92,74 +92,40 @@ class SortMenu extends ConsumerWidget { const SizedBox( height: 16, ), - if (ref.watch(tabBarProvider) == 0) - const ComicSortMenu() - else if (ref.watch(tabBarProvider) == 1) - const IssueSortMenu() - else if (ref.watch(tabBarProvider) == 2) - const CreatorSortMenu(), + if (ref.watch(tabBarProvider) == 2) + const _CreatorSortMenu() + else + const _DefaultSortMenu() ], ); } } -class ComicSortMenu extends StatelessWidget { - const ComicSortMenu({super.key}); +class _DefaultSortMenu extends StatelessWidget { + const _DefaultSortMenu(); @override Widget build(BuildContext context) { - return const Column( - children: [ - FilterRadioButton( - title: 'New', - value: SortByEnum.latest, - ), - FilterRadioButton( - title: 'Rating', - value: SortByEnum.rating, - ), - FilterRadioButton( - title: 'Likes', - value: SortByEnum.likes, - ), - FilterRadioButton( - title: 'Readers', - value: SortByEnum.readers, - ), - FilterRadioButton( - title: 'Viewers', - value: SortByEnum.viewers, - ), - ], - ); - } -} - -class IssueSortMenu extends StatelessWidget { - const IssueSortMenu({super.key}); - - @override - Widget build(BuildContext context) { - return const Column( + return Column( children: [ - FilterRadioButton( - title: 'New', + CustomRadioButton( + title: SortByEnum.latest.displayText(), value: SortByEnum.latest, ), - FilterRadioButton( - title: 'Rating', + CustomRadioButton( + title: SortByEnum.rating.displayText(), value: SortByEnum.rating, ), - FilterRadioButton( - title: 'Likes', + CustomRadioButton( + title: SortByEnum.likes.displayText(), value: SortByEnum.likes, ), - FilterRadioButton( - title: 'Readers', + CustomRadioButton( + title: SortByEnum.readers.displayText(), value: SortByEnum.readers, ), - FilterRadioButton( - title: 'Viewers', + CustomRadioButton( + title: SortByEnum.viewers.displayText(), value: SortByEnum.viewers, ), ], @@ -167,19 +133,19 @@ class IssueSortMenu extends StatelessWidget { } } -class CreatorSortMenu extends StatelessWidget { - const CreatorSortMenu({super.key}); +class _CreatorSortMenu extends StatelessWidget { + const _CreatorSortMenu(); @override Widget build(BuildContext context) { - return const Column( + return Column( children: [ - FilterRadioButton( - title: 'Name', + CustomRadioButton( + title: SortByEnum.name.displayText(), value: SortByEnum.name, ), - FilterRadioButton( - title: 'Followers', + CustomRadioButton( + title: SortByEnum.followers.displayText(), value: SortByEnum.followers, ), ], diff --git a/lib/features/settings/presentation/screens/change_network.dart b/lib/features/settings/presentation/screens/change_network.dart index 4bc1df91..d6dd1bb2 100644 --- a/lib/features/settings/presentation/screens/change_network.dart +++ b/lib/features/settings/presentation/screens/change_network.dart @@ -31,7 +31,7 @@ class ChangeNetworkView extends ConsumerWidget { }) async { return await triggerConfirmationDialog( context: context, - title: 'Warning, switching to $cluster', + title: 'Change Network', subtitle: subtitle, ); }, diff --git a/lib/features/settings/presentation/screens/profile/profile.dart b/lib/features/settings/presentation/screens/profile/profile.dart index bb908bd6..91ff24b8 100644 --- a/lib/features/settings/presentation/screens/profile/profile.dart +++ b/lib/features/settings/presentation/screens/profile/profile.dart @@ -267,7 +267,7 @@ class ProfileView extends HookConsumerWidget { onTap: () async { final result = await triggerConfirmationDialog( context: context, - title: '', + title: 'Logout', subtitle: 'Are you sure you want logout?', ); if (result) { diff --git a/lib/shared/domain/models/enums.dart b/lib/shared/domain/models/enums.dart index 944bbbb7..14878ede 100644 --- a/lib/shared/domain/models/enums.dart +++ b/lib/shared/domain/models/enums.dart @@ -1,6 +1,14 @@ enum FilterId { free, - popular, + popular; + + String displayText() => switch (this) { + FilterId.free => 'Free to read', + FilterId.popular => 'Popular', + }; + + String value() => + switch (this) { FilterId.free => 'free', FilterId.popular => 'popular' }; } enum SortByEnum { @@ -11,7 +19,29 @@ enum SortByEnum { viewers, followers, name, - published, + published; + + String displayText() => switch (this) { + SortByEnum.latest => 'New', + SortByEnum.rating => 'Rating', + SortByEnum.likes => 'Likes', + SortByEnum.readers => 'Readers', + SortByEnum.viewers => 'Viewers', + SortByEnum.followers => 'Followers', + SortByEnum.name => 'Name', + SortByEnum.published => 'Published', + }; + + String value() => switch (this) { + SortByEnum.latest => 'latest', + SortByEnum.rating => 'rating', + SortByEnum.likes => 'likes', + SortByEnum.readers => 'readers', + SortByEnum.viewers => 'viewers', + SortByEnum.followers => 'followers', + SortByEnum.name => 'name', + SortByEnum.published => 'published', + }; } enum SortDirection { asc, desc } diff --git a/lib/shared/widgets/buttons/radio_button.dart b/lib/shared/widgets/buttons/radio_button.dart index f634f7ff..69165bb4 100644 --- a/lib/shared/widgets/buttons/radio_button.dart +++ b/lib/shared/widgets/buttons/radio_button.dart @@ -4,10 +4,10 @@ import 'package:d_reader_flutter/shared/theme/app_colors.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -class FilterRadioButton extends ConsumerWidget { +class CustomRadioButton extends ConsumerWidget { final String title; final SortByEnum value; - const FilterRadioButton({ + const CustomRadioButton({ super.key, required this.title, required this.value,