Compare commits

..

2 Commits

2 changed files with 167 additions and 58 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:markdown/markdown.dart' as md;
import 'api_service.dart';
import 'structs.dart';
import 'emailView.dart';
@ -8,24 +9,28 @@ class EmailListScreen extends StatefulWidget {
final Future<List<String>> Function(List<String>, String) getEmailContent;
final String folder;
final GlobalKey<_EmailListScreenState> key;
final Function(List<GetThreadResponse>)? onSelectionChanged;
EmailListScreen(
{required this.key,
required this.emails,
required this.getEmailContent,
required this.folder})
: super(key: key);
EmailListScreen({
required this.key,
required this.emails,
required this.getEmailContent,
required this.folder,
this.onSelectionChanged,
}) : super(key: key);
@override
_EmailListScreenState createState() => _EmailListScreenState();
}
class _EmailListScreenState extends State<EmailListScreen> {
class _EmailListScreenState extends State<EmailListScreen>
with TickerProviderStateMixin {
late List<bool> selectStates; // for checkboxes if its selected or not
late List<GetThreadResponse> selectedEmails =
[]; // holds the emails that are selected i.e. the emails that got the checkbox on
final Set<int> _hoveredRows = {}; //the row that is being hovered over atm
bool bulkSelectMenu = false;
final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
@override
void initState() {
@ -42,21 +47,57 @@ class _EmailListScreenState extends State<EmailListScreen> {
}
bool selectAllChecks(bool selectionType) {
//perhaps it should return a list of the selected
setState(() {
selectedEmails = [];
if (selectionType) {
bulkSelectMenu = true;
}
for (int email = 0; email < selectStates.length; email++) {
selectStates[email] = selectionType;
for (int email = 0; email < selectStates.length; email++) {
selectStates[email] = selectionType;
selectedEmails.add(widget.emails[email]);
}
} else {
for (int email = 0; email < selectStates.length; email++) {
selectStates[email] = selectionType;
}
selectedEmails = [];
}
});
widget.onSelectionChanged?.call(selectedEmails);
printTheSelected();
return false;
}
bool markAsRead(bool read) {
print("markasread $read");
setState(() {
if (read) {
//read
for (int email = 0; email < selectedEmails.length; email++) {
selectedEmails[email].seen = read;
ApiService()
.markAsSeen(selectedEmails[email].id); //the remote or .json
}
} else {
//unread
for (int email = 0; email < selectedEmails.length; email++) {
selectedEmails[email].seen = read;
ApiService()
.markAsUnseen(selectedEmails[email].id); //the remote or .json
print(selectedEmails[email].subject);
}
}
});
return false;
}
List<GetThreadResponse> listOfSelectedThreads() {
return selectedEmails;
}
void printTheSelected() {
for (int i = 0; i < selectedEmails.length; i++) {
print(selectedEmails);
print(selectedEmails[i].subject);
}
}
@ -83,11 +124,19 @@ class _EmailListScreenState extends State<EmailListScreen> {
setState(() {
//works great
selectStates[index] = value ?? false;
if (value!) {
selectedEmails.add(widget.emails[index]);
} else {
selectedEmails.remove(widget.emails[index]);
}
setState(() {
if (value!) {
selectedEmails.add(widget.emails[index]);
//here i must update the other side
_emailPageKey.currentState?.getListOfSelected();
} else {
selectedEmails.remove(widget.emails[index]);
_emailPageKey.currentState?.getListOfSelected();
}
widget.onSelectionChanged?.call(selectedEmails);
print(selectedEmails);
});
});
},
),
@ -97,7 +146,6 @@ class _EmailListScreenState extends State<EmailListScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [Text(email.subject)],
),
// tileColor: () ,
trailing: _hoveredRows.contains(index)
? Row(
mainAxisSize: MainAxisSize.min,
@ -161,10 +209,12 @@ class _EmailListScreenState extends State<EmailListScreen> {
// ignore: must_be_immutable
class EmailPage extends StatefulWidget {
EmailPage({Key? key}) : super(key: key);
String selectedFolder = "INBOX"; //starter
int offset = 0;
int page = 1;
final Function(List<GetThreadResponse>)? onSelectionChanged;
EmailPage({Key? key, this.onSelectionChanged}) : super(key: key);
@override
EmailPageState createState() => EmailPageState();
@ -239,9 +289,19 @@ class EmailPageState extends State<EmailPage> {
bool selectAllEmails(bool selectionType) {
emailListKey.currentState?.selectAllChecks(selectionType);
return false;
return selectionType;
}
bool markSelectedAsRead(bool selectionType) {
emailListKey.currentState?.markAsRead(selectionType);
return selectionType;
}
List<GetThreadResponse> getListOfSelected() {
return emailListKey.currentState!.listOfSelectedThreads() ?? [];
}
// return [GetThreadResponse(id: 1, messages: [], subject: "subject", date: DateTime(2025), from_name: "from_name", from_address: "from_address", to: [], seen: false)];
@override
Widget build(BuildContext context) {
return Scaffold(
@ -251,6 +311,7 @@ class EmailPageState extends State<EmailPage> {
// getEmailContent: apiService.fetchEmailContent,
getEmailContent: apiService.fetchMarkdownContent,
folder: widget.selectedFolder, //try to grab from it directly
onSelectionChanged: widget.onSelectionChanged,
));
}
}

View File

@ -29,6 +29,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
];
bool _checkboxState = false;
bool bulkOptionsState = false;
List<GetThreadResponse> selectedThreads =
[]; //this should store the emails that are being stored downstream too
List<String> _tabs = ['Emails'];
Map<String, Widget> _tabWidgets = {};
@ -40,6 +42,11 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
_tabController = TabController(length: _tabs.length, vsync: this);
_tabWidgets['Emails'] = EmailPage(
key: _emailPageKey,
onSelectionChanged: (updatedList) {
setState(() {
selectedThreads = updatedList;
});
},
);
}
@ -354,24 +361,45 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
Icons.arrow_drop_down_outlined),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
child: Text("All")),
const PopupMenuItem<String>(
child: Text("None")),
const PopupMenuItem<String>(
child: Text("Read")),
const PopupMenuItem<String>(
child: Text("Unread")),
const PopupMenuItem<String>(
PopupMenuItem<String>(
//select all
child: Text("All"),
onTap: () {
_emailPageKey.currentState!
.selectAllEmails(true);
},
),
PopupMenuItem<String>(
child: Text("None"),
onTap: () {
_emailPageKey.currentState!
.selectAllEmails(false);
},
),
PopupMenuItem<String>(
child: Text("Read"),
onTap: () {
//select the read
},
),
PopupMenuItem<String>(
//select the unread
child: Text("Unread"),
onTap: () {
//select the unread
},
),
PopupMenuItem<String>(
child: Text("Starred")),
const PopupMenuItem<String>(
PopupMenuItem<String>(
child: Text("Unstarred")),
],
onSelected: (String result) {
print("result $result");
},
),
if (bulkOptionsState) ...<Widget>[
if (selectedThreads.isNotEmpty) ...<Widget>[
//this needs to know if anything got selected,
IconButton(
onPressed: null,
icon: Icon(Icons.archive_outlined)),
@ -379,7 +407,11 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
onPressed: null,
icon: Icon(Icons.delete_outlined)),
IconButton(
onPressed: null,
onPressed: () {
_emailPageKey.currentState!
.markSelectedAsRead(
true); //mark as read
},
icon: Icon(
Icons.mark_email_read_outlined)),
IconButton(
@ -390,9 +422,10 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
itemBuilder: (BuildContext context) {
if (!bulkOptionsState) {
if (selectedThreads.isEmpty) {
//why tf?
return <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
PopupMenuItem<String>(
child: Row(
children: [
Icon(Icons
@ -403,19 +436,28 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
Text("Mark all as read")
],
),
onTap: () {
_emailPageKey.currentState!
.selectAllEmails(true);
_emailPageKey.currentState!
.markSelectedAsRead(true);
_emailPageKey.currentState!
.selectAllEmails(false);
},
),
const PopupMenuDivider(),
PopupMenuItem(
child: Text(
"Select messages to see more actions",
style: TextStyle(
color: Colors
.blueGrey.shade300),
))
child: Text(
"Select messages to see more actions",
style: TextStyle(
color: Colors
.blueGrey.shade300),
),
)
];
} else {
return <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
PopupMenuItem<String>(
child: Row(
children: [
Icon(Icons
@ -426,28 +468,34 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
Text("Mark as unread")
],
),
onTap: () {
_emailPageKey.currentState!
.markSelectedAsRead(
false);
},
),
const PopupMenuItem<String>(
child: Row(
children: [
Icon(Icons.snooze_outlined),
const SizedBox(
width: 4.0,
),
Text("Snooze")
],
),
child: Row(
children: [
Icon(Icons.snooze_outlined),
const SizedBox(
width: 4.0,
),
Text("Snooze")
],
),
),
const PopupMenuItem<String>(
child: Row(
children: [
Icon(Icons.star_border_outlined),
const SizedBox(
width: 4.0,
),
Text("Add star")
],
),
child: Row(
children: [
Icon(Icons
.star_border_outlined),
const SizedBox(
width: 4.0,
),
Text("Add star")
],
),
),
];
}