|
@@ -17,8 +17,9 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
ApiService apiService = ApiService();
|
|
ApiService apiService = ApiService();
|
|
bool _isSidebarOpen = true;
|
|
bool _isSidebarOpen = true;
|
|
bool querySearches = false;
|
|
bool querySearches = false;
|
|
|
|
+ String? _selectedOption = "INBOX";
|
|
|
|
|
|
- List<String> _tabs = ['INBOX'];
|
|
|
|
|
|
+ List<String> _tabs = ['Emails'];
|
|
Map<String, Widget> _tabWidgets = {};
|
|
Map<String, Widget> _tabWidgets = {};
|
|
TabController? _tabController;
|
|
TabController? _tabController;
|
|
|
|
|
|
@@ -26,26 +27,70 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
void initState() {
|
|
void initState() {
|
|
super.initState();
|
|
super.initState();
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
- _tabWidgets['INBOX'] = EmailPage(
|
|
|
|
|
|
+ _tabWidgets['Emails'] = EmailPage(
|
|
key: _emailPageKey,
|
|
key: _emailPageKey,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
// Add a new tab based on the search
|
|
// Add a new tab based on the search
|
|
- void _performSearch(String query) {
|
|
|
|
|
|
+ void _performSearch(String query, String? list) {
|
|
setState(() {
|
|
setState(() {
|
|
if (!_tabs.contains(query)) {
|
|
if (!_tabs.contains(query)) {
|
|
_tabs.add(query);
|
|
_tabs.add(query);
|
|
_tabWidgets[query] = _buildSearchResultsWidget(
|
|
_tabWidgets[query] = _buildSearchResultsWidget(
|
|
- query); // Store a different widget for this tab
|
|
|
|
|
|
+ query, list); // Store a different widget for this tab
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void _showOptionsSearchDialog () async {
|
|
|
|
+ List<String> folders = await apiService.fetchFolders();
|
|
|
|
+
|
|
|
|
+ if (mounted) {
|
|
|
|
+ showDialog(
|
|
|
|
+ context: context,
|
|
|
|
+ builder: (BuildContext context) {
|
|
|
|
+ return AlertDialog(
|
|
|
|
+ title: Text('Choose an Option'),
|
|
|
|
+ content: Column(
|
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
|
+ children: folders.map((option) {
|
|
|
|
+ return ListTile(
|
|
|
|
+ title: Text(option),
|
|
|
|
+ leading: Radio<String>(
|
|
|
|
+ value: option,
|
|
|
|
+ groupValue: _selectedOption, // Bind with _selectedOption
|
|
|
|
+ onChanged: (String? value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ _selectedOption = value;
|
|
|
|
+ });
|
|
|
|
+ Navigator.of(context).pop(); // Close the dialog on selection
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ }).toList(),
|
|
|
|
+ ),
|
|
|
|
+ actions: <Widget>[
|
|
|
|
+ ElevatedButton(
|
|
|
|
+ child: Text('Submit'),
|
|
|
|
+ onPressed: () {
|
|
|
|
+ Navigator.of(context).pop(); // Close the dialog
|
|
|
|
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
+ content: Text('You selected: $_selectedOption'),
|
|
|
|
+ ));
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ );}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
// Remove a tab
|
|
// Remove a tab
|
|
void _removeTab(int index) {
|
|
void _removeTab(int index) {
|
|
- if (_tabs[index] != 'INBOX') {
|
|
|
|
|
|
+ if (_tabs[index] != 'Emails') {
|
|
setState(() {
|
|
setState(() {
|
|
String tabToRemove = _tabs[index];
|
|
String tabToRemove = _tabs[index];
|
|
_tabs.removeAt(index);
|
|
_tabs.removeAt(index);
|
|
@@ -57,23 +102,9 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
}
|
|
}
|
|
|
|
|
|
// Build a custom widget for each search query
|
|
// Build a custom widget for each search query
|
|
- Widget _buildSearchResultsWidget(String query) {
|
|
|
|
- // Future<List<SerializableMessage>> result = apiService.sonicSearch("INBOX", 10, 0, query);
|
|
|
|
- // return Center(
|
|
|
|
- // child: Column(
|
|
|
|
- // mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
- // children: [
|
|
|
|
- // // Text("Results for: $query", style: TextStyle(fontSize: 24)),
|
|
|
|
- // // // You can add a list or any custom widget here
|
|
|
|
- // // Text("Here you can display search results or other content."),
|
|
|
|
- // // Text(result[0].messages.toString()),
|
|
|
|
- // Text(query),
|
|
|
|
- // Text(result[0].name),
|
|
|
|
- // ],
|
|
|
|
- // ),
|
|
|
|
- // );
|
|
|
|
|
|
+ Widget _buildSearchResultsWidget(String query, String? list) {
|
|
return FutureBuilder<List<SerializableMessage>>(
|
|
return FutureBuilder<List<SerializableMessage>>(
|
|
- future: apiService.sonicSearch("INBOX", 10, 0, query),
|
|
|
|
|
|
+ future: apiService.sonicSearch(list ?? "INBOX", 50, 0, query),
|
|
builder: (BuildContext context,
|
|
builder: (BuildContext context,
|
|
AsyncSnapshot<List<SerializableMessage>> snapshot) {
|
|
AsyncSnapshot<List<SerializableMessage>> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
@@ -98,11 +129,11 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
),
|
|
),
|
|
trailing: Text(email.date.toString()),
|
|
trailing: Text(email.date.toString()),
|
|
onTap: () async {
|
|
onTap: () async {
|
|
- print('tapped');
|
|
|
|
- String emailContent = await apiService
|
|
|
|
- .fetchEmailContent([email.id]);
|
|
|
|
- print('content below');
|
|
|
|
- print(emailContent);
|
|
|
|
|
|
+ // print('tapped');
|
|
|
|
+ String emailContent =
|
|
|
|
+ await apiService.fetchEmailContent([email.id]);
|
|
|
|
+ // print('content below');
|
|
|
|
+ // print(emailContent);
|
|
Navigator.push(
|
|
Navigator.push(
|
|
context,
|
|
context,
|
|
MaterialPageRoute(
|
|
MaterialPageRoute(
|
|
@@ -234,7 +265,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
),
|
|
),
|
|
onSubmitted: (value) {
|
|
onSubmitted: (value) {
|
|
if (value.isNotEmpty) {
|
|
if (value.isNotEmpty) {
|
|
- _performSearch(value);
|
|
|
|
|
|
+ _performSearch(value, _selectedOption);
|
|
}
|
|
}
|
|
//this is the input box i mentioned
|
|
//this is the input box i mentioned
|
|
// if (value == '') {
|
|
// if (value == '') {
|
|
@@ -252,6 +283,17 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
+ SizedBox(
|
|
|
|
+ width: 16,
|
|
|
|
+ ),
|
|
|
|
+ Container(
|
|
|
|
+ width: 80,
|
|
|
|
+ height: 40,
|
|
|
|
+ child: ElevatedButton(
|
|
|
|
+ onPressed: _showOptionsSearchDialog,
|
|
|
|
+ child: Icon(Icons.manage_search),
|
|
|
|
+ ),
|
|
|
|
+ )
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
@@ -278,7 +320,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
child: Row(
|
|
child: Row(
|
|
children: [
|
|
children: [
|
|
Text(entry.value),
|
|
Text(entry.value),
|
|
- if (entry.value != 'INBOX')
|
|
|
|
|
|
+ if (entry.value != 'Emails')
|
|
GestureDetector(
|
|
GestureDetector(
|
|
onTap: () => _removeTab(entry.key),
|
|
onTap: () => _removeTab(entry.key),
|
|
child: Icon(Icons.close, size: 16),
|
|
child: Icon(Icons.close, size: 16),
|