search with folder filtering (untested ish)
This commit is contained in:
parent
e278643629
commit
5cc6b7eecb
@ -17,6 +17,7 @@ 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 = ['Emails'];
|
List<String> _tabs = ['Emails'];
|
||||||
Map<String, Widget> _tabWidgets = {};
|
Map<String, Widget> _tabWidgets = {};
|
||||||
@ -32,17 +33,61 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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] != 'Emails') {
|
if (_tabs[index] != 'Emails') {
|
||||||
@ -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) {
|
Widget _buildSearchResultsWidget(String query, String? list) {
|
||||||
// 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),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
return FutureBuilder<List<SerializableMessage>>(
|
return FutureBuilder<List<SerializableMessage>>(
|
||||||
future: apiService.sonicSearch("INBOX", 50, 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) {
|
||||||
@ -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),
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user