f655adfbea
Migrate app code into canonical feature slices, add phone-only AI digest scheduling and review, wire local notification/background task support, and cover the flow with tests.
198 lines
6.7 KiB
Dart
198 lines
6.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:relationship_saver/app/data/relationship_repository.dart';
|
|
import 'package:relationship_saver/app/state/local_data_state.dart';
|
|
import 'package:relationship_saver/core/config/app_theme.dart';
|
|
import 'package:relationship_saver/features/ai_digest/domain/ai_digest_models.dart';
|
|
import 'package:relationship_saver/features/people/domain/person_models.dart';
|
|
import 'package:relationship_saver/features/shared/frosted_card.dart';
|
|
|
|
class AiDigestReviewView extends ConsumerWidget {
|
|
const AiDigestReviewView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final AsyncValue<LocalDataState> localData = ref.watch(
|
|
localRepositoryProvider,
|
|
);
|
|
|
|
return Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: AppBar(title: const Text('AI Review Inbox')),
|
|
body: localData.when(
|
|
data: (LocalDataState data) => _AiDigestReviewContent(data: data),
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (Object error, StackTrace stackTrace) =>
|
|
Center(child: Text('Unable to load AI suggestions. $error')),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AiDigestReviewContent extends ConsumerWidget {
|
|
const _AiDigestReviewContent({required this.data});
|
|
|
|
final LocalDataState data;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final List<AiSuggestionDraft> pending = data.aiSuggestionDrafts
|
|
.where(
|
|
(AiSuggestionDraft draft) =>
|
|
draft.status == AiSuggestionStatus.pending,
|
|
)
|
|
.toList(growable: false);
|
|
final Map<String, PersonProfile> peopleById = <String, PersonProfile>{
|
|
for (final PersonProfile person in data.people) person.id: person,
|
|
};
|
|
|
|
return LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
final bool compact = constraints.maxWidth < 760;
|
|
return SingleChildScrollView(
|
|
padding: EdgeInsets.fromLTRB(
|
|
compact ? 16 : 28,
|
|
compact ? 16 : 24,
|
|
compact ? 16 : 28,
|
|
28,
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
'Private suggestions',
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
'Review each suggestion before it changes local data.',
|
|
style: Theme.of(
|
|
context,
|
|
).textTheme.bodyLarge?.copyWith(color: AppTheme.textSecondary),
|
|
),
|
|
const SizedBox(height: 16),
|
|
if (pending.isEmpty)
|
|
const FrostedCard(child: Text('No pending AI suggestions.'))
|
|
else
|
|
...pending.map(
|
|
(AiSuggestionDraft draft) => Padding(
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
child: _AiSuggestionCard(
|
|
draft: draft,
|
|
person: peopleById[draft.personId],
|
|
onAccept: () => ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.acceptAiSuggestionDraft(draft.id),
|
|
onDismiss: () => ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.dismissAiSuggestionDraft(draft.id),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AiSuggestionCard extends StatelessWidget {
|
|
const _AiSuggestionCard({
|
|
required this.draft,
|
|
required this.person,
|
|
required this.onAccept,
|
|
required this.onDismiss,
|
|
});
|
|
|
|
final AiSuggestionDraft draft;
|
|
final PersonProfile? person;
|
|
final VoidCallback onAccept;
|
|
final VoidCallback onDismiss;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FrostedCard(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Icon(_iconForKind(draft.kind), color: AppTheme.primary),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
draft.title,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'${_kindLabel(draft.kind)} · ${person?.name ?? 'Unknown person'}',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: AppTheme.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (draft.details.isNotEmpty) ...<Widget>[
|
|
const SizedBox(height: 12),
|
|
Text(draft.details),
|
|
],
|
|
if (draft.reason != null &&
|
|
draft.reason!.trim().isNotEmpty) ...<Widget>[
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Why: ${draft.reason}',
|
|
style: Theme.of(
|
|
context,
|
|
).textTheme.bodyMedium?.copyWith(color: AppTheme.textSecondary),
|
|
),
|
|
],
|
|
const SizedBox(height: 14),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: <Widget>[
|
|
FilledButton.icon(
|
|
onPressed: person == null ? null : onAccept,
|
|
icon: const Icon(Icons.check_rounded),
|
|
label: const Text('Accept'),
|
|
),
|
|
OutlinedButton.icon(
|
|
onPressed: onDismiss,
|
|
icon: const Icon(Icons.close_rounded),
|
|
label: const Text('Dismiss'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
IconData _iconForKind(AiSuggestionKind kind) {
|
|
return switch (kind) {
|
|
AiSuggestionKind.giftIdea => Icons.card_giftcard_rounded,
|
|
AiSuggestionKind.eventIdea => Icons.event_available_rounded,
|
|
AiSuggestionKind.checkIn => Icons.chat_bubble_outline_rounded,
|
|
AiSuggestionKind.reminder => Icons.notifications_active_outlined,
|
|
};
|
|
}
|
|
|
|
String _kindLabel(AiSuggestionKind kind) {
|
|
return switch (kind) {
|
|
AiSuggestionKind.giftIdea => 'Gift idea',
|
|
AiSuggestionKind.eventIdea => 'Event idea',
|
|
AiSuggestionKind.checkIn => 'Check-in',
|
|
AiSuggestionKind.reminder => 'Reminder',
|
|
};
|
|
}
|
|
}
|