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 'package:pointer_interceptor/pointer_interceptor.dart';
import 'collapsableEmails.dart';
import 'structs.dart';
import 'package:flutter/material.dart';
@ -111,11 +113,13 @@ class ApiService {
}
//returns the html for the email, it gets used in emailView
Future<String> fetchEmailContent(
Future<List<String>> fetchEmailContent(
List<String> IDsString, String emailFolder) async {
String content = r"""
""";
List<String> HTMLofThread = [];
threadAttachments = [];
int counter = 0;
try {
//attaches email after email from a thread
@ -124,7 +128,9 @@ class ApiService {
var response = await http.get(url);
currThread.add(id);
if (response.statusCode == 200) {
counter += 1;
content += response.body;
HTMLofThread.add(response.body);
try {
List<AttachmentInfo> attachments =
await getAttachmentsInfo(emailFolder, id);
@ -138,13 +144,14 @@ class ApiService {
}
content +=
"""<div id="JuanBedarramarker" style="width: 10px; height: 30px;"></div>""";
content += "<hr>";
content += "<hr><p>end of email</p>";
}
}
} catch (e) {
print('_getEmailContent caught error: $e');
}
return content;
// return content;
return HTMLofThread;
}
Future<List<SerializableMessage>> threadsInSerializable(
@ -419,13 +426,14 @@ class ApiService {
}
class EmailView extends StatefulWidget {
final String emailContent;
final List<String> emailContent;
final String from;
final String name;
final String to;
final String subject;
final String date;
final String id;
final List<String> messages;
const EmailView({
Key? key,
@ -436,6 +444,7 @@ class EmailView extends StatefulWidget {
required this.subject,
required this.date,
required this.id,
required this.messages,
}) : super(key: key);
@override
_EmailViewState createState() => _EmailViewState();
@ -445,7 +454,7 @@ class _EmailViewState extends State<EmailView> {
//html css rendering thing
late Key iframeKey;
late String currentContent;
late String viewTypeId;
late String viewTypeId; //make this a list too???
Future<List<Map<String, dynamic>>>? _markerPositionsFuture;
// TextEditingController _jumpController = TextEditingController();
final hardcodedMarkers = [
@ -458,33 +467,37 @@ class _EmailViewState extends State<EmailView> {
@override
void 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
// 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);
// _markerPositionsFuture = ApiService().getMarkerPosition();
}
void _registerViewFactory(String currentContent) {
setState(() {
void _registerViewFactory(List<String> currentContent) {
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}';
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) => web.HTMLDivElement()
..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');
(int viewId) => emailHTML,
);
});
}
@ -565,13 +578,18 @@ class _EmailViewState extends State<EmailView> {
)
],
),
Expanded(
child: HtmlElementView(
key: UniqueKey(),
viewType: viewTypeId,
child: CollapsableEmails(
thread: widget.messages,
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 {
final List<GetThreadResponse> emails;
final Future<String> Function(List<String>, String) getEmailContent;
final Future<List<String>> Function(List<String>, String) getEmailContent;
final String folder;
EmailListScreen(
@ -29,11 +29,14 @@ class EmailListScreen extends StatelessWidget {
),
trailing: Text(email.date.toString()),
onTap: () async {
String emailContent =
List<String> emailContent = // list of the html
await getEmailContent(email.messages, folder);
List<String> emailIds = email.messages;
print(email.messages); //email ids of the thread
Navigator.push(
context,
MaterialPageRoute(
MaterialPageRoute( // could call collapsable and inside collable each calls email view?
builder: (context) => EmailView(
emailContent: emailContent,
from: email.from_address,
@ -42,6 +45,7 @@ class EmailListScreen extends StatelessWidget {
subject: email.subject,
date: email.date.toString(),
id: email.id.toString(), //i think this is thread id?
messages: email.messages,
),
),
);
@ -91,8 +95,6 @@ class EmailPageState extends State<EmailPage> {
_fetchEmails();
}
// String getPage() => widget.page.toString();
void updatePagenation(String option) {
if (option == "next") {
setState(() {

View File

@ -77,7 +77,9 @@ class _FolderDrawerState extends State<FolderDrawer> {
title: Text('Refresh Folders'),
onTap: () {
_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
},
),
],