filter bangs by categories
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
import 'package:bang_navigator/core/routing/routes.dart';
|
||||
import 'package:bang_navigator/features/bangs/domain/providers.dart';
|
||||
import 'package:bang_navigator/features/bangs/presentation/widgets/bang_details.dart';
|
||||
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||
import 'package:bang_navigator/features/search_browser/domain/entities/sheet.dart';
|
||||
import 'package:bang_navigator/features/search_browser/domain/providers.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class BangScreen extends HookConsumerWidget {
|
||||
const BangScreen({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final bangsAsync = ref.watch(bangDataListProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Bangs'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await context.push(BangSearchRoute().location);
|
||||
},
|
||||
icon: const Icon(Icons.search),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: bangsAsync.when(
|
||||
data: (bangs) {
|
||||
return ListView.builder(
|
||||
itemCount: bangs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final bang = bangs[index];
|
||||
return BangDetails(
|
||||
bang,
|
||||
onTap: () {
|
||||
ref
|
||||
.read(selectedBangTriggerProvider.notifier)
|
||||
.setTrigger(bang.trigger);
|
||||
|
||||
if (ref.read(bottomSheetProvider) is! CreateTab) {
|
||||
ref.read(bottomSheetProvider.notifier).show(
|
||||
CreateTab(
|
||||
preferredTool: KagiTool.search,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
context.go(KagiRoute().location);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => SizedBox.shrink(),
|
||||
loading: () => SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import 'package:bang_navigator/core/routing/routes.dart';
|
||||
import 'package:bang_navigator/features/bangs/domain/providers.dart';
|
||||
import 'package:bang_navigator/presentation/widgets/failure_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class BangCategoriesScreen extends HookConsumerWidget {
|
||||
const BangCategoriesScreen({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final categoriesAsync = ref.watch(bangCategoriesProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Bang Categories'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await context.push(BangSearchRoute().location);
|
||||
},
|
||||
icon: const Icon(Icons.search),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: categoriesAsync.when(
|
||||
data: (categories) {
|
||||
return SingleChildScrollView(
|
||||
child: HookBuilder(
|
||||
builder: (context) {
|
||||
final expanded = useState(<String>{});
|
||||
|
||||
return ExpansionPanelList(
|
||||
expansionCallback: (index, expand) {
|
||||
final key = categories.keys.elementAt(index);
|
||||
if (!expanded.value.contains(key)) {
|
||||
expanded.value = {...expanded.value, key};
|
||||
} else {
|
||||
expanded.value = {...expanded.value}..remove(key);
|
||||
}
|
||||
},
|
||||
children: categories.entries
|
||||
.map(
|
||||
(category) => ExpansionPanel(
|
||||
canTapOnHeader: true,
|
||||
isExpanded: expanded.value.contains(category.key),
|
||||
headerBuilder: (context, isExpanded) => ListTile(
|
||||
title: Text(category.key),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: category.value
|
||||
.map(
|
||||
(subCategory) => ListTile(
|
||||
title: Text(subCategory),
|
||||
onTap: () async {
|
||||
await context.push(
|
||||
BangSubCategoryRoute(
|
||||
category: category.key,
|
||||
subCategory: subCategory,
|
||||
).location,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed to load Bang Categories',
|
||||
exception: error,
|
||||
),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:bang_navigator/core/routing/routes.dart';
|
||||
import 'package:bang_navigator/features/bangs/domain/providers.dart';
|
||||
import 'package:bang_navigator/features/bangs/presentation/widgets/bang_details.dart';
|
||||
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||
import 'package:bang_navigator/features/search_browser/domain/entities/sheet.dart';
|
||||
import 'package:bang_navigator/features/search_browser/domain/providers.dart';
|
||||
import 'package:bang_navigator/presentation/widgets/failure_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class BangListScreen extends HookConsumerWidget {
|
||||
final String? category;
|
||||
final String? subCategory;
|
||||
|
||||
const BangListScreen({this.category, this.subCategory, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final bangsAsync = ref.watch(
|
||||
bangDataListProvider(
|
||||
filter: (
|
||||
categoryFilter: (category != null)
|
||||
? (category: category!, subCategory: subCategory)
|
||||
: null,
|
||||
domain: null,
|
||||
groups: null
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar.medium(
|
||||
title: Text('$category: $subCategory'),
|
||||
),
|
||||
bangsAsync.when(
|
||||
data: (bangs) {
|
||||
return SliverList.builder(
|
||||
itemCount: bangs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final bang = bangs[index];
|
||||
return BangDetails(
|
||||
bang,
|
||||
onTap: () {
|
||||
ref
|
||||
.read(selectedBangTriggerProvider().notifier)
|
||||
.setTrigger(bang.trigger);
|
||||
|
||||
if (ref.read(bottomSheetProvider) is! CreateTab) {
|
||||
ref.read(bottomSheetProvider.notifier).show(
|
||||
CreateTab(
|
||||
preferredTool: KagiTool.search,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
context.go(KagiRoute().location);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed to load Bangs',
|
||||
exception: error,
|
||||
),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user