Tappable label tags

This commit is contained in:
LittleSheep 2024-12-22 17:37:37 +08:00
parent d1eb51c596
commit 594f57e0d3
3 changed files with 35 additions and 5 deletions

View File

@ -77,8 +77,11 @@ final _appRoutes = [
GoRoute( GoRoute(
path: '/search', path: '/search',
name: 'postSearch', name: 'postSearch',
builder: (context, state) => const AppBackground( builder: (context, state) => AppBackground(
child: PostSearchScreen(), child: PostSearchScreen(
initialTags: state.uri.queryParameters['tags']?.split(','),
initialCategories: state.uri.queryParameters['categories']?.split(','),
),
), ),
), ),
GoRoute( GoRoute(

View File

@ -13,7 +13,10 @@ import 'package:surface/widgets/post/post_tags_field.dart';
import 'package:very_good_infinite_list/very_good_infinite_list.dart'; import 'package:very_good_infinite_list/very_good_infinite_list.dart';
class PostSearchScreen extends StatefulWidget { class PostSearchScreen extends StatefulWidget {
const PostSearchScreen({super.key}); final Iterable<String>? initialTags;
final Iterable<String>? initialCategories;
const PostSearchScreen({super.key, this.initialTags, this.initialCategories});
@override @override
State<PostSearchScreen> createState() => _PostSearchScreenState(); State<PostSearchScreen> createState() => _PostSearchScreenState();
@ -31,6 +34,16 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
String _searchTerm = ''; String _searchTerm = '';
Duration? _lastTook; Duration? _lastTook;
@override
void initState() {
super.initState();
_searchTags.addAll(widget.initialTags ?? []);
_searchCategories.addAll(widget.initialCategories ?? []);
if (_searchTags.isNotEmpty || _searchCategories.isNotEmpty) {
_fetchPosts();
}
}
Future<void> _fetchPosts() async { Future<void> _fetchPosts() async {
if (_searchTerm.isEmpty && _searchCategories.isEmpty && _searchTags.isEmpty) return; if (_searchTerm.isEmpty && _searchCategories.isEmpty && _searchTags.isEmpty) return;
if (_postCount != null && _posts.length >= _postCount!) return; if (_postCount != null && _posts.length >= _postCount!) return;

View File

@ -989,7 +989,14 @@ class _PostTagsList extends StatelessWidget {
), ),
], ],
), ),
onTap: () {}, onTap: () {
GoRouter.of(context).pushNamed(
'postSearch',
queryParameters: {
'categories': ele.alias,
},
);
},
), ),
) )
.toList(), .toList(),
@ -1008,7 +1015,14 @@ class _PostTagsList extends StatelessWidget {
Text(ele.alias, style: GoogleFonts.robotoMono()), Text(ele.alias, style: GoogleFonts.robotoMono()),
], ],
), ),
onTap: () {}, onTap: () {
GoRouter.of(context).pushNamed(
'postSearch',
queryParameters: {
'tags': ele.alias,
},
);
},
), ),
) )
.toList(), .toList(),