From 254972d2af90445bbf7a2bc6e2453c14f9f8382b Mon Sep 17 00:00:00 2001 From: juan Date: Sat, 21 Sep 2024 01:18:47 -0400 Subject: [PATCH] shorter time to collect threads due to new endpoint, and fixed the view for emails (needs improvement tho) --- lib/api_service.dart | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/api_service.dart b/lib/api_service.dart index e3592e4..1eaca5c 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -124,9 +124,9 @@ class _EmailPageState extends State { setState(() { emails = allEmails; }); - print(emails[0]); + // print(emails[0]); // Print allEmails to debug its structure - print("allEmails: ${allEmails[0].messages}"); + // print("allEmails: ${allEmails[0].messages}"); // Convert allEmails to a list } @@ -188,23 +188,24 @@ class _EmailPageState extends State { // } // } - Future _getEmailContent(String id) async { + Future _getEmailContent(List IDs) async { String content = r""" - """; try { - var url = Uri.http('127.0.0.1:3001', 'email', {'id': id}); + for (var id in IDs) { + var url = Uri.http('127.0.0.1:3001', 'email', {'id': id}); - var response = await http.get(url); + var response = await http.get(url); - if (response.statusCode == 200) { - content = response.body; + if (response.statusCode == 200) { + content += response.body; + } } } catch (e) { print('_getEmailContent caught error: $e'); } - + print(content); return content; } @@ -280,7 +281,7 @@ class EmailListScreen extends StatelessWidget { //this is the bulding of the drawer with all emails // try to only get the subject and id, date, sender to make it faster final List emails; - final Future Function(String) getEmailContent; + final Future Function(List) getEmailContent; EmailListScreen({ required this.emails, @@ -309,7 +310,8 @@ class EmailListScreen extends StatelessWidget { //here we assign each part of json to a var, this could be changed so it only happens, // when clicking on email for modularity onTap: () async { - String emailContent = await getEmailContent(emails[index].id); + String emailContent = + await getEmailContent(emails[index].messages); String messages = emails[index].messages.toString(); String fromName = emails[index].from_name.toString(); String fromAddress = emails[index].from_address.toString();