Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 81 additions & 15 deletions app/lib/desktop/pages/memories/widgets/desktop_memory_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class _DesktopMemoryDialogState extends State<DesktopMemoryDialog> {
late TextEditingController _textController;
late MemoryVisibility _selectedVisibility;
late MemoryCategory _selectedCategory;
bool _isSaving = false;
bool _saveFailed = false;

@override
void initState() {
Expand Down Expand Up @@ -187,7 +189,42 @@ class _DesktopMemoryDialogState extends State<DesktopMemoryDialog> {
],
),

const SizedBox(height: 32),
const SizedBox(height: 24),

// Error message
if (_saveFailed) ...[
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.red.withOpacity(0.3),
width: 1,
),
),
child: Row(
children: [
Icon(
Icons.error_outline,
color: Colors.red.shade400,
size: 18,
),
const SizedBox(width: 8),
const Expanded(
child: Text(
'Failed to save. Please check your connection.',
style: TextStyle(
color: ResponsiveHelper.textSecondary,
fontSize: 13,
),
),
),
],
),
),
const SizedBox(height: 16),
],

// Actions
Row(
Expand Down Expand Up @@ -217,8 +254,12 @@ class _DesktopMemoryDialogState extends State<DesktopMemoryDialog> {
),
const SizedBox(width: 12),
OmiButton(
label: widget.memory != null ? 'Save Changes' : 'Create Memory',
onPressed: _saveMemory,
label: _isSaving
? 'Saving...'
: _saveFailed
? 'Retry'
: (widget.memory != null ? 'Save Changes' : 'Create Memory'),
onPressed: _isSaving ? null : _saveMemory,
),
],
),
Expand All @@ -228,24 +269,49 @@ class _DesktopMemoryDialogState extends State<DesktopMemoryDialog> {
);
}

void _saveMemory() {
Future<void> _saveMemory() async {
final content = _textController.text.trim();
if (content.isEmpty) return;

if (widget.memory != null) {
// Edit existing memory
widget.provider.editMemory(widget.memory!, content);
if (widget.memory!.visibility != _selectedVisibility) {
widget.provider.updateMemoryVisibility(widget.memory!, _selectedVisibility);
setState(() {
_isSaving = true;
_saveFailed = false;
});

bool success;

try {
if (widget.memory != null) {
// Edit existing memory
success = await widget.provider.editMemory(widget.memory!, content);
if (success && widget.memory!.visibility != _selectedVisibility) {
await widget.provider.updateMemoryVisibility(widget.memory!, _selectedVisibility);
}
if (success) {
MixpanelManager().memoriesPageEditedMemory();
}
} else {
// Create new memory
success = await widget.provider.createMemory(content, _selectedVisibility, _selectedCategory);
if (success) {
MixpanelManager().memoriesPageCreatedMemory(_selectedCategory);
}
}
MixpanelManager().memoriesPageEditedMemory();
} else {
// Create new memory
widget.provider.createMemory(content, _selectedVisibility, _selectedCategory);
MixpanelManager().memoriesPageCreatedMemory(_selectedCategory);
} catch (e) {
success = false;
debugPrint('Error saving memory: $e');
}

Navigator.pop(context);
if (!mounted) return;

setState(() {
_isSaving = false;
_saveFailed = !success;
});

if (success) {
Navigator.pop(context);
}
Comment thread
beastoin marked this conversation as resolved.
}

void _showDeleteConfirmation() {
Expand Down
98 changes: 77 additions & 21 deletions app/lib/pages/memories/widgets/memory_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MemoryDialog extends StatefulWidget {

class _MemoryDialogState extends State<MemoryDialog> {
late TextEditingController contentController;
bool _isSaving = false;
bool _saveFailed = false;

@override
void initState() {
Expand Down Expand Up @@ -122,37 +124,47 @@ class _MemoryDialogState extends State<MemoryDialog> {
),
),
const SizedBox(height: 24),
if (_saveFailed) ...[
const Text(
'Failed to save. Please check your connection.',
style: TextStyle(
color: Colors.redAccent,
fontSize: 13,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
],
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
if (contentController.text.trim().isNotEmpty) {
if (isEditing) {
widget.provider.editMemory(widget.memory!, contentController.text);
MixpanelManager().memoriesPageEditedMemory();
} else {
widget.provider
.createMemory(contentController.text, MemoryVisibility.private, MemoryCategory.manual);
MixpanelManager().memoriesPageCreatedMemory(MemoryCategory.manual);
}
Navigator.pop(context);
}
},
onPressed: _isSaving ? null : _handleSave,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurpleAccent,
backgroundColor: _saveFailed ? Colors.orange : Colors.deepPurpleAccent,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
disabledBackgroundColor: Colors.deepPurpleAccent.withOpacity(0.5),
disabledForegroundColor: Colors.white.withOpacity(0.7),
),
child: const Text(
'Save Memory',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
child: _isSaving
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Text(
_saveFailed ? 'Retry' : 'Save Memory',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
Expand All @@ -161,6 +173,50 @@ class _MemoryDialogState extends State<MemoryDialog> {
);
}

Future<void> _handleSave() async {
if (contentController.text.trim().isEmpty) return;

setState(() {
_isSaving = true;
_saveFailed = false;
});

final isEditing = widget.memory != null;
bool success;

try {
if (isEditing) {
success = await widget.provider.editMemory(widget.memory!, contentController.text);
if (success) {
MixpanelManager().memoriesPageEditedMemory();
}
} else {
success = await widget.provider.createMemory(
contentController.text,
MemoryVisibility.private,
MemoryCategory.manual,
);
if (success) {
MixpanelManager().memoriesPageCreatedMemory(MemoryCategory.manual);
}
}
} catch (e) {
success = false;
debugPrint('Error saving memory: $e');
}

if (!mounted) return;

setState(() {
_isSaving = false;
_saveFailed = !success;
});

if (success) {
Navigator.pop(context);
}
}

Future<void> _showDeleteConfirmation(BuildContext context) async {
if (widget.memory == null) return;

Expand Down
80 changes: 66 additions & 14 deletions app/lib/pages/memories/widgets/memory_edit_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MemoryEditSheet extends StatefulWidget {

class _MemoryEditSheetState extends State<MemoryEditSheet> {
late final TextEditingController contentController;
bool _isSaving = false;
bool _saveFailed = false;

@override
void initState() {
Expand Down Expand Up @@ -108,30 +110,47 @@ class _MemoryEditSheetState extends State<MemoryEditSheet> {
),
),
const SizedBox(height: 24),
if (_saveFailed) ...[
const Text(
'Failed to save. Please check your connection.',
style: TextStyle(
color: Colors.redAccent,
fontSize: 13,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
],
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
if (contentController.text.trim().isNotEmpty) {
widget.provider.editMemory(widget.memory, contentController.text, widget.memory.category);
Navigator.pop(context);
}
},
onPressed: _isSaving ? null : _handleSave,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurpleAccent,
backgroundColor: _saveFailed ? Colors.orange : Colors.deepPurpleAccent,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
disabledBackgroundColor: Colors.deepPurpleAccent.withOpacity(0.5),
disabledForegroundColor: Colors.white.withOpacity(0.7),
),
child: const Text(
'Save Memory',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
child: _isSaving
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Text(
_saveFailed ? 'Retry' : 'Save Memory',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
Expand All @@ -140,6 +159,39 @@ class _MemoryEditSheetState extends State<MemoryEditSheet> {
);
}

Future<void> _handleSave() async {
if (contentController.text.trim().isEmpty) return;

setState(() {
_isSaving = true;
_saveFailed = false;
});

bool success;

try {
success = await widget.provider.editMemory(
widget.memory,
contentController.text,
widget.memory.category,
);
} catch (e) {
success = false;
debugPrint('Error saving memory: $e');
}
Comment on lines +172 to +181
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The _handleSave method is missing an analytics call to track when a memory is successfully edited. This is inconsistent with other similar dialogs in the app (e.g., memory_dialog.dart) and means this important user action will not be tracked. Please add a call to MixpanelManager().memoriesPageEditedMemory() when the edit operation is successful.

Suggested change
try {
success = await widget.provider.editMemory(
widget.memory,
contentController.text,
widget.memory.category,
);
} catch (e) {
success = false;
debugPrint('Error saving memory: $e');
}
try {
success = await widget.provider.editMemory(
widget.memory,
contentController.text,
widget.memory.category,
);
if (success) {
MixpanelManager().memoriesPageEditedMemory();
}
} catch (e) {
success = false;
debugPrint('Error saving memory: $e');
}


if (!mounted) return;

setState(() {
_isSaving = false;
_saveFailed = !success;
});

if (success) {
Navigator.pop(context);
}
}

Future<void> _showDeleteConfirmation(BuildContext context) async {
final shouldDelete = await DeleteConfirmation.show(context);
if (shouldDelete) {
Expand Down
Loading