feat(app): show template stage counts
This commit is contained in:
@@ -67,6 +67,7 @@ class TemplatesScreen extends StatefulWidget {
|
||||
class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
late TemplateRepository _repository = TemplateRepository(widget.gateway);
|
||||
List<TemplateEntry> _templates = const [];
|
||||
Map<String, int?> _stageCounts = const {};
|
||||
bool _loading = true;
|
||||
bool _loaded = false;
|
||||
String? _error;
|
||||
@@ -91,6 +92,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
// selection while the replacement is read.
|
||||
_repository = TemplateRepository(widget.gateway);
|
||||
_templates = const [];
|
||||
_stageCounts = const {};
|
||||
_loaded = false;
|
||||
_selectedKey = null;
|
||||
unawaited(_load());
|
||||
@@ -107,8 +109,22 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
try {
|
||||
final templates = await _repository.listTemplates();
|
||||
if (!_owns(generation)) return;
|
||||
final stageCounts = <String, int?>{};
|
||||
for (final entry in templates) {
|
||||
try {
|
||||
final graph = await _repository.validate(entry.source);
|
||||
final stages = graph['stages'];
|
||||
stageCounts[entry.key] = stages is List ? stages.length : null;
|
||||
} catch (_) {
|
||||
// A refusal means the count is unknown, not that the template has
|
||||
// zero stages. The catalogue remains usable, as it does on the web.
|
||||
stageCounts[entry.key] = null;
|
||||
}
|
||||
if (!_owns(generation)) return;
|
||||
}
|
||||
setState(() {
|
||||
_templates = templates;
|
||||
_stageCounts = stageCounts;
|
||||
_loaded = true;
|
||||
_loading = false;
|
||||
final selected = _selectedKey;
|
||||
@@ -164,6 +180,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
final body = selected == null
|
||||
? TemplateGallery(
|
||||
templates: _templates,
|
||||
stageCounts: _stageCounts,
|
||||
loaded: _loaded,
|
||||
loading: _loading,
|
||||
error: _error,
|
||||
|
||||
Reference in New Issue
Block a user