From 7ec032c0f29ae1ebd8851eb089a978157dda1d90 Mon Sep 17 00:00:00 2001 From: juan Date: Mon, 19 May 2025 19:01:48 -0400 Subject: [PATCH] added sender and time to the email tile inside of the thread --- lib/collapsableEmails.dart | 104 +++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/lib/collapsableEmails.dart b/lib/collapsableEmails.dart index 224f097..ceed92a 100644 --- a/lib/collapsableEmails.dart +++ b/lib/collapsableEmails.dart @@ -8,8 +8,12 @@ import 'structs.dart'; class CollapsableEmails extends StatefulWidget { final List thread; // email id's in the form xyz@gmail.com final List threadHTML; + final String threadIDs; - CollapsableEmails({required this.thread, required this.threadHTML}); + CollapsableEmails( + {required this.thread, + required this.threadHTML, + required this.threadIDs}); @override State createState() => _CollapsableEmailsState(); @@ -21,12 +25,15 @@ class _CollapsableEmailsState extends State { Set _expandedEmails = {}; //open emails List viewtypeIDs = []; //IDs of the viewtypes, order matters List heightOfViewTypes = []; //the height of each viewtype + List emailsInThread = []; + bool _isLoaded = false; @override void initState() { // TODO: implement initState super.initState(); _registerViewFactory(widget.threadHTML); + _serializableData(widget.threadIDs); } void _registerViewFactory(List currentContent) async { @@ -70,61 +77,56 @@ class _CollapsableEmailsState extends State { viewtypeIDs.add(viewTypeId); heightOfViewTypes.add(heightOfEmail); } + } - // viewTypeId = 'iframe-${DateTime.now().millisecondsSinceEpoch}'; - // final emailHTML = web.document.createElement('div') as web.HTMLDivElement - // ..id = viewTypeId - // ..innerHTML = currentContent[0].toJS; // temporarily index because it has to do all of them - // emailHTML.style - // ..width = '100%' - // ..height = '100%' - // ..overflow = 'auto' - // ..scrollBehavior = 'smooth'; - - // ui.platformViewRegistry.registerViewFactory( - // viewTypeId, - // (int viewId) => emailHTML, - // ); - // }); + void _serializableData(String threadID) async { + emailsInThread = await ApiService().threadsInSerializable(threadID); + print("done thread serializable"); + if (!mounted) return; + setState(() { + _isLoaded = true; + }); } @override Widget build(BuildContext context) { - return Column(children: [ - Expanded( - child: ListView.builder( - itemCount: widget.thread.length, - itemBuilder: (context, index) { - final isExpanded = - _expandedEmails.contains(index); //check if email is expanded - return Column( - children: [ - ListTile( - title: Text("email $index"), - onTap: () { - setState(() { - if (isExpanded) { - _expandedEmails.remove(index); - } else { - _expandedEmails.add(index); - } - }); - }, - ), - if (isExpanded) - // if(viewtypeIDs[index] == null || heightOfViewTypes[index] == null) - // const SizedBox(height: 100, child: Center(child: CircularProgressIndicator())), - SizedBox( - height:heightOfViewTypes[index].toDouble(), - child: HtmlElementView( - key: UniqueKey(), viewType: viewtypeIDs[index]), + return _isLoaded + ?Column(children: [ + Expanded( + child: ListView.builder( + itemCount: widget.thread.length, + itemBuilder: (context, index) { + final isExpanded = + _expandedEmails.contains(index); //check if email is expanded + return Column( + children: [ + ListTile( + title: Text(emailsInThread[index].from), + trailing: Text(emailsInThread[index].date), + onTap: () { + setState(() { + if (isExpanded) { + _expandedEmails.remove(index); + } else { + _expandedEmails.add(index); + } + }); + }, ), - Divider(), - ], - ); - }, - ), - ) - ]); + if (isExpanded) + // if(viewtypeIDs[index] == null || heightOfViewTypes[index] == null) + // const SizedBox(height: 100, child: Center(child: CircularProgressIndicator())), + SizedBox( + height: heightOfViewTypes[index].toDouble(), + child: HtmlElementView( + key: UniqueKey(), viewType: viewtypeIDs[index]), + ), + Divider(), + ], + ); + }, + ), + ) + ]): const Center(child:CircularProgressIndicator()); } }