Переглянути джерело

added tabs for navigating between the current folder, and wtv search the user does (needs to implement yet api, along with dynamicism)

juan 1 місяць тому
батько
коміт
9210990b7b
2 змінених файлів з 139 додано та 5 видалено
  1. 18 1
      lib/api_service.dart
  2. 121 4
      lib/home_page.dart

+ 18 - 1
lib/api_service.dart

@@ -67,6 +67,24 @@ class ApiService {
     }
   }
 
+  Future<List<String>> sonicSearch(
+      String list, int limit, int offset, String query) async {
+    try {
+      var url = Uri.http('127.0.0.1:3001', 'search',
+          {'list': list, 'limit': limit.toString(), 'offset': offset.toString(), 'query': query});
+      var response = await http.get(url);
+
+      if (response.statusCode == 200) {
+        List<String> matches = List<String>.from(json.decode(response.body));
+        print(matches);
+        return matches;
+      }
+    } catch (e) {
+      print(e);
+    }
+    return [];
+  }
+
   Future<String> fetchEmailContent(List<String> IDs) async {
     String content = r"""
     """;
@@ -128,7 +146,6 @@ class ApiService {
     }
   }
 
-
   Future<void> deleteFolder(String folderName) async {
     var url = Uri.http('127.0.0.1:3001', 'delete_folder');
 

+ 121 - 4
lib/home_page.dart

@@ -9,16 +9,43 @@ class HomeScreen extends StatefulWidget {
   _HomeScreenState createState() => _HomeScreenState();
 }
 
-class _HomeScreenState extends State<HomeScreen> {
+class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
   final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
   final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
   ApiService apiService = ApiService();
   bool _isSidebarOpen = true;
+  bool querySearches = false;
+
+  List<String> _tabs = ['INBOX', 'Search'];
+  TabController? _tabController;
 
   @override
   void initState() {
     super.initState();
+    _tabController = TabController(length: _tabs.length, vsync: this);
   }
+   // Add a new tab based on the search
+  void _performSearch(String query) {
+    setState(() {
+      _tabs.add(query);
+      _tabController = TabController(length: _tabs.length, vsync: this);
+    });
+  }
+
+  // Remove a tab
+  void _removeTab(int index) {
+    setState(() {
+      _tabs.removeAt(index);
+      _tabController = TabController(length: _tabs.length, vsync: this);
+    });
+  }
+
+  @override
+  void dispose() {
+    _tabController?.dispose();
+    super.dispose();
+  }
+
 
   @override
   Widget build(BuildContext context) {
@@ -30,6 +57,31 @@ class _HomeScreenState extends State<HomeScreen> {
           _emailPageKey.currentState?.updateSelectedFolder(folder);
         },
       ),
+      // appBar: AppBar(
+      //   title: Text('Search with Tabs'),
+      //   bottom: _tabs.isNotEmpty
+      //       ? TabBar(
+      //           controller: _tabController,
+      //           isScrollable: true,
+      //           tabs: _tabs
+      //               .asMap()
+      //               .entries
+      //               .map((entry) => Tab(
+      //                     child: Row(
+      //                       children: [
+      //                         Text(entry.value),
+      //                         SizedBox(width: 8),
+      //                         GestureDetector(
+      //                           onTap: () => _removeTab(entry.key),
+      //                           child: Icon(Icons.close, size: 16),
+      //                         ),
+      //                       ],
+      //                     ),
+      //                   ))
+      //               .toList(),
+      //         )
+      //       : null,
+      // ),
       body: Stack(
         children: [
           Row(
@@ -97,6 +149,25 @@ class _HomeScreenState extends State<HomeScreen> {
                                 border: OutlineInputBorder(),
                                 prefixIcon: Icon(Icons.search),
                               ),
+                              onSubmitted: (value) {
+                                if (value.isNotEmpty) {
+                                  _performSearch(value);
+                                }
+                                //this is the input box i mentioned
+                                // if (value == '') {
+                                //   setState(() {
+                                //     querySearches = false;
+                                //   });
+                                // }
+                                // Future<List<String>> results = apiService
+                                //     .sonicSearch('INBOX', 20, 0, value);
+                                // // print(value);
+                                // print(results);
+                                // setState(() {
+                                //   querySearches = true;
+                                // });
+
+                              },
                             ),
                           ),
                         ],
@@ -113,6 +184,31 @@ class _HomeScreenState extends State<HomeScreen> {
                         ],
                       ),
                     ),
+                    Container(
+                      color: Color.fromARGB(255, 131, 110, 143),
+                      child: TabBar(
+                        controller: _tabController,
+                        isScrollable: true,
+                        tabs: _tabs
+                            .asMap()
+                            .entries
+                            .map((entry) => Tab(
+                                  child: Row(
+                                    children: [
+                                      Text(entry.value),
+                                      if (entry.value != 'INBOX')
+                                        GestureDetector(
+                                          onTap: () => _removeTab(entry.key),
+                                          child: Icon(Icons.close, size: 16),
+                                        ),
+                                    ],
+                                  ),
+                                ))
+                            .toList(),
+                        labelColor: Colors.white,
+                        indicatorColor: Colors.white,
+                      ),
+                    ),
                     Container(
                       // alignment: Alignment.topLeft,
                       padding: EdgeInsets.all(8.0),
@@ -134,12 +230,33 @@ class _HomeScreenState extends State<HomeScreen> {
                             },
                             child: Icon(Icons.navigate_next),
                           ),
+                          
                         ],
                       ),
                     ),
                     Expanded(
-                      child: EmailPage(key: _emailPageKey),
-                    )
+                      child: TabBarView(
+                        controller: _tabController,
+                        children: _tabs.map((tab) {
+                          return Center(child: EmailPage(key: _emailPageKey,));
+                        }).toList(),
+                      ),
+                    ),
+                    
+                    // if (_tabs.isEmpty)
+                    //   Expanded(
+                    //     child: EmailPage(key: _emailPageKey),
+                    //   ),
+                    // if (_tabs.isNotEmpty)
+                    //   Expanded(
+                    //     // child: Text('supposed to be mails'),
+                    //     child: TabBarView(
+                    //       controller: _tabController,
+                    //       children: _tabs
+                    //           .map((tab) => Center(child: Text('Results for $tab')))
+                    //           .toList(),
+                    //     ),
+                    //   ),
                   ],
                 ),
               ),
@@ -162,7 +279,7 @@ class _HomeScreenState extends State<HomeScreen> {
       ),
     );
   }
-
+}
 //   void _showPopupMenu(BuildContext context, Offset position) async {
 //     final RenderBox overlay =
 //         Overlay.of(context).context.findRenderObject() as RenderBox;