diff --git a/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift b/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift index 4f3c099f..f34fd262 100644 --- a/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift +++ b/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift @@ -10,6 +10,7 @@ import PresentationShared struct DevelopmentGoalSection: View { @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac + @Environment(\.usesDesktopLayout) private var usesDesktopLayout let items: [DevelopmentGoalItem] let isLoading: Bool let hasLoaded: Bool @@ -67,7 +68,12 @@ struct DevelopmentGoalSection: View { Button { onSelect(item) } label: { - DevelopmentGoalRow(item: item) + // 사이드바가 있는 창은 제목과 진행률만 담은 한 줄 행 + if usesDesktopLayout { + DevelopmentGoalCompactRow(item: item) + } else { + DevelopmentGoalRow(item: item) + } } .buttonStyle(.plain) } @@ -140,6 +146,65 @@ private struct DevelopmentGoalRow: View { } } +// 한 줄에 제목과 진행률, 그 아래 얇은 진행 막대를 둔 목표 행 +private struct DevelopmentGoalCompactRow: View { + @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac + let item: DevelopmentGoalItem + + var body: some View { + VStack(alignment: .leading, spacing: 7) { + HStack(alignment: .firstTextBaseline, spacing: 8) { + Text(item.goal.title) + .font(.adaptive(isiOSAppOnMac ? .body : .callout).weight(.semibold)) + .foregroundStyle(Color.label) + .lineLimit(1) + .frame(maxWidth: .infinity, alignment: .leading) + // 연결된 Todo가 없으면 0% 대신 연결 없음 문구로 아직 완료하지 않은 목표와 구분 + Group { + if item.todoProgress.isEmpty { + Text("home_development_goal_todo_empty", bundle: PresentationResources.bundle) + } else { + Text( + String.localizedStringWithFormat( + String( + localized: "home_development_goal_todo_progress_percent_format", + bundle: PresentationResources.bundle + ), + item.todoProgress.percentage + ) + ) + } + } + .font(.adaptive(isiOSAppOnMac ? .subheadline : .footnote)) + .foregroundStyle(Color.secondaryLabel) + .lineLimit(1) + .fixedSize() + } + + // 연결된 Todo가 없으면 막대를 그리지 않고 자리만 남겨 다른 행과 높이를 맞춤 + GeometryReader { proxy in + Capsule() + .fill(Color.separator) + .overlay(alignment: .leading) { + Capsule() + .fill(Color.accent) + .frame(width: proxy.size.width * item.todoProgress.fraction) + } + } + .frame(height: 4) + .opacity(item.todoProgress.isEmpty ? 0 : 1) + } + .padding(.vertical, isiOSAppOnMac ? 10 * AdaptiveSize.boardScale : 14) + .padding(.trailing, isiOSAppOnMac ? 14 * AdaptiveSize.boardScale : 16) + .overlay(alignment: .bottom) { + Rectangle() + .fill(Color.secondarySeparator) + .frame(height: 1) + } + .contentShape(.rect) + } +} + struct DevelopmentTodoProgressView: View { let progress: DevelopmentGoalTodoProgress diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift b/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift index 0127aa41..96a5ad61 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift @@ -59,6 +59,27 @@ struct HomeFeature { loading.visibleTargets.contains(LoadingTarget.developmentGoals.target) } + // 넓은 창 홈과 사이드바의 진행 중인 개발 순서 + // 최근 기록 순이고 기록이 없는 목표는 뒤에 표시 + var developmentGoalItemsByRecentRecord: [DevelopmentGoalItem] { + developmentGoalItems.sorted { lhs, rhs in + switch (lhs.recentRecord?.confirmedAt, rhs.recentRecord?.confirmedAt) { + case let (left?, right?) where left != right: + return right < left + case (.some, .none): + return true + case (.none, .some): + return false + default: + // 기록 시각이 같거나 둘 다 기록이 없으면 불러온 목록과 같은 생성 순, 같은 시각이면 id 순 + if lhs.goal.createdAt == rhs.goal.createdAt { + return lhs.id < rhs.id + } + return lhs.goal.createdAt < rhs.goal.createdAt + } + } + } + // 사이드바에서 고른 채로 표시할 위치 var sideBarLocation: SideBarLocation { if let goalDetail { @@ -77,10 +98,11 @@ struct HomeFeature { } // 사이드바 Todo, 개발 목표 묶음의 하위 항목 + // 개발 목표는 같은 창의 홈과 같은 최근 기록 순 var sideBarContent: SideBarContent { SideBarContent( todoCategories: preferences.filter(\.isVisible), - developmentGoals: developmentGoalItems.map { SideBarGoal(id: $0.id, title: $0.goal.title) } + developmentGoals: developmentGoalItemsByRecentRecord.map { SideBarGoal(id: $0.id, title: $0.goal.title) } ) } diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index f2875f73..4ee61c9c 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -258,27 +258,22 @@ private struct HomeTopBarIconButtonStyle: ButtonStyle { } } -// 넓은 화면은 두 열, 좁은 화면과 오른쪽 칸이 열려 좁아진 왼쪽 칸은 한 열 +// 사이드바가 있는 창은 요약 없이 칸 가운데 좁은 한 칸, 좁은 화면은 요약을 포함한 한 열 private struct HomeColumns: View { @Environment(\.usesDesktopLayout) private var usesDesktopLayout - @Environment(\.paneWidth) private var paneWidth @Environment(\.readableContentWidth) private var readableContentWidth let store: StoreOf var body: some View { - if usesDesktopLayout && paneWidth == nil { - // 왼쪽 요약·카테고리, 오른쪽 진행 중인 개발의 두 열 - HStack(spacing: 0) { - ScrollView { - VStack(alignment: .leading, spacing: 0) { - HomeDevelopmentSummary(store: store) - HomeTodoSection(store: store) - } - } - Divider().overlay(Color.secondarySeparator) - ScrollView { + if usesDesktopLayout { + // 버튼 위주 화면이라 목록 폭보다 좁은 320 폭 + ScrollView { + LazyVStack(alignment: .leading, spacing: 0) { + HomeTodoSection(store: store) HomeDevelopmentGoals(store: store) } + .frame(maxWidth: 320 * AdaptiveSize.boardScale) + .frame(maxWidth: .infinity) } } else { ScrollView { @@ -312,11 +307,12 @@ private struct HomeDevelopmentSummary: View { } private struct HomeDevelopmentGoals: View { + @Environment(\.usesDesktopLayout) private var usesDesktopLayout let store: StoreOf var body: some View { DevelopmentGoalSection( - items: store.developmentGoalItems, + items: usesDesktopLayout ? store.developmentGoalItemsByRecentRecord : store.developmentGoalItems, isLoading: store.isDevelopmentGoalsLoading, hasLoaded: store.hasDevelopmentGoalsLoaded, hasLoadFailure: store.hasDevelopmentGoalsLoadFailure, diff --git a/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift b/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift index ab9e3ff9..e19a0b76 100644 --- a/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift +++ b/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift @@ -52,6 +52,36 @@ struct HomeFeatureTests { #expect(adapter.developmentGoalItems.first?.recentRecord == version) } + @Test("HomeFeature 넓은 창 목표 순서는 최근 기록 순이고 기록 시각이 같거나 없는 목표는 생성 순으로 둔다") + func HomeFeature_넓은_창_목표_순서는_최근_기록_순이고_기록_시각이_같거나_없는_목표는_생성_순으로_둔다() throws { + var state = HomeFeature.State() + state.developmentGoalItems = [ + DevelopmentGoalItem(goal: try makeDevelopmentGoal(id: "empty-second", createdAt: 6), recentRecord: nil), + DevelopmentGoalItem( + goal: try makeDevelopmentGoal(id: "old", createdAt: 2), + recentRecord: try makeDevelopmentRecordVersion(id: "old", recordID: "old", title: "old", confirmedAt: 10) + ), + DevelopmentGoalItem(goal: try makeDevelopmentGoal(id: "empty-first", createdAt: 1), recentRecord: nil), + DevelopmentGoalItem( + goal: try makeDevelopmentGoal(id: "recent-second", createdAt: 5), + recentRecord: try makeDevelopmentRecordVersion(id: "b", recordID: "b", title: "b", confirmedAt: 20) + ), + DevelopmentGoalItem( + goal: try makeDevelopmentGoal(id: "recent-first", createdAt: 3), + recentRecord: try makeDevelopmentRecordVersion(id: "a", recordID: "a", title: "a", confirmedAt: 20) + ) + ] + + #expect( + state.developmentGoalItemsByRecentRecord.map(\.id) + == ["recent-first", "recent-second", "old", "empty-first", "empty-second"] + ) + #expect( + state.sideBarContent.developmentGoals.map(\.id) + == state.developmentGoalItemsByRecentRecord.map(\.id) + ) + } + @Test("HomeFeature fetchData는 연결 Todo 완료 수로 목표 진행률을 계산한다") func HomeFeature_fetchData는_연결_Todo_완료_수로_목표_진행률을_계산한다() async throws { let goal = try makeDevelopmentGoal(id: "goal", createdAt: 1)