-
Notifications
You must be signed in to change notification settings - Fork 0
[#578] TodayView에 TCA를 적용한다 #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
de34bc0
feat: Store 1차 구현
opficdev 36abe2d
refactor: 헬퍼 메서드를 피쳐 쪽으로 이동
opficdev 546a321
refactor: 불필요 리듀서 분리 수정
opficdev a0f755a
refactor: 코디네이터에서 캐싱하는 Store들은 Bindable 처리
opficdev 668e80a
refactor: 불필요 컴포넌트화 제거
opficdev 6fddced
refactor: Picker에 BindingAction 처리
opficdev d3d61bc
refactor: Toggle에 BindingAction 처리
opficdev 3b15203
refactor: BindingAction으로 인한 기존 액션 제거
opficdev 09b5009
refactor: now 시점을 최대한 상위 위치로 옮겨 시간을 일차화
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
Application/DevLogPresentation/Sources/Today/TodayFeature+State.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // | ||
| // TodayFeature+State.swift | ||
| // DevLogPresentation | ||
| // | ||
| // Created by opfic on 6/14/26. | ||
| // | ||
|
|
||
| import DevLogCore | ||
| import Foundation | ||
|
|
||
| extension TodayFeature { | ||
| static func summaryValue( | ||
| for scope: SectionScope, | ||
| todos: [TodayTodoItem], | ||
| displayOptions: TodayDisplayOptions, | ||
| now: Date | ||
| ) -> Int { | ||
| let displayedTodos = displayedTodos( | ||
| todos: todos, | ||
| displayOptions: displayOptions | ||
| ) | ||
|
|
||
| switch scope { | ||
| case .all: | ||
| return displayedTodos.count | ||
| case .focused: | ||
| return displayedTodos.filter(\.isPinned).count | ||
| case .overdue: | ||
| return displayedTodos.filter { isOverdue($0, now: now) }.count | ||
| case .dueSoon: | ||
| return displayedTodos.filter { isDueSoon($0, now: now) }.count | ||
| } | ||
| } | ||
|
|
||
| static func displayedTodos( | ||
| todos: [TodayTodoItem], | ||
| displayOptions: TodayDisplayOptions | ||
| ) -> [TodayTodoItem] { | ||
| let dueDateFilteredTodos: [TodayTodoItem] | ||
| switch displayOptions.dueDateVisibility { | ||
| case .all: | ||
| dueDateFilteredTodos = todos | ||
| case .withDueDateOnly: | ||
| dueDateFilteredTodos = todos.filter { $0.dueDate != nil } | ||
| case .withoutDueDateOnly: | ||
| dueDateFilteredTodos = todos.filter { $0.dueDate == nil } | ||
| } | ||
|
|
||
| switch displayOptions.focusVisibility { | ||
| case .all: | ||
| return dueDateFilteredTodos | ||
| case .focusedOnly: | ||
| return dueDateFilteredTodos.filter(\.isPinned) | ||
| } | ||
| } | ||
|
|
||
| static func groupedSectionItems( | ||
| from items: [TodayTodoItem], | ||
| now: Date | ||
| ) -> TodayFeature.SectionCollection { | ||
| let calendar = Calendar.current | ||
| let startOfToday = calendar.startOfDay(for: now) | ||
| guard let windowEnd = calendar.date( | ||
| byAdding: .day, | ||
| value: TodayFeature.upcomingWindowDays, | ||
| to: startOfToday | ||
| ) else { | ||
| return TodayFeature.SectionCollection( | ||
| focused: items.filter(\.isPinned), | ||
| unscheduled: items.filter { !$0.isPinned && $0.dueDate == nil } | ||
| ) | ||
| } | ||
|
opficdev marked this conversation as resolved.
|
||
|
|
||
| var collection = TodayFeature.SectionCollection() | ||
|
|
||
| for item in items { | ||
| if item.isPinned { | ||
| collection.focused.append(item) | ||
| continue | ||
| } | ||
|
|
||
| guard let dueDate = item.dueDate else { | ||
| collection.unscheduled.append(item) | ||
| continue | ||
| } | ||
|
|
||
| let dueDay = calendar.startOfDay(for: dueDate) | ||
| if dueDay < startOfToday { | ||
| collection.overdue.append(item) | ||
| } else if dueDay <= windowEnd { | ||
| collection.dueSoon.append(item) | ||
| } else { | ||
| collection.later.append(item) | ||
| } | ||
| } | ||
|
|
||
| return collection | ||
| } | ||
|
|
||
| static func isOverdue(_ item: TodayTodoItem, now: Date) -> Bool { | ||
| guard let dueDate = item.dueDate else { return false } | ||
| let calendar = Calendar.current | ||
| return calendar.startOfDay(for: dueDate) < calendar.startOfDay(for: now) | ||
| } | ||
|
|
||
| static func isDueSoon(_ item: TodayTodoItem, now: Date) -> Bool { | ||
| guard let dueDate = item.dueDate else { return false } | ||
| let calendar = Calendar.current | ||
| let startOfToday = calendar.startOfDay(for: now) | ||
| guard let windowEnd = calendar.date( | ||
| byAdding: .day, | ||
| value: TodayFeature.upcomingWindowDays, | ||
| to: startOfToday | ||
| ) else { | ||
| return false | ||
| } | ||
| let dueDay = calendar.startOfDay(for: dueDate) | ||
| return startOfToday <= dueDay && dueDay <= windowEnd | ||
| } | ||
|
|
||
| static func makeSection( | ||
| category: SectionCategory, | ||
| title: String, | ||
| items: [TodayTodoItem] | ||
| ) -> [SectionContent] { | ||
| guard !items.isEmpty else { return [] } | ||
| return [SectionContent(category: category, title: title, items: items)] | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.