Add ideas and reminders CRUD flows with navigation
This commit is contained in:
@@ -9,7 +9,7 @@ import 'package:uuid/uuid.dart';
|
||||
class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
static const String _storageKey = 'local_data_state_v1';
|
||||
static const String _schemaVersionKey = 'local_data_schema_version';
|
||||
static const int _schemaVersion = 1;
|
||||
static const int _schemaVersion = 2;
|
||||
|
||||
static const Uuid _uuid = Uuid();
|
||||
|
||||
@@ -42,11 +42,17 @@ class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
required List<String> tags,
|
||||
DateTime? nextMoment,
|
||||
}) async {
|
||||
final String normalizedName = name.trim();
|
||||
final String normalizedRelationship = relationship.trim();
|
||||
if (normalizedName.isEmpty || normalizedRelationship.isEmpty) {
|
||||
throw ArgumentError('Name and relationship are required');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final PersonProfile person = PersonProfile(
|
||||
id: 'p-${_uuid.v4()}',
|
||||
name: name.trim(),
|
||||
relationship: relationship.trim(),
|
||||
name: normalizedName,
|
||||
relationship: normalizedRelationship,
|
||||
affinityScore: 75,
|
||||
nextMoment: nextMoment ?? DateTime.now().add(const Duration(days: 3)),
|
||||
tags: tags,
|
||||
@@ -61,6 +67,10 @@ class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
}
|
||||
|
||||
Future<void> updatePerson(PersonProfile person) async {
|
||||
if (person.name.trim().isEmpty || person.relationship.trim().isEmpty) {
|
||||
throw ArgumentError('Name and relationship are required');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final List<PersonProfile> updated = current.people
|
||||
.map((PersonProfile item) => item.id == person.id ? person : item)
|
||||
@@ -76,8 +86,21 @@ class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
final List<RelationshipMoment> moments = current.moments
|
||||
.where((RelationshipMoment moment) => moment.personId != personId)
|
||||
.toList(growable: false);
|
||||
final List<RelationshipIdea> ideas = current.ideas
|
||||
.where((RelationshipIdea idea) => idea.personId != personId)
|
||||
.toList(growable: false);
|
||||
final List<ReminderRule> reminders = current.reminders
|
||||
.where((ReminderRule reminder) => reminder.personId != personId)
|
||||
.toList(growable: false);
|
||||
|
||||
await _setState(current.copyWith(people: people, moments: moments));
|
||||
await _setState(
|
||||
current.copyWith(
|
||||
people: people,
|
||||
moments: moments,
|
||||
ideas: ideas,
|
||||
reminders: reminders,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> addMoment({
|
||||
@@ -88,15 +111,18 @@ class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
final LocalDataState current = _requireState();
|
||||
final String normalized = summary.trim();
|
||||
if (normalized.isEmpty) {
|
||||
return;
|
||||
throw ArgumentError('Capture summary cannot be empty');
|
||||
}
|
||||
|
||||
final String title = _titleFromSummary(normalized);
|
||||
final String payload = normalized.length > 280
|
||||
? normalized.substring(0, 280)
|
||||
: normalized;
|
||||
final String title = _titleFromSummary(payload);
|
||||
final RelationshipMoment moment = RelationshipMoment(
|
||||
id: 'm-${_uuid.v4()}',
|
||||
personId: personId,
|
||||
title: title,
|
||||
summary: normalized,
|
||||
summary: payload,
|
||||
at: DateTime.now(),
|
||||
type: type,
|
||||
);
|
||||
@@ -108,6 +134,18 @@ class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
await _setState(current.copyWith(moments: moments));
|
||||
}
|
||||
|
||||
Future<void> updateMoment(RelationshipMoment moment) async {
|
||||
if (moment.summary.trim().isEmpty) {
|
||||
throw ArgumentError('Capture summary cannot be empty');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final List<RelationshipMoment> updated = current.moments
|
||||
.map((RelationshipMoment item) => item.id == moment.id ? moment : item)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(moments: updated));
|
||||
}
|
||||
|
||||
Future<void> deleteMoment(String momentId) async {
|
||||
final LocalDataState current = _requireState();
|
||||
final List<RelationshipMoment> moments = current.moments
|
||||
@@ -116,6 +154,126 @@ class LocalRepository extends AsyncNotifier<LocalDataState> {
|
||||
await _setState(current.copyWith(moments: moments));
|
||||
}
|
||||
|
||||
Future<void> addIdea({
|
||||
required IdeaType type,
|
||||
required String title,
|
||||
required String details,
|
||||
String? personId,
|
||||
}) async {
|
||||
final String normalizedTitle = title.trim();
|
||||
if (normalizedTitle.isEmpty) {
|
||||
throw ArgumentError('Idea title is required');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final RelationshipIdea idea = RelationshipIdea(
|
||||
id: 'i-${_uuid.v4()}',
|
||||
personId: personId,
|
||||
type: type,
|
||||
title: normalizedTitle,
|
||||
details: details.trim(),
|
||||
createdAt: DateTime.now(),
|
||||
);
|
||||
|
||||
final List<RelationshipIdea> ideas = <RelationshipIdea>[
|
||||
idea,
|
||||
...current.ideas,
|
||||
];
|
||||
await _setState(current.copyWith(ideas: ideas));
|
||||
}
|
||||
|
||||
Future<void> updateIdea(RelationshipIdea idea) async {
|
||||
if (idea.title.trim().isEmpty) {
|
||||
throw ArgumentError('Idea title is required');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final List<RelationshipIdea> ideas = current.ideas
|
||||
.map((RelationshipIdea item) => item.id == idea.id ? idea : item)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(ideas: ideas));
|
||||
}
|
||||
|
||||
Future<void> toggleIdeaArchived(String ideaId) async {
|
||||
final LocalDataState current = _requireState();
|
||||
final List<RelationshipIdea> ideas = current.ideas
|
||||
.map(
|
||||
(RelationshipIdea item) => item.id == ideaId
|
||||
? item.copyWith(isArchived: !item.isArchived)
|
||||
: item,
|
||||
)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(ideas: ideas));
|
||||
}
|
||||
|
||||
Future<void> deleteIdea(String ideaId) async {
|
||||
final LocalDataState current = _requireState();
|
||||
final List<RelationshipIdea> ideas = current.ideas
|
||||
.where((RelationshipIdea idea) => idea.id != ideaId)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(ideas: ideas));
|
||||
}
|
||||
|
||||
Future<void> addReminder({
|
||||
required String title,
|
||||
required ReminderCadence cadence,
|
||||
required DateTime nextAt,
|
||||
String? personId,
|
||||
}) async {
|
||||
final String normalizedTitle = title.trim();
|
||||
if (normalizedTitle.isEmpty) {
|
||||
throw ArgumentError('Reminder title is required');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final ReminderRule reminder = ReminderRule(
|
||||
id: 'r-${_uuid.v4()}',
|
||||
personId: personId,
|
||||
title: normalizedTitle,
|
||||
cadence: cadence,
|
||||
nextAt: nextAt,
|
||||
enabled: true,
|
||||
);
|
||||
|
||||
final List<ReminderRule> reminders = <ReminderRule>[
|
||||
reminder,
|
||||
...current.reminders,
|
||||
];
|
||||
await _setState(current.copyWith(reminders: reminders));
|
||||
}
|
||||
|
||||
Future<void> updateReminder(ReminderRule reminder) async {
|
||||
if (reminder.title.trim().isEmpty) {
|
||||
throw ArgumentError('Reminder title is required');
|
||||
}
|
||||
|
||||
final LocalDataState current = _requireState();
|
||||
final List<ReminderRule> reminders = current.reminders
|
||||
.map((ReminderRule item) => item.id == reminder.id ? reminder : item)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(reminders: reminders));
|
||||
}
|
||||
|
||||
Future<void> toggleReminderEnabled(String reminderId) async {
|
||||
final LocalDataState current = _requireState();
|
||||
final List<ReminderRule> reminders = current.reminders
|
||||
.map(
|
||||
(ReminderRule item) => item.id == reminderId
|
||||
? item.copyWith(enabled: !item.enabled)
|
||||
: item,
|
||||
)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(reminders: reminders));
|
||||
}
|
||||
|
||||
Future<void> deleteReminder(String reminderId) async {
|
||||
final LocalDataState current = _requireState();
|
||||
final List<ReminderRule> reminders = current.reminders
|
||||
.where((ReminderRule reminder) => reminder.id != reminderId)
|
||||
.toList(growable: false);
|
||||
await _setState(current.copyWith(reminders: reminders));
|
||||
}
|
||||
|
||||
Future<void> toggleTaskDone(String taskId) async {
|
||||
final LocalDataState current = _requireState();
|
||||
final List<DashboardTask> tasks = current.tasks
|
||||
|
||||
Reference in New Issue
Block a user