diff --git a/frontend/lib/pages/list.dart b/frontend/lib/pages/list.dart index 6706c7b..b0e99a4 100644 --- a/frontend/lib/pages/list.dart +++ b/frontend/lib/pages/list.dart @@ -119,6 +119,9 @@ class ListPage extends StatelessWidget { children: [ TextField( autofocus: true, + decoration: InputDecoration( + label: Text(Strings.quote) + ), controller: bodyController, ), TextField( @@ -218,19 +221,21 @@ class ListPage extends StatelessWidget { Expanded( child: TextField( controller: provider.filterController, + onChanged: (_) => provider.filterQuotes(), decoration: InputDecoration( - label: Text(Strings.filterQuery), + label: Text( + '${Strings.filterQuery} – ${Strings.byAttribute} ${(provider.filterBy == 0) ? Strings.author : Strings.quote}' + ), suffixIcon: IconButton( icon: Icon(Icons.cancel), - onPressed: provider.clearFilterController - ) + onPressed: () { + provider.clearFilterController(); + provider.filterQuotes(); + }, + ), ), ), ), - IconButton( - icon: Icon(Icons.search), - onPressed: provider.filterQuotes, - ), IconButton( icon: Icon(Icons.more_horiz), onPressed: () { @@ -246,23 +251,83 @@ class ListPage extends StatelessWidget { showModalBottomSheet( context: context, builder: (context) { - return SizedBox( - height: 300, - child: ListView( - padding: const EdgeInsets.all(Constants.edgeInset), - children: [ - ListTile( - title: Text(Strings.filterBy), - trailing: Icon(Icons.filter_alt), - ), - ListTile( - title: Text(Strings.exportSelectedQuotes), - trailing: Icon(Icons.import_export), - ), - ], - ) + return Padding( + padding: const EdgeInsets.all(Constants.edgeInset), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + title: Text(Strings.filterBy), + trailing: Icon(Icons.filter_alt), + onTap: () { + _showFilterOptionsBottomSheet(context, provider); + }, + ), + ListTile( + title: Text(Strings.exportSelectedQuotes), + trailing: Icon(Icons.import_export), + onTap: () { + // TODO: trigger an os dialog FileSave + }, + ), + ], + ), ); }, ); } + + void _showFilterOptionsBottomSheet( + BuildContext context, + QuoteProvider provider, + ) { + showModalBottomSheet( + context: context, + builder: (context) { + return Padding( + padding: const EdgeInsets.all(Constants.edgeInset), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + title: const Text(Strings.author), + leading: Radio( + value: 0, + groupValue: provider.filterBy, + onChanged: (value) { + if (value != null) { + provider.setFilterBy(value); + Navigator.pop(context); + } + }, + ), + onTap: () { + provider.setFilterBy(0); + Navigator.pop(context); + }, + ), + + ListTile( + title: const Text(Strings.quote), + leading: Radio( + value: 1, + groupValue: provider.filterBy, + onChanged: (value) { + if (value != null) { + provider.setFilterBy(value); + Navigator.pop(context); + } + }, + ), + onTap: () { + provider.setFilterBy(1); + Navigator.pop(context); + }, + ), + ], + ), + ); + }, + ); + } } \ No newline at end of file diff --git a/frontend/lib/provider/quote_provider.dart b/frontend/lib/provider/quote_provider.dart index c2cac4b..a21cee0 100644 --- a/frontend/lib/provider/quote_provider.dart +++ b/frontend/lib/provider/quote_provider.dart @@ -7,7 +7,6 @@ import 'package:frontend/repository/quote_repository.dart'; class QuoteProvider extends ChangeNotifier { List _quotes = []; - List _filteredQuotes = []; Set _authors = {}; bool _loading = false; String? _error; @@ -40,6 +39,10 @@ class QuoteProvider extends ChangeNotifier { filterController.text = ''; } + void filterQuotes() { + notifyListeners(); + } + QuoteProvider() { readQuotes(); // auto-load on creation } @@ -51,7 +54,8 @@ class QuoteProvider extends ChangeNotifier { } } - void filterQuotes() { + void setFilterBy(int value) { + filterBy = value; notifyListeners(); } @@ -62,7 +66,6 @@ class QuoteProvider extends ChangeNotifier { try { _quotes = await repo.readQuotes(); - _filteredQuotes = _quotes; } catch (e) { _error = e.toString(); } diff --git a/frontend/lib/values/strings.dart b/frontend/lib/values/strings.dart index d80dba4..306cd05 100644 --- a/frontend/lib/values/strings.dart +++ b/frontend/lib/values/strings.dart @@ -24,4 +24,5 @@ class Strings { static const String allQuotesCount = "Celkový počet hlášek"; static const String filterBy = "Filtrovat podle"; static const String exportSelectedQuotes = "Exportovat vybrané hlášky"; + static const String byAttribute = "podle příznaku"; } \ No newline at end of file