Skip to content

Commit 4e6a441

Browse files
committed
refactor: Picker 형태로 변경
1 parent 1f53f66 commit 4e6a441

3 files changed

Lines changed: 35 additions & 64 deletions

File tree

DevLog/Domain/Entity/PushNotificationQuery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct PushNotificationQuery: Equatable {
1313
case oldest
1414
}
1515

16-
enum TimeFilter: Equatable {
16+
enum TimeFilter: Equatable, Hashable {
1717
case none
1818
case hours(Int)
1919
case days(Int)

DevLog/UI/Home/TodoListView.swift

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -311,35 +311,29 @@ struct TodoListView: View {
311311

312312
private var sortMenu: some View {
313313
Menu {
314-
Section {
314+
Picker(selection: Binding(
315+
get: { viewModel.state.query.sortTarget },
316+
set: { viewModel.send(.setSortTarget($0)) }
317+
)) {
315318
ForEach([TodoQuery.SortTarget.createdAt, .updatedAt], id: \.self) { option in
316-
Button {
317-
viewModel.send(.setSortTarget(option))
318-
} label: {
319-
selectionLabel(
320-
title: option.title,
321-
isSelected: viewModel.state.query.sortTarget == option
322-
)
323-
}
319+
Text(option.title).tag(option)
324320
}
325-
} header: {
321+
} label: {
326322
Text("정렬 기준")
327323
}
324+
.tint(.blue)
328325

329-
Section {
326+
Picker(selection: Binding(
327+
get: { viewModel.state.query.sortOrder },
328+
set: { viewModel.send(.setSortOrder($0)) }
329+
)) {
330330
ForEach([TodoQuery.SortOrder.latest, .oldest], id: \.self) { option in
331-
Button {
332-
viewModel.send(.setSortOrder(option))
333-
} label: {
334-
selectionLabel(
335-
title: option.title,
336-
isSelected: viewModel.state.query.sortOrder == option
337-
)
338-
}
331+
Text(option.title).tag(option)
339332
}
340-
} header: {
333+
} label: {
341334
Text("정렬 순서")
342335
}
336+
.tint(.blue)
343337
} label: {
344338
let condition = viewModel.state.query.sortTarget == .createdAt && viewModel.state.query.sortOrder == .latest
345339
HStack {
@@ -353,27 +347,21 @@ struct TodoListView: View {
353347

354348
private var filterMenu: some View {
355349
Menu {
356-
Button {
357-
viewModel.send(.togglePinnedOnly)
358-
} label: {
359-
selectionLabel(
360-
title: "중요 표시",
361-
isSelected: viewModel.state.query.isPinned == true
362-
)
350+
Toggle(isOn: Binding(
351+
get: { viewModel.state.query.isPinned == true },
352+
set: { _ in viewModel.send(.togglePinnedOnly) }
353+
)) {
354+
Text("중요 표시")
363355
}
364356

365-
Section {
357+
Picker(selection: Binding(
358+
get: { viewModel.state.query.completionFilter },
359+
set: { viewModel.send(.setCompletionFilter($0)) }
360+
)) {
366361
ForEach([TodoQuery.CompletionFilter.all, .incomplete, .completed], id: \.self) { option in
367-
Button {
368-
viewModel.send(.setCompletionFilter(option))
369-
} label: {
370-
selectionLabel(
371-
title: option.title,
372-
isSelected: viewModel.state.query.completionFilter == option
373-
)
374-
}
362+
Text(option.title).tag(option)
375363
}
376-
} header: {
364+
} label: {
377365
Text("완료 상태")
378366
}
379367
} label: {
@@ -402,19 +390,7 @@ struct TodoListView: View {
402390
.background(Circle().fill(backgroundColor))
403391
}
404392

405-
private func selectionLabel(title: String, isSelected: Bool) -> some View {
406-
HStack {
407-
Text(title)
408-
Spacer()
409-
if isSelected {
410-
Image(systemName: "checkmark")
411-
.tint(.blue)
412-
}
413-
}
414-
.frame(maxWidth: .infinity, alignment: .leading)
415-
}
416-
417-
private enum Path: Hashable {
393+
private enum Path: Hashable {
418394
case detail(String)
419395
}
420396
}

DevLog/UI/PushNotification/PushNotificationListView.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,15 @@ struct PushNotificationListView: View {
168168
}
169169

170170
Menu {
171-
ForEach(PushNotificationQuery.TimeFilter.availableOptions, id: \.id) { option in
172-
Button {
173-
viewModel.send(.setTimeFilter(option))
174-
} label: {
175-
HStack {
176-
Text(option.title)
177-
Spacer()
178-
if viewModel.state.query.timeFilter == option {
179-
Image(systemName: "checkmark")
180-
.tint(.blue)
181-
}
182-
}
183-
.frame(maxWidth: .infinity, alignment: .leading)
171+
Picker(selection: Binding(
172+
get: { viewModel.state.query.timeFilter },
173+
set: { viewModel.send(.setTimeFilter($0)) }
174+
)) {
175+
ForEach(PushNotificationQuery.TimeFilter.availableOptions, id: \.self) { option in
176+
Text(option.title).tag(option)
184177
}
178+
} label: {
179+
Text("기간")
185180
}
186181
} label: {
187182
let condition = viewModel.state.query.timeFilter == .none

0 commit comments

Comments
 (0)