Compare commits

...

4 Commits

4 changed files with 186 additions and 34 deletions

View File

@ -5,6 +5,8 @@ import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:pointer_interceptor/pointer_interceptor.dart'; import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'collapsableEmails.dart';
import 'structs.dart'; import 'structs.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -111,11 +113,13 @@ class ApiService {
} }
//returns the html for the email, it gets used in emailView //returns the html for the email, it gets used in emailView
Future<String> fetchEmailContent( Future<List<String>> fetchEmailContent(
List<String> IDsString, String emailFolder) async { List<String> IDsString, String emailFolder) async {
String content = r""" String content = r"""
"""; """;
List<String> HTMLofThread = [];
threadAttachments = []; threadAttachments = [];
int counter = 0;
try { try {
//attaches email after email from a thread //attaches email after email from a thread
@ -124,7 +128,9 @@ class ApiService {
var response = await http.get(url); var response = await http.get(url);
currThread.add(id); currThread.add(id);
if (response.statusCode == 200) { if (response.statusCode == 200) {
counter += 1;
content += response.body; content += response.body;
HTMLofThread.add(response.body);
try { try {
List<AttachmentInfo> attachments = List<AttachmentInfo> attachments =
await getAttachmentsInfo(emailFolder, id); await getAttachmentsInfo(emailFolder, id);
@ -138,13 +144,14 @@ class ApiService {
} }
content += content +=
"""<div id="JuanBedarramarker" style="width: 10px; height: 30px;"></div>"""; """<div id="JuanBedarramarker" style="width: 10px; height: 30px;"></div>""";
content += "<hr>"; content += "<hr><p>end of email</p>";
} }
} }
} catch (e) { } catch (e) {
print('_getEmailContent caught error: $e'); print('_getEmailContent caught error: $e');
} }
return content; // return content;
return HTMLofThread;
} }
Future<List<SerializableMessage>> threadsInSerializable( Future<List<SerializableMessage>> threadsInSerializable(
@ -419,13 +426,14 @@ class ApiService {
} }
class EmailView extends StatefulWidget { class EmailView extends StatefulWidget {
final String emailContent; final List<String> emailContent;
final String from; final String from;
final String name; final String name;
final String to; final String to;
final String subject; final String subject;
final String date; final String date;
final String id; final String id;
final List<String> messages;
const EmailView({ const EmailView({
Key? key, Key? key,
@ -436,6 +444,7 @@ class EmailView extends StatefulWidget {
required this.subject, required this.subject,
required this.date, required this.date,
required this.id, required this.id,
required this.messages,
}) : super(key: key); }) : super(key: key);
@override @override
_EmailViewState createState() => _EmailViewState(); _EmailViewState createState() => _EmailViewState();
@ -445,7 +454,7 @@ class _EmailViewState extends State<EmailView> {
//html css rendering thing //html css rendering thing
late Key iframeKey; late Key iframeKey;
late String currentContent; late String currentContent;
late String viewTypeId; late String viewTypeId; //make this a list too???
Future<List<Map<String, dynamic>>>? _markerPositionsFuture; Future<List<Map<String, dynamic>>>? _markerPositionsFuture;
// TextEditingController _jumpController = TextEditingController(); // TextEditingController _jumpController = TextEditingController();
final hardcodedMarkers = [ final hardcodedMarkers = [
@ -458,33 +467,37 @@ class _EmailViewState extends State<EmailView> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
String currentContent = widget List<String> currentContent = widget
.emailContent; //html of the email/ actually entire thread, gives me little space to play in between .emailContent; //html of the email/ actually entire thread, gives me little space to play in between
// i wonder if the other attributes change? because if so i have to add like some zooms in and out of the emails, as in collapse // i wonder if the other attributes change? because if so i have to add like some zooms in and out of the emails, as in collapse
viewTypeId = "iframe-${DateTime.now().millisecondsSinceEpoch}"; // viewTypeId = "iframe-${DateTime.now().millisecondsSinceEpoch}";
_registerViewFactory(currentContent); _registerViewFactory(currentContent);
// _markerPositionsFuture = ApiService().getMarkerPosition(); // _markerPositionsFuture = ApiService().getMarkerPosition();
} }
void _registerViewFactory(String currentContent) { void _registerViewFactory(List<String> currentContent) {
setState(() { setState(() { //update to do item per item
// each item to have itsviewtype ID
// is this necessarey here??
//could just move to collapsable
viewTypeId = 'iframe-${DateTime.now().millisecondsSinceEpoch}'; 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( ui.platformViewRegistry.registerViewFactory(
viewTypeId, viewTypeId,
(int viewId) => web.HTMLDivElement() (int viewId) => emailHTML,
..id = 'new-web' );
..innerHTML = currentContent as js.JSAny);
// DivElement div = HTMLDivElement()
// ..id =
// ui.platformViewRegistry.registerViewFactory(
// viewTypeId,
// (int viewId) => html.IFrameElement()
// ..width = '100%'
// ..height = '100%'
// ..srcdoc = currentContent
// ..style.border = 'none');
}); });
} }
@ -565,13 +578,18 @@ class _EmailViewState extends State<EmailView> {
) )
], ],
), ),
Expanded( Expanded(
child: HtmlElementView( child: CollapsableEmails(
key: UniqueKey(), thread: widget.messages,
viewType: viewTypeId, threadHTML: widget.emailContent,
), ),
), ),
// Expanded(
// child: HtmlElementView(
// key: UniqueKey(),
// viewType: viewTypeId,
// ),
// ),
], ],
), ),

130
lib/collapsableEmails.dart Normal file
View File

@ -0,0 +1,130 @@
import 'dart:js_interop';
import 'package:web/web.dart' as web;
import 'package:flutter/material.dart';
import 'dart:ui_web' as ui;
import 'api_service.dart';
import 'structs.dart';
class CollapsableEmails extends StatefulWidget {
final List<String> thread; // email id's in the form xyz@gmail.com
final List<String> threadHTML;
CollapsableEmails({required this.thread, required this.threadHTML});
@override
State<CollapsableEmails> createState() => _CollapsableEmailsState();
}
class _CollapsableEmailsState extends State<CollapsableEmails> {
List<String> emailsHTML = []; //html of the emails in the thread
// build attachments with the forldar name and id
Set<int> _expandedEmails = {}; //open emails
List viewtypeIDs = []; //IDs of the viewtypes, order matters
List heightOfViewTypes = []; //the height of each viewtype
@override
void initState() {
// TODO: implement initState
super.initState();
_registerViewFactory(widget.threadHTML);
}
void _registerViewFactory(List<String> currentContent) async {
// setState(() { //update to do item per item
// each item to have itsviewtype ID
// is this necessarey here??
//could just move to collapsable
for (var emailHTML in widget.threadHTML) {
String viewTypeId = 'email-${DateTime.now().millisecondsSinceEpoch}';
final ghost = web.document.createElement('div') as web.HTMLDivElement
..style.visibility = 'hidden'
..style.position = 'absolute'
..style.width = '100%'
..style.overflow = 'auto'
..innerHTML = emailHTML
.toJS; // temporarily index because it has to do all of them
web.document.body?.append(ghost);
await Future.delayed(Duration(milliseconds: 10));
final heightOfEmail = ghost.scrollHeight;
ghost.remove();
final HTMLsnippet = web.document.createElement('div')
as web.HTMLDivElement
..id = viewTypeId
..innerHTML = emailHTML
.toJS; // temporarily index because it has to do all of them
HTMLsnippet.style
..width = '100%'
..height = '${heightOfEmail}px'
..overflow = 'auto'
..scrollBehavior = 'smooth';
ui.platformViewRegistry.registerViewFactory(
viewTypeId,
(int viewId) => HTMLsnippet,
);
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,
// );
// });
}
@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]),
),
Divider(),
],
);
},
),
)
]);
}
}

View File

@ -5,7 +5,7 @@ import 'structs.dart';
class EmailListScreen extends StatelessWidget { class EmailListScreen extends StatelessWidget {
final List<GetThreadResponse> emails; final List<GetThreadResponse> emails;
final Future<String> Function(List<String>, String) getEmailContent; final Future<List<String>> Function(List<String>, String) getEmailContent;
final String folder; final String folder;
EmailListScreen( EmailListScreen(
@ -29,11 +29,14 @@ class EmailListScreen extends StatelessWidget {
), ),
trailing: Text(email.date.toString()), trailing: Text(email.date.toString()),
onTap: () async { onTap: () async {
String emailContent = List<String> emailContent = // list of the html
await getEmailContent(email.messages, folder); await getEmailContent(email.messages, folder);
List<String> emailIds = email.messages;
print(email.messages); //email ids of the thread
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute( // could call collapsable and inside collable each calls email view?
builder: (context) => EmailView( builder: (context) => EmailView(
emailContent: emailContent, emailContent: emailContent,
from: email.from_address, from: email.from_address,
@ -42,6 +45,7 @@ class EmailListScreen extends StatelessWidget {
subject: email.subject, subject: email.subject,
date: email.date.toString(), date: email.date.toString(),
id: email.id.toString(), //i think this is thread id? id: email.id.toString(), //i think this is thread id?
messages: email.messages,
), ),
), ),
); );
@ -91,8 +95,6 @@ class EmailPageState extends State<EmailPage> {
_fetchEmails(); _fetchEmails();
} }
// String getPage() => widget.page.toString();
void updatePagenation(String option) { void updatePagenation(String option) {
if (option == "next") { if (option == "next") {
setState(() { setState(() {

View File

@ -77,7 +77,9 @@ class _FolderDrawerState extends State<FolderDrawer> {
title: Text('Refresh Folders'), title: Text('Refresh Folders'),
onTap: () { onTap: () {
_fetchFolders(); // Refresh folders when this tile is tapped _fetchFolders(); // Refresh folders when this tile is tapped
Navigator.pop(context); // Close the drawer after refresh // rebuild
// Navigator.pop(context); // Close the drawer after refresh
}, },
), ),
], ],