Skip to content

Commit bba0dbf

Browse files
committed
refactor: category를 상태(State)에서 제거
1 parent 8a12019 commit bba0dbf

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

DevLog/Presentation/ViewModel/TodoListViewModel.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ final class TodoListViewModel: Store {
1313
var todos: [TodoListItem] = []
1414
var searchText: String = ""
1515
var searchResults: [TodoListItem] = []
16-
let category: TodoCategory
1716
var showEditor: Bool = false
1817
var showAlert: Bool = false
1918
var alertTitle: String = ""
@@ -81,6 +80,7 @@ final class TodoListViewModel: Store {
8180
case request
8281
}
8382

83+
let category: TodoCategory
8484
private(set) var state: State
8585
private let fetchTodosUseCase: FetchTodosUseCase
8686
private let fetchTodoByIdUseCase: FetchTodoByIdUseCase
@@ -106,18 +106,14 @@ final class TodoListViewModel: Store {
106106
self.upsertTodoUseCase = upsertTodoUseCase
107107
self.deleteTodoUseCase = deleteTodoUseCase
108108
self.undoDeleteTodoUseCase = undoDeleteTodoUseCase
109+
self.category = category
109110
self.state = State(
110-
category: category,
111111
query: TodoQuery(category: category)
112112
)
113113
}
114114

115115
let searchResultsLimit = 5
116116

117-
var category: TodoCategory {
118-
state.category
119-
}
120-
121117
var appliedFilterCount: Int {
122118
var count = 0
123119
if state.query.sortTarget != .createdAt { count += 1 }
@@ -195,7 +191,7 @@ final class TodoListViewModel: Store {
195191
self.endLoading(.immediate)
196192
}
197193
}
198-
let query = TodoQuery(category: state.category, keyword: keyword)
194+
let query = TodoQuery(category: category, keyword: keyword)
199195
let page = try await fetchTodosUseCase.execute(query, cursor: nil)
200196
if Task.isCancelled { return }
201197
send(.fetchSearchResults(page.items.compactMap { TodoListItem(from: $0) }))
@@ -311,7 +307,7 @@ private extension TodoListViewModel {
311307
self.nextCursor = nil
312308
return [.fetch]
313309
case .resetFilters:
314-
state.query = TodoQuery(category: state.category)
310+
state.query = TodoQuery(category: category)
315311
self.nextCursor = nil
316312
return [.fetch]
317313
case .setIsSearching(let value):

DevLog/UI/Home/TodoListView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct TodoListView: View {
4545
prompt: Text(
4646
String.localizedStringWithFormat(
4747
String(localized: "todo_list_search_prompt_format"),
48-
TodoCategoryItem(from: viewModel.state.category).localizedName
48+
TodoCategoryItem(from: viewModel.category).localizedName
4949
)
5050
)
5151
)
@@ -71,14 +71,14 @@ struct TodoListView: View {
7171
) {
7272
Label(viewModel.state.toastMessage, systemImage: "arrow.uturn.left")
7373
}
74-
.navigationTitle(TodoCategoryItem(from: viewModel.state.category).localizedName)
74+
.navigationTitle(TodoCategoryItem(from: viewModel.category).localizedName)
7575
.fullScreenCover(isPresented: Binding(
7676
get: { viewModel.state.showEditor },
7777
set: { viewModel.send(.setShowEditor($0)) }
7878
)) {
7979
TodoEditorView(
8080
viewModel: TodoEditorViewModel(
81-
category: viewModel.state.category,
81+
category: viewModel.category,
8282
fetchPreferencesUseCase: container.resolve(FetchTodoCategoryPreferencesUseCase.self),
8383
fetchReferenceItemsUseCase: container.resolve(FetchReferenceItemsUseCase.self)
8484
),
@@ -222,7 +222,7 @@ struct TodoListView: View {
222222
prompt: Text(
223223
String.localizedStringWithFormat(
224224
String(localized: "todo_list_search_prompt_format"),
225-
TodoCategoryItem(from: viewModel.state.category).localizedName
225+
TodoCategoryItem(from: viewModel.category).localizedName
226226
)
227227
)
228228
)
@@ -240,7 +240,7 @@ struct TodoListView: View {
240240
Text(
241241
String.localizedStringWithFormat(
242242
String(localized: "todo_list_search_instruction_format"),
243-
TodoCategoryItem(from: viewModel.state.category).localizedName
243+
TodoCategoryItem(from: viewModel.category).localizedName
244244
)
245245
)
246246
.foregroundStyle(Color.gray)

0 commit comments

Comments
 (0)