Ready to implement GitHub search (UI done)

This commit is contained in:
Imran Remtulla
2022-11-12 01:05:16 -05:00
parent 5db2c5f0b1
commit ab57b97875

View File

@@ -223,6 +223,97 @@ class _ImportExportPageState extends State<ImportExportPage> {
child: const Text( child: const Text(
'Import from URL List', 'Import from URL List',
)), )),
...sourceProvider.sources
.where((element) => element.canSearch)
.map((source) => Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 8),
TextButton(
onPressed: importInProgress
? null
: () {
() async {
var values = await showDialog<
List<String>>(
context: context,
builder:
(BuildContext ctx) {
return GeneratedFormModal(
title:
'Search ${source.runtimeType}',
items: [
[
GeneratedFormItem(
label:
'${source.runtimeType} Search Query')
]
],
defaultValues: const [],
);
});
if (values != null &&
values[0].isNotEmpty) {
setState(() {
importInProgress = true;
});
var urls = await source
.search(values[0]);
if (urls.isNotEmpty) {
var selectedUrls =
await showDialog<
List<
String>?>(
context: context,
builder:
(BuildContext
ctx) {
return UrlSelectionModal(
urls: urls);
});
if (selectedUrls !=
null &&
selectedUrls
.isNotEmpty) {
var errors =
await addApps(
selectedUrls);
if (errors.isEmpty) {
// ignore: use_build_context_synchronously
showError(
'Imported ${selectedUrls.length} Apps',
context);
} else {
showDialog(
context: context,
builder:
(BuildContext
ctx) {
return ImportErrorDialog(
urlsLength:
selectedUrls
.length,
errors:
errors);
});
}
}
}
}
}()
.catchError((e) {
showError(e, context);
}).whenComplete(() {
setState(() {
importInProgress = false;
});
});
},
child: Text(
'Search ${source.runtimeType}'))
]))
.toList(),
...sourceProvider.massUrlSources ...sourceProvider.massUrlSources
.map((source) => Column( .map((source) => Column(
crossAxisAlignment: crossAxisAlignment:
@@ -233,84 +324,73 @@ class _ImportExportPageState extends State<ImportExportPage> {
onPressed: importInProgress onPressed: importInProgress
? null ? null
: () { : () {
showDialog( () async {
context: context, var values = await showDialog(
builder: context: context,
(BuildContext ctx) { builder:
return GeneratedFormModal( (BuildContext ctx) {
title: return GeneratedFormModal(
'Import ${source.name}', title:
items: source 'Import ${source.name}',
.requiredArgs items:
.map((e) => [ source
GeneratedFormItem( .requiredArgs
label: e) .map(
]) (e) => [
.toList(), GeneratedFormItem(label: e)
defaultValues: const [], ])
); .toList(),
}).then((values) { defaultValues: const [],
);
});
if (values != null) { if (values != null) {
setState(() { setState(() {
importInProgress = true; importInProgress = true;
}); });
source var urls = await source
.getUrls(values) .getUrls(values);
.then((urls) { var selectedUrls =
showDialog<List<String>?>( await showDialog<
context: context, List<String>?>(
builder: context: context,
(BuildContext builder:
ctx) { (BuildContext
return UrlSelectionModal( ctx) {
urls: urls); return UrlSelectionModal(
}) urls: urls);
.then((selectedUrls) {
if (selectedUrls !=
null) {
addApps(selectedUrls)
.then((errors) {
if (errors
.isEmpty) {
showError(
'Imported ${selectedUrls.length} Apps',
context);
} else {
showDialog(
context:
context,
builder:
(BuildContext
ctx) {
return ImportErrorDialog(
urlsLength:
selectedUrls
.length,
errors:
errors);
});
}
}).whenComplete(() {
setState(() {
importInProgress =
false;
}); });
}); if (selectedUrls != null) {
} else { var errors =
setState(() { await addApps(
importInProgress = selectedUrls);
false; if (errors.isEmpty) {
}); // ignore: use_build_context_synchronously
} showError(
}); 'Imported ${selectedUrls.length} Apps',
}).catchError((e) { context);
setState(() { } else {
importInProgress = showDialog(
false; context: context,
}); builder:
showError(e, context); (BuildContext
}); ctx) {
return ImportErrorDialog(
urlsLength:
selectedUrls
.length,
errors:
errors);
});
}
}
} }
}()
.catchError((e) {
showError(e, context);
}).whenComplete(() {
setState(() {
importInProgress = false;
});
}); });
}, },
child: Text('Import ${source.name}')) child: Text('Import ${source.name}'))