create folder
This commit is contained in:
		
							parent
							
								
									336f7e8788
								
							
						
					
					
						commit
						55de9ea8b9
					
				
					 2 changed files with 74 additions and 2 deletions
				
			
		| 
						 | 
					@ -9,9 +9,7 @@ import 'dart:ui_web' as ui;
 | 
				
			||||||
import 'augment.dart';
 | 
					import 'augment.dart';
 | 
				
			||||||
import 'dart:html' as html;
 | 
					import 'dart:html' as html;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
class ApiService {
 | 
					class ApiService {
 | 
				
			||||||
 | 
					 | 
				
			||||||
  Future<List<GetThreadResponse>> fetchEmailsFromFolder(
 | 
					  Future<List<GetThreadResponse>> fetchEmailsFromFolder(
 | 
				
			||||||
      String folder, int pagenitaion) async {
 | 
					      String folder, int pagenitaion) async {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
| 
						 | 
					@ -106,6 +104,29 @@ class ApiService {
 | 
				
			||||||
      return [];
 | 
					      return [];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Future<void> createFolder(String folderName) async {
 | 
				
			||||||
 | 
					    var url = Uri.http('127.0.0.1:3001', 'create_folder');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Map<String, String> requestBody = {'name': folderName};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      var response = await http.post(
 | 
				
			||||||
 | 
					        url,
 | 
				
			||||||
 | 
					        headers: {
 | 
				
			||||||
 | 
					          'Content-Type': 'application/json',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        body: jsonEncode(requestBody),
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      if (response.statusCode == 200) {
 | 
				
			||||||
 | 
					        print('response body: ${response.body}');
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        print('Error: ${response.statusCode}, response body: ${response.body}');
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
					      print('error making post req: $e');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EmailView extends StatefulWidget {
 | 
					class EmailView extends StatefulWidget {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
//drawer with the folders for emails a.k.a mailboxes
 | 
					//drawer with the folders for emails a.k.a mailboxes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					import 'package:flutter/services.dart';
 | 
				
			||||||
import 'api_service.dart';
 | 
					import 'api_service.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FolderDrawer extends StatefulWidget {
 | 
					class FolderDrawer extends StatefulWidget {
 | 
				
			||||||
| 
						 | 
					@ -50,6 +51,19 @@ class _FolderDrawerState extends State<FolderDrawer> {
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
          }).toList(),
 | 
					          }).toList(),
 | 
				
			||||||
 | 
					          ListTile(
 | 
				
			||||||
 | 
					            leading: Icon(Icons.add),
 | 
				
			||||||
 | 
					            title: Text("New Mailbox"),
 | 
				
			||||||
 | 
					            onTap: () {
 | 
				
			||||||
 | 
					              showDialog(
 | 
				
			||||||
 | 
					                context: context,
 | 
				
			||||||
 | 
					                builder: (BuildContext context) {
 | 
				
			||||||
 | 
					                  return NewMailbox(apiService:  widget.apiService);
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              );
 | 
				
			||||||
 | 
					              // Navigator.of(context).pop();
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
          ListTile(
 | 
					          ListTile(
 | 
				
			||||||
            leading: Icon(Icons.refresh),
 | 
					            leading: Icon(Icons.refresh),
 | 
				
			||||||
            title: Text('Refresh Folders'),
 | 
					            title: Text('Refresh Folders'),
 | 
				
			||||||
| 
						 | 
					@ -63,3 +77,40 @@ class _FolderDrawerState extends State<FolderDrawer> {
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NewMailbox extends StatelessWidget {
 | 
				
			||||||
 | 
					  final ApiService apiService;
 | 
				
			||||||
 | 
					  // final Function(String) onFolderCreated;
 | 
				
			||||||
 | 
					  final TextEditingController _textFieldController = TextEditingController();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  NewMailbox({required this.apiService});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  Widget build(BuildContext context) {
 | 
				
			||||||
 | 
					    return AlertDialog(
 | 
				
			||||||
 | 
					      title: const Text("Create a new Mailbox"),
 | 
				
			||||||
 | 
					      content: TextField(
 | 
				
			||||||
 | 
					        controller: _textFieldController,
 | 
				
			||||||
 | 
					        decoration: const InputDecoration(
 | 
				
			||||||
 | 
					          hintText: "EPIC FOLDER", // Your custom hint text here
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					      actions: <Widget>[
 | 
				
			||||||
 | 
					        TextButton(
 | 
				
			||||||
 | 
					          onPressed: () {
 | 
				
			||||||
 | 
					            print("Folder name: ${_textFieldController.text}");
 | 
				
			||||||
 | 
					            String folderName = _textFieldController.text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (folderName.isNotEmpty) {
 | 
				
			||||||
 | 
					              apiService.createFolder(folderName);
 | 
				
			||||||
 | 
					              // onFolderCreated(folderName);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            // apiService.createFolder(_textFieldController.text);
 | 
				
			||||||
 | 
					            Navigator.of(context).pop();
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          child: const Text("Approve"),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue