1
0

4 Achegas 1db462ec8e ... 5cc6b7eecb

Autor SHA1 Mensaxe Data
  juan 5cc6b7eecb search with folder filtering (untested ish) hai 1 mes
  juan e278643629 slight change to show more emails when search hai 1 mes
  juan b19005585d another placeholder to avoid confusion hai 1 mes
  juan 89597b6d2b accidentaly committed some print statements hai 1 mes
Modificáronse 1 ficheiros con 70 adicións e 28 borrados
  1. 70 28
      lib/home_page.dart

+ 70 - 28
lib/home_page.dart

@@ -17,8 +17,9 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
   ApiService apiService = ApiService();
   bool _isSidebarOpen = true;
   bool querySearches = false;
+  String? _selectedOption = "INBOX";
 
-  List<String> _tabs = ['INBOX'];
+  List<String> _tabs = ['Emails'];
   Map<String, Widget> _tabWidgets = {};
   TabController? _tabController;
 
@@ -26,26 +27,70 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
   void initState() {
     super.initState();
     _tabController = TabController(length: _tabs.length, vsync: this);
-    _tabWidgets['INBOX'] = EmailPage(
+    _tabWidgets['Emails'] = EmailPage(
       key: _emailPageKey,
     );
   }
 
   // Add a new tab based on the search
-  void _performSearch(String query) {
+  void _performSearch(String query, String? list) {
     setState(() {
       if (!_tabs.contains(query)) {
         _tabs.add(query);
         _tabWidgets[query] = _buildSearchResultsWidget(
-            query); // Store a different widget for this tab
+            query, list); // Store a different widget for this tab
         _tabController = TabController(length: _tabs.length, vsync: this);
       }
     });
   }
 
+  void _showOptionsSearchDialog () async {
+    List<String> folders = await apiService.fetchFolders();
+
+    if (mounted) {
+    showDialog(
+      context: context,
+      builder: (BuildContext context) {
+        return AlertDialog(
+          title: Text('Choose an Option'),
+          content: Column(
+            mainAxisSize: MainAxisSize.min,
+            children: folders.map((option) {
+              return ListTile(
+                title: Text(option),
+                leading: Radio<String>(
+                  value: option,
+                  groupValue: _selectedOption, // Bind with _selectedOption
+                  onChanged: (String? value) {
+                    setState(() {
+                      _selectedOption = value;
+                    });
+                    Navigator.of(context).pop(); // Close the dialog on selection
+                  },
+                ),
+              );
+            }).toList(),
+          ),
+          actions: <Widget>[
+            ElevatedButton(
+              child: Text('Submit'),
+              onPressed: () {
+                Navigator.of(context).pop(); // Close the dialog
+                ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+                  content: Text('You selected: $_selectedOption'),
+                ));
+              },
+            ),
+          ],
+        );
+      },
+    );}
+  }
+  
+
   // Remove a tab
   void _removeTab(int index) {
-    if (_tabs[index] != 'INBOX') {
+    if (_tabs[index] != 'Emails') {
       setState(() {
         String tabToRemove = _tabs[index];
         _tabs.removeAt(index);
@@ -57,23 +102,9 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
   }
 
   // Build a custom widget for each search query
-  Widget _buildSearchResultsWidget(String query) {
-    // Future<List<SerializableMessage>> result = apiService.sonicSearch("INBOX", 10, 0, query);
-    // return Center(
-    //   child: Column(
-    //     mainAxisAlignment: MainAxisAlignment.center,
-    //     children: [
-    //       // Text("Results for: $query", style: TextStyle(fontSize: 24)),
-    //       // // You can add a list or any custom widget here
-    //       // Text("Here you can display search results or other content."),
-    //       // Text(result[0].messages.toString()),
-    //       Text(query),
-    //       Text(result[0].name),
-    //     ],
-    //   ),
-    // );
+  Widget _buildSearchResultsWidget(String query, String? list) {
     return FutureBuilder<List<SerializableMessage>>(
-      future: apiService.sonicSearch("INBOX", 10, 0, query),
+      future: apiService.sonicSearch(list ?? "INBOX", 50, 0, query),
       builder: (BuildContext context,
           AsyncSnapshot<List<SerializableMessage>> snapshot) {
         if (snapshot.connectionState == ConnectionState.waiting) {
@@ -98,11 +129,11 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
                   ),
                   trailing: Text(email.date.toString()),
                   onTap: () async {
-                    print('tapped');
-                    String emailContent = await apiService
-                        .fetchEmailContent([email.id]);
-                    print('content below');
-                    print(emailContent);
+                    // print('tapped');
+                    String emailContent =
+                        await apiService.fetchEmailContent([email.id]);
+                    // print('content below');
+                    // print(emailContent);
                     Navigator.push(
                       context,
                       MaterialPageRoute(
@@ -234,7 +265,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
                               ),
                               onSubmitted: (value) {
                                 if (value.isNotEmpty) {
-                                  _performSearch(value);
+                                  _performSearch(value, _selectedOption);
                                 }
                                 //this is the input box i mentioned
                                 // if (value == '') {
@@ -252,6 +283,17 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
                               },
                             ),
                           ),
+                          SizedBox(
+                            width: 16,
+                          ),
+                          Container(
+                            width: 80,
+                            height: 40,
+                            child: ElevatedButton(
+                              onPressed: _showOptionsSearchDialog,
+                              child: Icon(Icons.manage_search),
+                            ),
+                          )
                         ],
                       ),
                     ),
@@ -278,7 +320,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
                                   child: Row(
                                     children: [
                                       Text(entry.value),
-                                      if (entry.value != 'INBOX')
+                                      if (entry.value != 'Emails')
                                         GestureDetector(
                                           onTap: () => _removeTab(entry.key),
                                           child: Icon(Icons.close, size: 16),