Skip to content

Commit 6f3c949

Browse files
committed
feat(content_management): improve snackbar behavior and state management
- Replace snackbarMessage with itemPendingDeletion in state - Remove messageBuilder from undo deletions - Clear itemPendingDeletion on undo or deletion completion - Update comments to explain changes in snackbar logic
1 parent 69b04d5 commit 6f3c949

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/content_management/bloc/content_management_bloc.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,15 @@ class ContentManagementBloc
387387
state.copyWith(
388388
headlines: updatedHeadlines,
389389
lastPendingDeletionId: event.id,
390-
snackbarMessage: 'Headline "${headlineToDelete.title}" deleted.',
390+
itemPendingDeletion: headlineToDelete,
391391
),
392392
);
393393

394394
_pendingDeletionsService.requestDeletion(
395395
item: headlineToDelete,
396396
repository: _headlinesRepository,
397397
undoDuration: AppConstants.kSnackbarDuration,
398+
// messageBuilder is omitted, UI will build the message
398399
);
399400
}
400401

@@ -578,14 +579,15 @@ class ContentManagementBloc
578579
state.copyWith(
579580
topics: updatedTopics,
580581
lastPendingDeletionId: event.id,
581-
snackbarMessage: 'Topic "${topicToDelete.name}" deleted.',
582+
itemPendingDeletion: topicToDelete,
582583
),
583584
);
584585

585586
_pendingDeletionsService.requestDeletion(
586587
item: topicToDelete,
587588
repository: _topicsRepository,
588589
undoDuration: AppConstants.kSnackbarDuration,
590+
// messageBuilder is omitted, UI will build the message
589591
);
590592
}
591593

@@ -769,14 +771,15 @@ class ContentManagementBloc
769771
state.copyWith(
770772
sources: updatedSources,
771773
lastPendingDeletionId: event.id,
772-
snackbarMessage: 'Source "${sourceToDelete.name}" deleted.',
774+
itemPendingDeletion: sourceToDelete,
773775
),
774776
);
775777

776778
_pendingDeletionsService.requestDeletion(
777779
item: sourceToDelete,
778780
repository: _sourcesRepository,
779781
undoDuration: AppConstants.kSnackbarDuration,
782+
// messageBuilder is omitted, UI will build the message
780783
);
781784
}
782785

@@ -802,8 +805,9 @@ class ContentManagementBloc
802805
// The item was already optimistically removed from the list.
803806
emit(
804807
state.copyWith(
805-
lastPendingDeletionId: null,
806-
snackbarMessage: null,
808+
lastPendingDeletionId: null, // Clear the pending ID
809+
// Clear the item so the snackbar doesn't reappear on rebuilds
810+
itemPendingDeletion: null,
807811
),
808812
);
809813
case DeletionStatus.undone:
@@ -816,8 +820,8 @@ class ContentManagementBloc
816820
emit(
817821
state.copyWith(
818822
headlines: updatedHeadlines,
819-
lastPendingDeletionId: null,
820-
snackbarMessage: null,
823+
lastPendingDeletionId: null, // Clear the pending ID
824+
itemPendingDeletion: null,
821825
),
822826
);
823827
} else if (item is Topic) {
@@ -827,8 +831,8 @@ class ContentManagementBloc
827831
emit(
828832
state.copyWith(
829833
topics: updatedTopics,
830-
lastPendingDeletionId: null,
831-
snackbarMessage: null,
834+
lastPendingDeletionId: null, // Clear the pending ID
835+
itemPendingDeletion: null,
832836
),
833837
);
834838
} else if (item is Source) {
@@ -838,8 +842,8 @@ class ContentManagementBloc
838842
emit(
839843
state.copyWith(
840844
sources: updatedSources,
841-
lastPendingDeletionId: null,
842-
snackbarMessage: null,
845+
lastPendingDeletionId: null, // Clear the pending ID
846+
itemPendingDeletion: null,
843847
),
844848
);
845849
}

0 commit comments

Comments
 (0)