Prechádzať zdrojové kódy

cleaned, and new endpoint

juan 2 mesiacov pred
rodič
commit
aaaacade4d
4 zmenil súbory, kde vykonal 24 pridanie a 40 odobranie
  1. 17 18
      lib/api_service.dart
  2. 0 6
      lib/augment.dart
  3. 7 4
      lib/main.dart
  4. 0 12
      lib/structs.dart

+ 17 - 18
lib/api_service.dart

@@ -1,12 +1,10 @@
 import 'package:crab_ui/structs.dart';
-import 'package:english_words/english_words.dart';
 import 'package:flutter/material.dart';
 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;
+import 'dart:html' as html;
 
 //data structure
 class MailAddress {
@@ -28,17 +26,15 @@ class MailAddress {
   }
 }
 
-
-
 class EmailPage extends StatefulWidget {
   const EmailPage({super.key});
   final String title = 'Emails';
 
   @override
-  State<EmailPage> createState() => _EmailPageState();
+  State<EmailPage> createState() => EmailPageState();
 }
 
-class _EmailPageState extends State<EmailPage> {
+class EmailPageState extends State<EmailPage> {
   List emails = [];
 
   void _displayEmailsFromFolder(String folder) async {
@@ -46,9 +42,12 @@ class _EmailPageState extends State<EmailPage> {
 
     try {
       var url = Uri.http(
-          '127.0.0.1:3001', 'sorted_threads_by_date', {'folder': folder});
+          '127.0.0.1:3001', 'sorted_threads_by_date', 
+          {'folder': folder,
+           'limit': '10',
+           'offset': '0'});
       var response = await http.get(url);
-
+      print(response);
       if (response.statusCode == 200) {
         List json = jsonDecode(response.body);
         for (var item in json.take(1)) {
@@ -74,16 +73,15 @@ class _EmailPageState extends State<EmailPage> {
   }
 
   Future<void> fetchThreads(
-      int threadId,
-      List<GetThreadResponse> allEmails) async {
+      int threadId, List<GetThreadResponse> allEmails) async {
     try {
       var url =
           Uri.http('127.0.0.1:3001', 'get_thread', {'id': threadId.toString()});
       var response = await http.get(url);
-      
+
       if (response.statusCode == 200) {
         Map<String, dynamic> messagesJson = jsonDecode(response.body);
-            GetThreadResponse threadResponse =
+        GetThreadResponse threadResponse =
             GetThreadResponse.fromJson(messagesJson);
 
         allEmails.add(threadResponse);
@@ -101,6 +99,7 @@ class _EmailPageState extends State<EmailPage> {
     """;
 
     try {
+      //attaches email after email from a thread
       for (var id in IDs) {
         var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
 
@@ -108,6 +107,7 @@ class _EmailPageState extends State<EmailPage> {
 
         if (response.statusCode == 200) {
           content += response.body;
+          content += "<p>new shit</p><br><br><br>";
         }
       }
     } catch (e) {
@@ -116,7 +116,7 @@ class _EmailPageState extends State<EmailPage> {
     return content;
   }
 
-  Future<List<Widget>> _getDrawerItems() async {
+  Future<List<Widget>> getDrawerItems(BuildContext context) async {
     List<String> drawerItems = [];
 
     try {
@@ -124,7 +124,7 @@ class _EmailPageState extends State<EmailPage> {
       var response = await http.get(url);
       drawerItems = List<String>.from(json.decode(response.body));
     } catch (e) {
-      print('_getDrawerItems caught error: $e');
+      print('getDrawerItems caught error: $e');
     }
 
     List<Widget> drawerWidgets = [];
@@ -155,7 +155,7 @@ class _EmailPageState extends State<EmailPage> {
       drawer: Drawer(
         child: FutureBuilder<List<Widget>>(
           future:
-              _getDrawerItems(), // call the async function to get the future
+              getDrawerItems(context), // call the async function to get the future
           builder:
               (BuildContext context, AsyncSnapshot<List<Widget>> snapshot) {
             if (snapshot.connectionState == ConnectionState.waiting) {
@@ -237,8 +237,7 @@ class EmailListScreen extends StatelessWidget {
                             subject: subject,
                             date: date,
                             id: id,
-                          )
-                      ),
+                          )),
                 );
               });
         },

+ 0 - 6
lib/augment.dart

@@ -1,12 +1,6 @@
-import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter/widgets.dart';
-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;
-import 'api_service.dart';
 
 class EmailToolbar extends StatefulWidget {
   final Function(String) onJumpToSpan;

+ 7 - 4
lib/main.dart

@@ -1,18 +1,18 @@
 import 'package:crab_ui/contact.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter/rendering.dart';
 import 'home_page.dart';
 import 'api_service.dart';
-import 'dart:html' as html;
+import 'login.dart';
 
 void main() {
   WidgetsFlutterBinding.ensureInitialized();
   // debugPaintSizeEnabled = true;
-  runApp(const HyM());
+  runApp( HyM());
 }
 
 class HyM extends StatelessWidget {
-  const HyM({super.key});
+  final AuthService _authService = AuthService();
+  HyM({super.key});
 
   @override
   Widget build(BuildContext context) {
@@ -20,8 +20,11 @@ class HyM extends StatelessWidget {
       debugShowCheckedModeBanner: false,
       theme: ThemeData.light(),
       title: 'HyM',
+      // home: HomeScreen(),
       home: HomeScreen(),
+
       routes: {
+        "/login": (context) => const LoginPage(),
         "/email": (context) => EmailPage(),
         "/contacts": (context) => ContactsPage(),
       },

+ 0 - 12
lib/structs.dart

@@ -1,13 +1,4 @@
-import 'package:flutter/material.dart';
-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;
 import 'api_service.dart';
-import 'dart:convert';  // For JSON decoding
-import 'package:intl/intl.dart'; 
 
 
 class GetThreadResponse {
@@ -29,13 +20,10 @@ class GetThreadResponse {
     required this.to,
   });
   factory GetThreadResponse.fromJson(Map<String, dynamic> json) {
-    var messagesList = json['messages'] as List<dynamic>;
     var toList = json['to'] as List<dynamic>;
-    // var ccList = json['cc'] as List;
 
     return GetThreadResponse (
       id: json['id'],
-      // messages: messagesList.map((message) => message.toString()).toList(),
       messages: List<String>.from(json['messages']),
       subject: json['subject'],
       date: DateTime.parse(json['date']),