Explorar el Código

get the email view when on search

juan hace 1 mes
padre
commit
1db462ec8e
Se han modificado 3 ficheros con 75 adiciones y 69 borrados
  1. 2 2
      lib/api_service.dart
  2. 4 2
      lib/email.dart
  3. 69 65
      lib/home_page.dart

+ 2 - 2
lib/api_service.dart

@@ -15,7 +15,7 @@ class ApiService {
     try {
       var url = Uri.http('127.0.0.1:3001', 'sorted_threads_by_date', {
         'folder': folder,
-        'limit': '20',
+        'limit': '50',
         'offset': pagenitaion.toString(),
       });
       var response = await http.get(url);
@@ -90,7 +90,7 @@ class ApiService {
         // -            messagesJson.map((mj) => SerializableMessage.fromJson(mj)).toList();
         // print("above mess");
         
-        print(messages[0].uid);
+        // print(messages[0].uid);
         return messages;
       }
     } catch (e) {

+ 4 - 2
lib/email.dart

@@ -84,12 +84,12 @@ class EmailPageState extends State<EmailPage> {
   void updatePagenation(String option) {
     if (option == "next") {
       setState(() {
-        widget.offset += 20;
+        widget.offset += 50;
         widget.page += 1;
       });
     } else if (option == "back") {
       setState(() {
-        widget.offset -= 20;
+        widget.offset -= 50;
         widget.page -= 1;
       });
     }
@@ -102,6 +102,8 @@ class EmailPageState extends State<EmailPage> {
     try {
       List<GetThreadResponse> fetchedEmails = await apiService
           .fetchEmailsFromFolder(widget.selectedFolder, widget.offset);
+      if (!mounted) return;
+
       setState(() {
         emails = fetchedEmails; // Update the list of emails
       });

+ 69 - 65
lib/home_page.dart

@@ -36,7 +36,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
     setState(() {
       if (!_tabs.contains(query)) {
         _tabs.add(query);
-        _tabWidgets[query] = _buildSearchResultsWidget(query); // Store a different widget for this tab
+        _tabWidgets[query] = _buildSearchResultsWidget(
+            query); // Store a different widget for this tab
         _tabController = TabController(length: _tabs.length, vsync: this);
       }
     });
@@ -72,76 +73,80 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
     //   ),
     // );
     return FutureBuilder<List<SerializableMessage>>(
-    future: apiService.sonicSearch("INBOX", 10, 0, query),
-    builder: (BuildContext context, AsyncSnapshot<List<SerializableMessage>> snapshot) {
-      if (snapshot.connectionState == ConnectionState.waiting) {
-        return Center(child: CircularProgressIndicator());
-      } else if (snapshot.hasError) {
-        return Center(child: Text('Error: ${snapshot.error}'));
-      } else if (!snapshot.hasData || snapshot.data!.isEmpty) {
-        return Center(child: Text('No results found for: $query'));
-      } else {
-        List<SerializableMessage> result = snapshot.data!;
-        return Scaffold(
-          body: ListView.separated(
-            itemCount: result.length,
-            itemBuilder: (context, index){
-              final email = result[index];
-              return ListTile(
-              title: Text(email.from,
-                  style: TextStyle(fontWeight: FontWeight.bold)),
-              subtitle: Column(
-                crossAxisAlignment: CrossAxisAlignment.start,
-                children: [Text(email.subject)],
-              ),
-              trailing: Text(email.date.toString()),
-              onTap: () async {
-                String emailContent = await apiService.fetchEmailContent(email.id as List<String>);
-                Navigator.push(
-                  context,
-                  MaterialPageRoute(
-                    builder: (context) => EmailView(
-                      emailContent: emailContent,
-                      from: email.from,
-                      name: email.name,
-                      to: email.to.toString(),
-                      subject: email.subject,
-                      date: email.date.toString(),
-                      id: email.id.toString(),
-                    ),
+      future: apiService.sonicSearch("INBOX", 10, 0, query),
+      builder: (BuildContext context,
+          AsyncSnapshot<List<SerializableMessage>> snapshot) {
+        if (snapshot.connectionState == ConnectionState.waiting) {
+          return Center(child: CircularProgressIndicator());
+        } else if (snapshot.hasError) {
+          return Center(child: Text('Error: ${snapshot.error}'));
+        } else if (!snapshot.hasData || snapshot.data!.isEmpty) {
+          return Center(child: Text('No results found for: $query'));
+        } else {
+          List<SerializableMessage> result = snapshot.data!;
+          return Scaffold(
+            body: ListView.separated(
+              itemCount: result.length,
+              itemBuilder: (context, index) {
+                final email = result[index];
+                return ListTile(
+                  title: Text(email.from,
+                      style: TextStyle(fontWeight: FontWeight.bold)),
+                  subtitle: Column(
+                    crossAxisAlignment: CrossAxisAlignment.start,
+                    children: [Text(email.subject)],
                   ),
+                  trailing: Text(email.date.toString()),
+                  onTap: () async {
+                    print('tapped');
+                    String emailContent = await apiService
+                        .fetchEmailContent([email.id]);
+                    print('content below');
+                    print(emailContent);
+                    Navigator.push(
+                      context,
+                      MaterialPageRoute(
+                        builder: (context) => EmailView(
+                          emailContent: emailContent,
+                          from: email.from,
+                          name: email.name,
+                          to: email.to.toString(),
+                          subject: email.subject,
+                          date: email.date.toString(),
+                          id: email.id.toString(),
+                        ),
+                      ),
+                    );
+                  },
                 );
               },
-              );
-            },
               separatorBuilder: (context, index) => Divider(),
             ),
-          // child: Column(
-          //   mainAxisAlignment: MainAxisAlignment.center,
-          //   children: [
-          //     Text("Results for: $query", style: TextStyle(fontSize: 24)),
-          //     // Display the actual data
-          //     Text(result[0].name), // Accessing the first result safely
-          //     Text(result[0].from), // Displaying the 'from' field as an example
-          //     Text(result[0].hash),
-          //     Text(result[0].subject),
-          //     Text(result[0].uid.toString()),
-          //     Text(result[0].list),
-          //     Text(result[0].id),
-              
-              
-          //     // Add more fields or customize the display
-          //     // SerializableEmailListScreen(emails: result, getEmailContent: getEmailContent)
-          //     // Expanded(
+            // child: Column(
+            //   mainAxisAlignment: MainAxisAlignment.center,
+            //   children: [
+            //     Text("Results for: $query", style: TextStyle(fontSize: 24)),
+            //     // Display the actual data
+            //     Text(result[0].name), // Accessing the first result safely
+            //     Text(result[0].from), // Displaying the 'from' field as an example
+            //     Text(result[0].hash),
+            //     Text(result[0].subject),
+            //     Text(result[0].uid.toString()),
+            //     Text(result[0].list),
+            //     Text(result[0].id),
 
-          //     //   child: 
-          //     // ),
+            //     // Add more fields or customize the display
+            //     // SerializableEmailListScreen(emails: result, getEmailContent: getEmailContent)
+            //     // Expanded(
+
+            //     //   child:
+            //     // ),
             // ],
           );
-        // );
-      }
-    },
-  );
+          // );
+        }
+      },
+    );
   }
 
   @override
@@ -160,7 +165,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
           _emailPageKey.currentState?.updateSelectedFolder(folder);
         },
       ),
-
       body: Stack(
         children: [
           Row(
@@ -316,7 +320,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
                         controller: _tabController,
                         children: _tabs.map((tab) {
                           return _tabWidgets[tab] ??
-                            Center(child: Text("No content found"));
+                              Center(child: Text("No content found"));
                           // return Center(
                           //     child: EmailPage(
                           //   key: _emailPageKey,