From 92458d2e03843a206b25f3618c49f8944c52d6d2 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 25 Oct 2023 20:05:14 +0530 Subject: [PATCH] Create a map of searchType to suggested queries in NoResultWidget --- lib/ui/search_tab.dart | 3 +- .../search/result/no_result_widget.dart | 97 ++++++------------- 2 files changed, 33 insertions(+), 67 deletions(-) diff --git a/lib/ui/search_tab.dart b/lib/ui/search_tab.dart index cfebbd1d7..466162f6b 100644 --- a/lib/ui/search_tab.dart +++ b/lib/ui/search_tab.dart @@ -8,6 +8,8 @@ import "package:photos/ui/viewer/search/search_section.dart"; import "package:photos/ui/viewer/search/search_suggestions.dart"; import "package:photos/ui/viewer/search/search_widget_new.dart"; +late Future>> allSectionsExamples; + class SearchTab extends StatefulWidget { const SearchTab({Key? key}) : super(key: key); @@ -57,7 +59,6 @@ class AllSearchSections extends StatefulWidget { } class _AllSearchSectionsState extends State { - late Future>> allSectionsExamples; late List>> sectionExamples; static const _limit = 7; diff --git a/lib/ui/viewer/search/result/no_result_widget.dart b/lib/ui/viewer/search/result/no_result_widget.dart index c4d027eac..9f7cc0b9d 100644 --- a/lib/ui/viewer/search/result/no_result_widget.dart +++ b/lib/ui/viewer/search/result/no_result_widget.dart @@ -1,74 +1,39 @@ import 'package:flutter/material.dart'; -import 'package:photos/ente_theme_data.dart'; -import "package:photos/generated/l10n.dart"; +import "package:photos/models/search/search_types.dart"; +import "package:photos/ui/search_tab.dart"; -class NoResultWidget extends StatelessWidget { +class NoResultWidget extends StatefulWidget { const NoResultWidget({Key? key}) : super(key: key); + @override + State createState() => _NoResultWidgetState(); +} + +class _NoResultWidgetState extends State { + late final List searchTypes; + final searchTypeToSearchSuggestion = >{}; + @override + void initState() { + super.initState(); + searchTypes = SectionType.values.toList(growable: true); + // remove face and content sectionType + searchTypes.remove(SectionType.face); + searchTypes.remove(SectionType.content); + allSectionsExamples.then((value) { + for (int i = 0; i < searchTypes.length; i++) { + final querySuggestions = []; + for (int j = 0; j < 2 && j < value[i].length; j++) { + querySuggestions.add(value[i][j].name()); + } + //todo: remove keys with empty list + searchTypeToSearchSuggestion + .addAll({searchTypes[i].sectionTitle(context): querySuggestions}); + } + }); + } + @override Widget build(BuildContext context) { - return Container( - width: double.infinity, - margin: const EdgeInsets.only(top: 6), - padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12), - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.searchResultsColor, - borderRadius: BorderRadius.circular(8), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - spreadRadius: -3, - blurRadius: 6, - offset: const Offset(0, 8), - ), - ], - ), - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - margin: const EdgeInsets.only(top: 8), - child: Text( - S.of(context).noResultsFound, - textAlign: TextAlign.left, - style: const TextStyle( - fontSize: 16, - ), - ), - ), - Container( - margin: const EdgeInsets.only(top: 16), - child: Text( - S.of(context).youCanTrySearchingForADifferentQuery, - style: TextStyle( - fontSize: 14, - color: Theme.of(context) - .colorScheme - .defaultTextColor - .withOpacity(0.5), - height: 1.5, - ), - ), - ), - Container( - margin: const EdgeInsets.only(bottom: 20, top: 12), - child: Text( - S.of(context).searchByExamples, - style: TextStyle( - fontSize: 14, - color: Theme.of(context) - .colorScheme - .defaultTextColor - .withOpacity(0.5), - height: 1.5, - ), - ), - ), - ], - ), - ), - ); + return const SizedBox.shrink(); } }