Browse Source

fixed issues regarding <script> tags being repeated

juan 3 months ago
parent
commit
8baf399608
3 changed files with 75 additions and 418 deletions
  1. 74 106
      lib/api_service.dart
  2. 1 0
      lib/augment.dart
  3. 0 312
      lib/home_page.dart

+ 74 - 106
lib/api_service.dart

@@ -3,6 +3,8 @@ import 'package:http/http.dart' as http;
 import 'dart:convert';
 import 'dart:ui_web' as ui;
 import 'dart:html' as html;
+import 'augment.dart';
+import 'dart:js' as js;
 
 class MailAddress {
   final String? name;
@@ -108,7 +110,6 @@ class _EmailPageState extends State<EmailPage> {
         List<dynamic> json = jsonDecode(response.body);
         for (var item in json) {
           if (item.length > 1 && item[0] is String && item[1] is List) {
-            //  print('Date: ${item[0]}, Threads: ${item[1]}');
             List<int> threadIDs = List<int>.from(item[1]);
             for (var threadId in threadIDs) {
               await fetchThreadMessages(threadId, allEmails);
@@ -125,7 +126,6 @@ class _EmailPageState extends State<EmailPage> {
       emails.clear();
       // emails = messagesMap.values.toList().expand((list) => list).toList();
       emails.addAll(allEmails);
-      // print(emails);
       ;
     });
   }
@@ -135,9 +135,9 @@ class _EmailPageState extends State<EmailPage> {
     try {
       var url = Uri.http(
           '127.0.0.1:3001', 'get_thread_messages', {'id': threadId.toString()});
-      // print(url);
+
       var response = await http.get(url);
-      // print(response.body);
+
       if (response.statusCode == 200) {
         List<dynamic> messagesJson = jsonDecode(response.body);
         List<SerializableMessage> messages =
@@ -156,59 +156,22 @@ class _EmailPageState extends State<EmailPage> {
     String content = r"""
 
     """;
-    // String restcontent = "";
+
     try {
       var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
-      // print(url);
+
       var response = await http.get(url);
-      // print(response.body);
+
       if (response.statusCode == 200) {
-        print('ok');
         content = response.body;
-        // try {
-        //   var restUrl =
-        //       Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': id});
-        //   // print(restUrl);
-        //   var restresponse = await http.get(restUrl);
-        //   // print(restresponse.statusCode);
-        //   if (restresponse.statusCode == 200) {
-        //     print("ok squared");
-        //     // restcontent = restresponse.body;
-        //   }
-        // } catch (i) {
-        //   print('jsoncontent caught error: $i');
-        // }
       }
     } catch (e) {
       print('_getEmailContent caught error: $e');
     }
-    // print(content);
-    // print(restcontent);
+
     return content;
   }
 
-  // Future<String> _getThreadMessagesJson(String threadId) async {
-  //   String jsonResponse = "";
-
-  //   try {
-  //     var url =
-  //         Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': threadId});
-  //     // print(url);
-  //     var response = await http.get(url);
-  //     // print(response.statusCode);
-  //     // print(response.body);
-  //     if (response.statusCode == 200) {
-  //       jsonResponse = response.body; // Here you get the JSON response
-  //     } else {
-  //       throw Exception('Failed to load thread messages');
-  //     }
-  //   } catch (e) {
-  //     print('_getThreadMessagesJson caught error: $e');
-  //   }
-
-  //   return jsonResponse; // Returns the JSON string
-  // }
-
   Future<List<Widget>> _getDrawerItems() async {
     List<String> drawerItems = [];
 
@@ -280,17 +243,14 @@ class _EmailPageState extends State<EmailPage> {
 class EmailListScreen extends StatelessWidget {
   final List emails;
   final Future<String> Function(String) getEmailContent;
-  // final Future<String> Function(String) getJsonEmail;
 
   EmailListScreen({
     required this.emails,
     required this.getEmailContent,
-    // required this.getJsonEmail
   });
 
   @override
   Widget build(BuildContext context) {
-    // print(emails);
     return Scaffold(
       appBar: AppBar(
         title: Text('Emails'),
@@ -310,9 +270,6 @@ class EmailListScreen extends StatelessWidget {
               trailing: Text(emails[index].date.toString()),
               onTap: () async {
                 String emailContent = await getEmailContent(emails[index].id);
-                // String jsonContent =
-                //     await getJsonEmail(emails[index].uid.toString());
-                // print(emails[index]);
                 String from = emails[index].from.toString();
                 String name = emails[index].name.toString();
                 String to = emails[index].to.toString();
@@ -388,6 +345,7 @@ class _EmailViewState extends State<EmailView> {
   @override
   void initState() {
     super.initState();
+    print(widget.id);
     iframeKey = Key("iframe-${widget.id}");
     ui.platformViewRegistry.registerViewFactory(
       // 'html-view33'
@@ -397,67 +355,77 @@ class _EmailViewState extends State<EmailView> {
         ..height = '100%'
         ..srcdoc = widget.emailContent
         ..style.border = 'none',
+        // ..style.width = '100%',
+        // ..style.height = '100%'
     );
   }
 
   @override
   Widget build(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(
-        title: Text(widget.name),
-      ),
-      body: Column( 
-        children: [
-          // Container(
-          //   color: Colors.amber,
-          //   child: Text(
-          //     widget.from ,),
-          // ),
-          Row(
-            // title of email
-            children: [
-                Text(
-                widget.subject,
-                style: TextStyle(fontSize: 30),
-                ),
-            ],
-          ),
-          Row(
-            children: [
-              Text(
-                'from ${widget.name}',
-                style: TextStyle(fontSize: 18),
-              ),
-              Text(
-                '<${widget.from}>',
-                style: TextStyle(fontSize: 18),
-              ),
-              Spacer(),
-              Text(
-                '${widget.date}',
-                textAlign: TextAlign.right,
-              )
-            ],
-          ),
-          // TODO: make a case where if one of these is the user's email it just says me :)))))
-          Row(
-            children: [
-              Text(
-                'to ${widget.to.toString()}',
-                style: TextStyle(fontSize: 15),
-              )
-            ],
-          ),
+    void _handleNumbering() {
+      // Check if the iframe content window is accessible
+      try {
+        js.context.callMethod('applyNumberingVisibility');
+      } catch (e) {
+        print('Error accessing iframe method: $e');
+        // Optionally, use postMessage for cross-origin communication
+        // js.context['iframeElement'].contentWindow.postMessage(jsify({'action': 'toggleNumbering'}), '*');
+      }
+    }
 
-          Expanded(
-            child: HtmlElementView(
-              key: iframeKey,
-              viewType: iframeKey.toString(), 
-        // 'html-view33',
+
+
+    return Scaffold(
+        appBar: AppBar(
+          title: Text(widget.name),
+        ),
+        body: Column(
+          children: [
+            EmailToolbar(onButtonPressed: _handleNumbering),
+            Row(
+              // title of email
+              children: [
+                Text(
+                  widget.subject,
+                  style: TextStyle(fontSize: 30),
+                ),
+              ],
             ),
-          )
-        ],
-      )
-    );
+            Row(
+              children: [
+                Text(
+                  'from ${widget.name}',
+                  style: TextStyle(fontSize: 18),
+                ),
+                Text(
+                  '<${widget.from}>',
+                  style: TextStyle(fontSize: 18),
+                ),
+                Spacer(),
+                Text(
+                  '${widget.date}',
+                  textAlign: TextAlign.right,
+                )
+              ],
+            ),
+            // TODO: make a case where if one of these is the user's email it just says me :)))))
+            Row(
+              children: [
+                Text(
+                  'to ${widget.to.toString()}',
+                  style: TextStyle(fontSize: 15),
+                )
+              ],
+            ),
+
+            Expanded(
+              child: HtmlElementView(
+                key: iframeKey,
+                viewType: iframeKey.toString(),
+                // 'html-view33',
+              ),
+            ),
+          ],
+        ));
   }
 }

+ 1 - 0
lib/augment.dart

@@ -3,6 +3,7 @@ import 'package:http/http.dart' as http;
 import 'dart:convert';
 import 'dart:ui_web' as ui;
 import 'dart:html' as html;
+import 'dart:js' as js;
 
 class EmailToolbar extends StatelessWidget {
   final VoidCallback onButtonPressed;

File diff suppressed because it is too large
+ 0 - 312
lib/home_page.dart


Some files were not shown because too many files changed in this diff