diff --git a/lib/providers/post.dart b/lib/providers/post.dart index 58dae80..c6330f1 100644 --- a/lib/providers/post.dart +++ b/lib/providers/post.dart @@ -118,12 +118,14 @@ class SnPostContentProvider { int take = 10, int offset = 0, Iterable? tags, + Iterable? categories, }) async { final resp = await _sn.client.get('/cgi/co/posts/search', queryParameters: { 'take': take, 'offset': offset, 'probe': searchTerm, if (tags?.isNotEmpty ?? false) 'tags': tags!.join(','), + if (categories?.isNotEmpty ?? false) 'categories': categories!.join(','), }); final List out = await _preloadRelatedDataInBatch( List.from(resp.data['data']?.map((e) => SnPost.fromJson(e)) ?? []), diff --git a/lib/screens/post/post_search.dart b/lib/screens/post/post_search.dart index b517d7d..906c469 100644 --- a/lib/screens/post/post_search.dart +++ b/lib/screens/post/post_search.dart @@ -23,6 +23,7 @@ class _PostSearchScreenState extends State { bool _isBusy = false; List _searchTags = List.empty(growable: true); + List _searchCategories = List.empty(growable: true); final List _posts = List.empty(growable: true); int? _postCount; @@ -31,7 +32,7 @@ class _PostSearchScreenState extends State { Duration? _lastTook; Future _fetchPosts() async { - if (_searchTerm.isEmpty && _searchTags.isEmpty) return; + if (_searchTerm.isEmpty && _searchCategories.isEmpty && _searchTags.isEmpty) return; if (_postCount != null && _posts.length >= _postCount!) return; setState(() => _isBusy = true); @@ -45,6 +46,7 @@ class _PostSearchScreenState extends State { take: 10, offset: _posts.length, tags: _searchTags, + categories: _searchCategories, ); final List out = result.$1; _postCount = result.$2; @@ -73,9 +75,20 @@ class _PostSearchScreenState extends State { setState(() => _searchTags = value); }, ), + const Gap(4), + PostCategoriesField( + labelText: 'fieldPostCategories'.tr(), + initialCategories: _searchCategories, + onUpdate: (value) { + setState(() => _searchCategories = value); + }, + ), ], ).padding(horizontal: 24, vertical: 16), - ); + ).then((_) { + _posts.clear(); + _fetchPosts(); + }); } @override