Skip to content

Commit 38fc5bc

Browse files
committed
ExplorePage: replace filter bar with dropdown (#43)
1 parent bb3fc91 commit 38fc5bc

14 files changed

+153
-454
lines changed

Diff for: lib/l10n/app_en.arb

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"serverAndCloud": "Server and Cloud",
2525
"social": "Social",
2626
"utilities": "Utilities",
27+
"all": "All",
2728
"installDate": "Installation Date",
2829
"lastUpdated": "Last updated",
2930
"notInstalled": "Not installed",
@@ -51,5 +52,6 @@
5152
"sortBy": "Sort by",
5253
"media": "Media",
5354
"done": "Done",
54-
"systemUpdates": "System updates"
55+
"systemUpdates": "System updates",
56+
"searchHint": "Search..."
5557
}

Diff for: lib/store_app/common/app_tile.dart

-30
This file was deleted.

Diff for: lib/store_app/common/constants.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'package:flutter/material.dart';
22

3-
const dialogWidth = 400.0;
3+
const dialogWidth = 450.0;
44
const kGridDelegate = SliverGridDelegateWithMaxCrossAxisExtent(
55
mainAxisExtent: 110,
66
mainAxisSpacing: 15,
77
crossAxisSpacing: 15,
8-
maxCrossAxisExtent: 600,
8+
maxCrossAxisExtent: 550,
99
);

Diff for: lib/store_app/common/snap_section.dart

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:software/l10n/l10n.dart';
55
import 'package:yaru_icons/yaru_icons.dart';
66

77
enum SnapSection {
8+
all,
89
art_and_design,
910
books_and_reference,
1011
development,
@@ -70,6 +71,8 @@ enum SnapSection {
7071
return l10n.social;
7172
case SnapSection.utilities:
7273
return l10n.utilities;
74+
case SnapSection.all:
75+
return l10n.all;
7376
default:
7477
return title;
7578
}
@@ -97,4 +100,5 @@ Map<SnapSection, IconData> snapSectionToIcon = {
97100
SnapSection.server_and_cloud: YaruIcons.weather_cloudy,
98101
SnapSection.social: YaruIcons.subtitles,
99102
SnapSection.utilities: YaruIcons.utilities,
103+
SnapSection.all: YaruIcons.compass
100104
};

Diff for: lib/store_app/explore/explore_model.dart

+22-49
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ class ExploreModel extends SafeChangeNotifier {
99

1010
ExploreModel(
1111
this.client,
12-
) : _searchActive = false,
13-
_searchQuery = '',
14-
_exploreMode = true,
12+
) : _searchQuery = '',
1513
sectionNameToSnapsMap = {},
1614
_errorMessage = '';
1715

@@ -27,25 +25,6 @@ class ExploreModel extends SafeChangeNotifier {
2725
notifyListeners();
2826
}
2927

30-
bool _searchActive;
31-
bool get searchActive => _searchActive;
32-
set searchActive(bool value) {
33-
if (value == _searchActive) return;
34-
_searchActive = value;
35-
if (_searchActive == false) {
36-
searchQuery = '';
37-
}
38-
notifyListeners();
39-
}
40-
41-
bool _exploreMode;
42-
bool get exploreMode => _exploreMode;
43-
set exploreMode(bool value) {
44-
if (value == _exploreMode) return;
45-
_exploreMode = value;
46-
notifyListeners();
47-
}
48-
4928
String _searchQuery;
5029
String get searchQuery => _searchQuery;
5130
set searchQuery(String value) {
@@ -55,59 +34,53 @@ class ExploreModel extends SafeChangeNotifier {
5534
notifyListeners();
5635
}
5736

58-
Map<SnapSection, bool> get filters => _filters;
59-
final Map<SnapSection, bool> _filters = {
60-
for (final snapSection in SnapSection.values)
61-
snapSection: snapSection == SnapSection.featured ? true : false,
62-
};
63-
64-
List<SnapSection> get sortedFilters =>
65-
_filters.entries
66-
.where((entry) => entry.value == true)
67-
.map((e) => e.key)
68-
.toList() +
69-
_filters.entries
70-
.where((entry) => entry.value == false)
71-
.map((e) => e.key)
72-
.toList();
73-
74-
void setFilter({required List<SnapSection> snapSections}) {
75-
for (var snapSection in snapSections) {
76-
_filters[snapSection] = !_filters[snapSection]!;
77-
loadSection(snapSection.title);
78-
}
37+
SnapSection _selectedSection = SnapSection.all;
38+
SnapSection get selectedSection => _selectedSection;
39+
set selectedSection(SnapSection value) {
40+
if (value == _selectedSection) return;
41+
_selectedSection = value;
7942
}
8043

8144
Future<List<Snap>> findSnapsByQuery() async {
8245
if (searchQuery.isEmpty) {
8346
return [];
8447
} else {
8548
try {
86-
return await client.find(query: _searchQuery);
49+
return await client.find(
50+
query: _searchQuery,
51+
section:
52+
selectedSection == SnapSection.all ? null : selectedSection.title,
53+
);
8754
} on SnapdException catch (e) {
8855
errorMessage = e.message.toString();
8956
return [];
9057
}
9158
}
9259
}
9360

94-
Future<List<Snap>> findSnapsBySection({String? section}) async {
61+
Future<List<Snap>> findSnapsBySection({SnapSection? section}) async {
9562
if (section == null) return [];
9663
try {
97-
return (await client.find(section: section));
64+
return (await client.find(
65+
section: section == SnapSection.all
66+
? SnapSection.featured.title
67+
: section.title,
68+
));
9869
} on SnapdException catch (e) {
9970
errorMessage = e.toString();
10071
return [];
10172
}
10273
}
10374

10475
Map<String, List<Snap>> sectionNameToSnapsMap;
105-
Future<void> loadSection(String name) async {
76+
Future<void> loadSection(SnapSection section) async {
10677
List<Snap> sectionList = [];
107-
for (final snap in await findSnapsBySection(section: name)) {
78+
for (final snap in await findSnapsBySection(
79+
section: section,
80+
)) {
10881
sectionList.add(snap);
10982
}
110-
sectionNameToSnapsMap.putIfAbsent(name, () => sectionList);
83+
sectionNameToSnapsMap.putIfAbsent(section.title, () => sectionList);
11184
notifyListeners();
11285
}
11386
}

Diff for: lib/store_app/explore/explore_page.dart

+31-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:snapd/snapd.dart';
44
import 'package:software/l10n/l10n.dart';
55
import 'package:software/store_app/common/snap_section.dart';
66
import 'package:software/store_app/explore/explore_model.dart';
7-
import 'package:software/store_app/explore/filter_and_search_bar.dart';
7+
import 'package:software/store_app/explore/search_field.dart';
88
import 'package:software/store_app/explore/search_page.dart';
99
import 'package:software/store_app/explore/section_banner_grid.dart';
1010
import 'package:software/store_app/explore/snap_banner_carousel.dart';
@@ -25,36 +25,39 @@ class ExplorePage extends StatelessWidget {
2525

2626
static Widget createTitle(BuildContext context) =>
2727
Text(context.l10n.explorePageTitle);
28+
2829
@override
2930
Widget build(BuildContext context) {
3031
final model = context.watch<ExploreModel>();
31-
if (model.errorMessage.isNotEmpty) return const _ErrorPage();
32-
return Column(
33-
children: [
34-
const FilterAndSearchBar(),
35-
if (model.filters[SnapSection.featured] == true && !model.searchActive)
36-
const Padding(
37-
padding: EdgeInsets.symmetric(horizontal: 20),
38-
child: SnapBannerCarousel(
39-
snapSection: SnapSection.featured,
40-
height: 220,
41-
),
42-
),
43-
if (model.sectionNameToSnapsMap.isNotEmpty && !model.searchActive)
44-
Expanded(
45-
child: YaruPage(
46-
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
47-
children: [
48-
for (int i = 0; i < model.filters.entries.length; i++)
49-
if (model.filters.entries.elementAt(i).value == true)
50-
SectionBannerGrid(
51-
snapSection: model.filters.entries.elementAt(i).key,
52-
),
53-
],
54-
),
55-
),
56-
if (model.searchActive) const Expanded(child: SearchPage())
57-
],
32+
return Scaffold(
33+
appBar: AppBar(
34+
flexibleSpace: const SearchField(),
35+
),
36+
body: Padding(
37+
padding: const EdgeInsets.only(top: 20),
38+
child: Column(
39+
children: [
40+
if ((model.selectedSection == SnapSection.featured ||
41+
model.selectedSection == SnapSection.all) &&
42+
model.searchQuery.isEmpty)
43+
const Padding(
44+
padding: EdgeInsets.symmetric(horizontal: 20),
45+
child: SnapBannerCarousel(
46+
snapSection: SnapSection.featured,
47+
height: 220,
48+
),
49+
),
50+
if (model.searchQuery.isEmpty &&
51+
model.sectionNameToSnapsMap.isNotEmpty)
52+
Expanded(
53+
child: SectionBannerGrid(snapSection: model.selectedSection),
54+
),
55+
if (model.errorMessage.isNotEmpty) const _ErrorPage(),
56+
if (model.searchQuery.isNotEmpty)
57+
const Expanded(child: SearchPage())
58+
],
59+
),
60+
),
5861
);
5962
}
6063
}

Diff for: lib/store_app/explore/filter_and_search_bar.dart

-79
This file was deleted.

0 commit comments

Comments
 (0)