Skip to content

Commit f46afd5

Browse files
committed
refactor(content_management): improve headline restoration logic
- Simplify index calculation for restored headlines - Enhance readability and performance of insertion logic
1 parent 2e4a0dc commit f46afd5

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/content_management/bloc/archived_headlines/archived_headlines_bloc.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,12 @@ class ArchivedHeadlinesBloc
183183
} else if (status == DeletionStatus.undone) {
184184
// Deletion undone, restore the headline to the main list.
185185
if (item is Headline) {
186+
final insertionIndex = state.headlines.indexWhere(
187+
(h) => h.updatedAt.isBefore(item.updatedAt),
188+
);
186189
final updatedHeadlines = List<Headline>.from(state.headlines)
187190
..insert(
188-
state.headlines.indexWhere(
189-
(h) => h.updatedAt.isBefore(
190-
item.updatedAt,
191-
),
192-
) !=
193-
-1
194-
? state.headlines.indexWhere(
195-
(h) => h.updatedAt.isBefore(
196-
item.updatedAt,
197-
),
198-
)
199-
: state.headlines.length,
191+
insertionIndex != -1 ? insertionIndex : state.headlines.length,
200192
item,
201193
);
202194
emit(

0 commit comments

Comments
 (0)