Skip to content

Commit e3d739c

Browse files
committed
refactor: Today 섹션 생성 로직을 SummaryScope 기반으로 정리
1 parent 17b9619 commit e3d739c

1 file changed

Lines changed: 57 additions & 22 deletions

File tree

DevLog/Presentation/ViewModel/TodayViewModel.swift

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ final class TodayViewModel: Store {
1717
}
1818

1919
struct SectionContent: Identifiable, Equatable {
20-
var id: String { title }
20+
var id: SummaryScope { scope }
21+
let scope: SummaryScope
2122
let title: String
2223
let items: [TodayTodoItem]
2324
}
@@ -87,35 +88,60 @@ final class TodayViewModel: Store {
8788
}
8889

8990
var sections: [SectionContent] {
90-
let groupedItems = groupedSectionItems(from: displayedTodos)
91-
let allSections: [SectionContent] = [
92-
SectionContent(title: String(localized: "today_section_focused"), items: groupedItems.focused),
93-
SectionContent(title: String(localized: "today_section_overdue"), items: groupedItems.overdue),
94-
SectionContent(
95-
title: String.localizedStringWithFormat(
96-
String(localized: "today_section_due_soon_format"),
97-
Int64(upcomingWindowDays)
98-
),
99-
items: groupedItems.dueSoon
100-
),
101-
SectionContent(title: String(localized: "today_section_later"), items: groupedItems.later),
102-
SectionContent(title: String(localized: "today_section_unscheduled"), items: groupedItems.unscheduled)
103-
]
91+
let items = groupedSectionItems(from: displayedTodos)
10492

10593
switch state.selectedSummaryScope {
10694
case .all:
107-
return allSections.filter { !$0.items.isEmpty }
95+
return
96+
makeSection(
97+
scope: .focused,
98+
title: String(localized: "today_section_focused"),
99+
items: items.focused
100+
)
101+
+ makeSection(
102+
scope: .overdue,
103+
title: String(localized: "today_section_overdue"),
104+
items: items.overdue
105+
)
106+
+ makeSection(
107+
scope: .dueSoon,
108+
title: String.localizedStringWithFormat(
109+
String(localized: "today_section_due_soon_format"),
110+
Int64(upcomingWindowDays)
111+
),
112+
items: items.dueSoon
113+
)
114+
+ makeSection(
115+
scope: .all,
116+
title: String(localized: "today_section_later"),
117+
items: items.later
118+
)
119+
+ makeSection(
120+
scope: .all,
121+
title: String(localized: "today_section_unscheduled"),
122+
items: items.unscheduled
123+
)
108124
case .focused:
109-
return allSections.filter { $0.title == String(localized: "today_section_focused") && !$0.items.isEmpty }
125+
return makeSection(
126+
scope: .focused,
127+
title: String(localized: "today_section_focused"),
128+
items: items.focused
129+
)
110130
case .overdue:
111-
return allSections.filter { $0.title == String(localized: "today_section_overdue") && !$0.items.isEmpty }
131+
return makeSection(
132+
scope: .overdue,
133+
title: String(localized: "today_section_overdue"),
134+
items: items.overdue
135+
)
112136
case .dueSoon:
113-
return allSections.filter {
114-
$0.title == String.localizedStringWithFormat(
137+
return makeSection(
138+
scope: .dueSoon,
139+
title: String.localizedStringWithFormat(
115140
String(localized: "today_section_due_soon_format"),
116141
Int64(upcomingWindowDays)
117-
) && !$0.items.isEmpty
118-
}
142+
),
143+
items: items.dueSoon
144+
)
119145
}
120146
}
121147

@@ -221,6 +247,15 @@ final class TodayViewModel: Store {
221247
}
222248

223249
private extension TodayViewModel {
250+
func makeSection(
251+
scope: SummaryScope,
252+
title: String,
253+
items: [TodayTodoItem]
254+
) -> [SectionContent] {
255+
guard !items.isEmpty else { return [] }
256+
return [SectionContent(scope: scope, title: title, items: items)]
257+
}
258+
224259
func reduceByUser(_ action: Action, state: inout State) -> [SideEffect] {
225260
switch action {
226261
case .refresh:

0 commit comments

Comments
 (0)