Skip to content

Commit 02d13d8

Browse files
committed
feat: 카테고리를 수정해도 최근 수정 섹션에서는 반영되지 않는 현상 해결
1 parent 32652e8 commit 02d13d8

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

DevLog/Presentation/Structure/RecentTodoItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct RecentTodoItem: Identifiable, Hashable {
1414
let isPinned: Bool
1515
let updatedAt: Date
1616
let tags: [String]
17-
let category: TodoCategory
17+
var category: TodoCategory
1818

1919
init(from todo: Todo) {
2020
self.id = todo.id

DevLog/Presentation/ViewModel/HomeViewModel.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ private extension HomeViewModel {
304304
return [.showModalAfterDelay(.todoEditor)]
305305
case .orderTodoCategoryPreferences(let preferences):
306306
state.preferences = preferences
307+
state.recentTodos = syncRecentTodos(state.recentTodos, preferences: preferences)
307308
return [.updateTodoCategoryPreferences(preferences)]
308309
case .addTodo(let todo):
309310
return [.addTodo(todo)]
@@ -340,6 +341,7 @@ private extension HomeViewModel {
340341
setLoading(&state, loadingTarget: loadingTarget, isLoading: isLoading)
341342
case .setTodoCategoryPreferences(let preferences):
342343
state.preferences = preferences
344+
state.recentTodos = syncRecentTodos(state.recentTodos, preferences: preferences)
343345
case .updateRecentTodos(let todos):
344346
state.recentTodos = todos
345347
case .updateWebPages(let pages):
@@ -437,6 +439,23 @@ private extension HomeViewModel {
437439
}
438440
}
439441

442+
func syncRecentTodos(
443+
_ recentTodos: [RecentTodoItem],
444+
preferences: [TodoCategoryPreference]
445+
) -> [RecentTodoItem] {
446+
recentTodos.map { recentTodo in
447+
guard let category = preferences.first(where: {
448+
$0.category.storageValue == recentTodo.category.storageValue
449+
})?.category else {
450+
return recentTodo
451+
}
452+
453+
var recentTodo = recentTodo
454+
recentTodo.category = category
455+
return recentTodo
456+
}
457+
}
458+
440459
func normalizedWebPageURL(_ input: String) -> String? {
441460
let trimmed = input.trimmingCharacters(in: .whitespacesAndNewlines)
442461
guard !trimmed.isEmpty else { return nil }

0 commit comments

Comments
 (0)