140 lines
3.9 KiB
Dart
140 lines
3.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
|
|
import 'package:pipelines_app/features/attention/ui/needs_you_bell.dart';
|
|
|
|
/// Browser capture entrypoint for the reusable `Needs you` bell and sheet.
|
|
///
|
|
/// The fixture owns the entries and records the callbacks in plain text, so a
|
|
/// browser drive can prove the bell label, both native sheets, the empty state
|
|
/// and that a dismissal/clear names a real identity. Nothing here opens a
|
|
/// socket, reads storage or asks for notification permission.
|
|
const _longDetail =
|
|
'Stage 3 stopped at the export archive step because the credential it '
|
|
'needs is no longer configured on this server.';
|
|
|
|
List<AttentionEntry> _entries() => [
|
|
attentionEntryFor({
|
|
'id': 7,
|
|
'name': 'release',
|
|
'title': 'Approve the release candidate',
|
|
'status': 'waiting',
|
|
'created_at': '2026-10-21T09:00:00Z',
|
|
'finished_at': '',
|
|
})!,
|
|
attentionEntryFor({
|
|
'id': 8,
|
|
'name': 'nightly-audit',
|
|
'title': 'Nightly audit with a label long enough to wrap at 320 logical px',
|
|
'status': 'failed',
|
|
'diagnostic': _longDetail,
|
|
'created_at': '2026-10-21T08:00:00Z',
|
|
'finished_at': '2026-10-21T08:30:00Z',
|
|
})!,
|
|
];
|
|
|
|
void main() {
|
|
final params = Uri.base.queryParameters;
|
|
final cupertino = params['host'] == 'cupertino';
|
|
final scale = double.tryParse(params['scale'] ?? '') ?? 1;
|
|
final empty = params['mode'] == 'empty';
|
|
final brightness = params['theme'] == 'light'
|
|
? Brightness.light
|
|
: Brightness.dark;
|
|
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
|
|
child: app!,
|
|
);
|
|
final home = _ProbeHome(
|
|
cupertino: cupertino,
|
|
entries: empty ? const [] : _entries(),
|
|
);
|
|
if (cupertino) {
|
|
runApp(
|
|
CupertinoApp(
|
|
theme: CupertinoThemeData(brightness: brightness),
|
|
builder: scaled,
|
|
home: home,
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
runApp(
|
|
MaterialApp(
|
|
theme: ThemeData(
|
|
platform: TargetPlatform.android,
|
|
brightness: brightness,
|
|
),
|
|
builder: scaled,
|
|
home: home,
|
|
),
|
|
);
|
|
}
|
|
|
|
class _ProbeHome extends StatefulWidget {
|
|
const _ProbeHome({required this.cupertino, required this.entries});
|
|
|
|
final bool cupertino;
|
|
final List<AttentionEntry> entries;
|
|
|
|
@override
|
|
State<_ProbeHome> createState() => _ProbeHomeState();
|
|
}
|
|
|
|
class _ProbeHomeState extends State<_ProbeHome> {
|
|
late List<AttentionEntry> _entries = [...widget.entries];
|
|
String _event = 'Nothing raised yet';
|
|
|
|
void _open(AttentionEntry entry) {
|
|
setState(() => _event = 'Opened ${entry.key}');
|
|
}
|
|
|
|
void _dismiss(AttentionEntry entry) {
|
|
setState(() {
|
|
_entries = _entries.where((item) => item.key != entry.key).toList();
|
|
_event = 'Dismissed ${entry.key}';
|
|
});
|
|
}
|
|
|
|
void _clearAll(List<AttentionEntry> snapshot) {
|
|
final keys = snapshot.map((entry) => entry.key).toSet();
|
|
setState(() {
|
|
_entries = _entries.where((entry) => !keys.contains(entry.key)).toList();
|
|
_event = 'Cleared ${keys.length} of the open snapshot';
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bell = NeedsYouBell(
|
|
entries: _entries,
|
|
cupertino: widget.cupertino,
|
|
onOpen: _open,
|
|
onDismiss: _dismiss,
|
|
onClearAll: _clearAll,
|
|
);
|
|
final body = ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Text(_event),
|
|
const SizedBox(height: 12),
|
|
Text('${_entries.length} needing attention now'),
|
|
],
|
|
);
|
|
if (widget.cupertino) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: const Text('Runs'),
|
|
trailing: bell,
|
|
),
|
|
child: SafeArea(child: body),
|
|
);
|
|
}
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Runs'), actions: [bell]),
|
|
body: SafeArea(child: body),
|
|
);
|
|
}
|
|
}
|