From a7433a53b15ec36b2c1f6d9ab91658741335fda7 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 01/25] =?UTF-8?q?refactor:=20=ED=99=94=EB=A9=B4=EC=9D=B4?= =?UTF-8?q?=20=EC=84=B8=EB=B6=80=20=EC=A0=95=EB=B3=B4=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EB=93=9C=EB=B0=94=20=EB=82=B4=EC=9A=A9=EC=9D=84=20compositionR?= =?UTF-8?q?ight=EB=A1=9C=20=EC=98=AC=EB=A6=AC=EA=B3=A0=20SplitShell=20?= =?UTF-8?q?=EC=98=A4=EB=A5=B8=EC=AA=BD=20=EC=9E=90=EB=A6=AC=EC=97=90=20?= =?UTF-8?q?=EA=B7=B8=EB=A6=AC=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Common/Component/SplitShell.swift | 14 +++- .../Sources/Composition/CompositionView.swift | 27 ++++--- .../Entry/Sources/Composition/TabScreen.swift | 6 ++ .../DetailSideBarFeatureTests.swift | 17 +++-- .../Sources/Category/CategoryManageView.swift | 2 +- .../HomeTab/Sources/Home/HomeView.swift | 2 +- .../Common/Component/DetailSideBar.swift | 76 +++++++++++-------- .../Extension/EnvironmentValues+.swift | 10 --- .../Sources/Todo/Editor/TodoEditorView.swift | 2 +- 9 files changed, 89 insertions(+), 67 deletions(-) diff --git a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift index 35368301..9abe8094 100644 --- a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift +++ b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift @@ -6,24 +6,27 @@ // import SwiftUI +import PresentationShared // 왼쪽, 가운데, 오른쪽 자리와 창 전체를 덮는 자리만 있는 껍데기 // 자리마다 어떤 화면이 언제 나올지는 쓰는 쪽에서 결정 struct SplitShell: View { + // 가운데 화면이 올린 세부 정보 사이드바 내용, 오른쪽 자리에 그릴지는 쓰는 쪽에서 결정 + @State private var rightContent: DetailSideBarContent? private let left: Left private let center: Center - private let right: Right + private let right: (DetailSideBarContent?) -> Right private let overlay: Overlay init( @ViewBuilder left: () -> Left, @ViewBuilder center: () -> Center, - @ViewBuilder right: () -> Right, + @ViewBuilder right: @escaping (DetailSideBarContent?) -> Right, @ViewBuilder overlay: () -> Overlay ) { self.left = left() self.center = center() - self.right = right() + self.right = right self.overlay = overlay() } @@ -31,7 +34,10 @@ struct SplitShell: View { HStack(spacing: 0) { left center - right + .onPreferenceChange(DetailSideBarContentPreferenceKey.self) { content in + rightContent = content + } + right(rightContent) } .overlay { overlay } } diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift index 3d2febfd..82378cab 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift @@ -120,21 +120,26 @@ struct CompositionView: View { showsSideBar && !store.detailSideBar.isPresented ? { store.send(.detailSideBar(.binding(.set(\.isPresented, true)))) } : nil ) - .environment(\.isDetailSideBarPresented, showsSideBar && store.detailSideBar.isPresented) .environment( \.setDetailSideBarPresented, showsSideBar ? { store.send(.detailSideBar(.binding(.set(\.isPresented, $0)))) } : nil ) - } right: { - // 칸 화면이 사이드바를 직접 그리면 창 사이드바는 표시하지 않음 - if showsSideBar - && store.detailSideBar.isPresented - && store.detailSideBar.targets[selectedTab] != .hosted { - DetailSideBar( - target: store.detailSideBar.targets[selectedTab], - windowEvent: windowEvent - ) { - store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) + } right: { content in + // 탭 화면이 올린 내용이 있으면 그 내용, 없으면 고른 대상의 속성 표시 + if showsSideBar && store.detailSideBar.isPresented { + if let content { + DetailSideBar { + store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) + } content: { + content + } + } else { + DetailSideBar( + target: store.detailSideBar.targets[selectedTab], + windowEvent: windowEvent + ) { + store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) + } } } } overlay: { diff --git a/Application/Presentation/Entry/Sources/Composition/TabScreen.swift b/Application/Presentation/Entry/Sources/Composition/TabScreen.swift index e304ad0d..4d02fd90 100644 --- a/Application/Presentation/Entry/Sources/Composition/TabScreen.swift +++ b/Application/Presentation/Entry/Sources/Composition/TabScreen.swift @@ -28,6 +28,12 @@ struct TabScreen: View { // 좁은 창에서도 고른 대상을 기록해 넓은 창으로 바뀌면 바로 세부 정보 사이드바에 표시 .environment(\.selectDetailSideBarTarget) { store.send(.detailSideBar(.targetChanged(tab, $0, owner: $1))) } .environment(\.removeDetailSideBarTarget) { store.send(.detailSideBar(.ownerRemoved(tab, owner: $0))) } + // 고른 탭 화면이 올린 세부 정보 사이드바 내용만 창에 전달 + .transformPreference(DetailSideBarContentPreferenceKey.self) { content in + if !isSelected { + content = nil + } + } .onPreferenceChange(SideBarLocationPreferenceKey.self) { location in guard let location else { return } store.send(.sideBar(.locationChanged(tab, location))) diff --git a/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift b/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift index e5b39dfb..962171f1 100644 --- a/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift +++ b/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift @@ -18,14 +18,15 @@ struct DetailSideBarFeatureTests { DetailSideBarFeature() } store.exhaustivity = .off(showSkippedAssertions: false) + let screen = DetailSideBarTarget.todo(id: "screen", isEditable: false) let goal = UUID() let category = UUID() - await store.send(.targetChanged(.home, .hosted, owner: goal)) - await store.send(.targetChanged(.home, .hosted, owner: category)) + await store.send(.targetChanged(.home, screen, owner: goal)) + await store.send(.targetChanged(.home, screen, owner: category)) await store.send(.ownerRemoved(.home, owner: goal)) - #expect(store.state.targets[.home] == .hosted) + #expect(store.state.targets[.home] == screen) await store.send(.ownerRemoved(.home, owner: category)) @@ -38,14 +39,15 @@ struct DetailSideBarFeatureTests { DetailSideBarFeature() } store.exhaustivity = .off(showSkippedAssertions: false) + let screen = DetailSideBarTarget.todo(id: "screen", isEditable: false) let list = UUID() let editor = UUID() await store.send(.targetChanged(.home, .todo(id: "todo", isEditable: true), owner: list)) - await store.send(.targetChanged(.home, .hosted, owner: editor)) + await store.send(.targetChanged(.home, screen, owner: editor)) await store.send(.targetChanged(.home, .todo(id: "other", isEditable: true), owner: list)) - #expect(store.state.targets[.home] == .hosted) + #expect(store.state.targets[.home] == screen) await store.send(.ownerRemoved(.home, owner: editor)) @@ -58,14 +60,15 @@ struct DetailSideBarFeatureTests { DetailSideBarFeature() } store.exhaustivity = .off(showSkippedAssertions: false) + let screen = DetailSideBarTarget.todo(id: "screen", isEditable: false) let list = UUID() let editor = UUID() await store.send(.targetChanged(.home, nil, owner: list)) - await store.send(.targetChanged(.home, .hosted, owner: editor)) + await store.send(.targetChanged(.home, screen, owner: editor)) await store.send(.targetChanged(.home, .todo(id: "todo", isEditable: true), owner: list)) - #expect(store.state.targets[.home] == .hosted) + #expect(store.state.targets[.home] == screen) await store.send(.ownerRemoved(.home, owner: editor)) diff --git a/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift b/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift index b32acf8f..8b81d551 100644 --- a/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift +++ b/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift @@ -109,7 +109,7 @@ struct CategoryManageView: View { CategoryManageSheet(store: sheetStore) } .prominentAlert(store, state: \.alert, action: \.alert) - .detailSideBar(isActive: usesDesktopLayout) { + .compositionRight(isActive: usesDesktopLayout) { if let sheetStore = store.scope(state: \.categorySheet, action: \.categorySheet.presented) { ScrollView { CategoryEditForm(store: sheetStore) { diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index 545dbf61..1c9a3ba0 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -67,7 +67,7 @@ public struct HomeView: View { } detail: { GoalCreateView(store: goalStore) } - .detailSideBar { + .compositionRight { GoalCreateSideBarContent(store: goalStore) } } else if usesDesktopLayout, diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift index 3d1eb3ba..5e7de785 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift @@ -12,8 +12,6 @@ public enum DetailSideBarTarget: Hashable { // 고칠 수 없는 활동 기록 Todo는 읽기 전용 // 다른 곳에서 바꾼 Todo를 다시 조회하도록 목록이 올리는 revision case todo(id: String, isEditable: Bool, revision: Int = 0) - // 칸 화면이 사이드바 내용을 직접 그리는 대상 - case hosted } // 사이드바가 있는 창 오른쪽에 두는 세부 정보 사이드바 @@ -79,7 +77,7 @@ public struct DetailSideBarTargetContent: View { case .todo(let id, let isEditable, _): TodoDetailSideBarView(todoId: id, isEditable: isEditable, windowEvent: windowEvent) .id(target) - case .hosted, nil: + case nil: DetailSideBarPlaceholder() } } @@ -109,12 +107,37 @@ public extension View { modifier(DetailSideBarTargetModifier(target: target)) } - // 창 오른쪽 끝 칸 화면이 세부 정보 사이드바 내용을 직접 그림, 사이드바가 있는 창에서만 표시 - func detailSideBar( + // 이 화면의 세부 정보 사이드바 내용, 사이드바가 있는 창에서 SplitShell 오른쪽에 표시 + // 화면은 내용만 올리고 사이드바는 CompositionView가 그림 + func compositionRight( isActive: Bool = true, - @ViewBuilder content: () -> Content + @ViewBuilder content: @escaping () -> Content ) -> some View { - modifier(HostedDetailSideBarModifier(isActive: isActive, sideBarContent: content())) + modifier(CompositionRightModifier(isActive: isActive, sideBarContent: content)) + } +} + +// 화면이 올린 세부 정보 사이드바 내용 +// 같은 화면이 올린 동안은 같은 값으로 보고, 내용이 읽는 상태가 바뀌면 이 View만 다시 그림 +public struct DetailSideBarContent: View, Equatable { + let id: UUID + let content: () -> AnyView + + public var body: some View { + content() + } + + public static func == (lhs: Self, rhs: Self) -> Bool { + lhs.id == rhs.id + } +} + +// 탭 화면이 올린 세부 정보 사이드바 내용, 나중에 나타난 화면의 내용을 표시 +public struct DetailSideBarContentPreferenceKey: PreferenceKey { + public static var defaultValue: DetailSideBarContent? { nil } + + public static func reduce(value: inout DetailSideBarContent?, nextValue: () -> DetailSideBarContent?) { + value = nextValue() ?? value } } @@ -135,35 +158,24 @@ private struct DetailSideBarTargetModifier: ViewModifier { } } -private struct HostedDetailSideBarModifier: ViewModifier { +private struct CompositionRightModifier: ViewModifier { @Environment(\.selectDetailSideBarTarget) private var selectDetailSideBarTarget - @Environment(\.removeDetailSideBarTarget) private var removeDetailSideBarTarget - @Environment(\.isDetailSideBarPresented) private var isDetailSideBarPresented - @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented - @State private var owner = UUID() + @State private var id = UUID() + // 화면을 벗어나 가려진 동안은 내용을 올리지 않음 + @State private var isAppeared = false let isActive: Bool - let sideBarContent: SideBarContent + let sideBarContent: () -> SideBarContent func body(content: Content) -> some View { - HStack(spacing: 0) { - content - if isActive && isDetailSideBarPresented && selectDetailSideBarTarget != nil { - DetailSideBar { - setDetailSideBarPresented?(false) - } content: { - sideBarContent - } - // 왼쪽 사이드바를 펴는 버튼은 창 오른쪽 사이드바 제목 줄에 두지 않음 - .environment(\.expandSideBar, nil) + // 세부 정보 사이드바 대상을 고를 수 없는 곳(상세 판, 좁은 창 시트)은 내용을 올리지 않음 + let isShown = isActive && isAppeared && selectDetailSideBarTarget != nil + + content + .transformPreference(DetailSideBarContentPreferenceKey.self) { value in + guard isShown, value == nil else { return } + value = DetailSideBarContent(id: id) { AnyView(sideBarContent()) } } - } - // 창이 그리는 사이드바 대신 이 화면의 사이드바 표시 - .onAppear { - if isActive { selectDetailSideBarTarget?(.hosted, owner) } - } - .onChange(of: isActive) { _, isActive in - selectDetailSideBarTarget?(isActive ? .hosted : nil, owner) - } - .onDisappear { removeDetailSideBarTarget?(owner) } + .onAppear { isAppeared = true } + .onDisappear { isAppeared = false } } } diff --git a/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift b/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift index b0d27a4f..1c629398 100644 --- a/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift +++ b/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift @@ -57,12 +57,6 @@ public extension EnvironmentValues { set { self[RemoveDetailSideBarTargetKey.self] = newValue } } - // 세부 정보 사이드바가 열려 있는지 여부 - var isDetailSideBarPresented: Bool { - get { self[IsDetailSideBarPresentedKey.self] } - set { self[IsDetailSideBarPresentedKey.self] = newValue } - } - // 세부 정보 사이드바를 열고 닫는 동작, 세부 정보 사이드바가 있는 창 안에서만 있음 var setDetailSideBarPresented: ((Bool) -> Void)? { get { self[SetDetailSideBarPresentedKey.self] } @@ -155,10 +149,6 @@ public extension EnvironmentValues { static let defaultValue: ((UUID) -> Void)? = nil } - private struct IsDetailSideBarPresentedKey: EnvironmentKey { - static let defaultValue = false - } - private struct SetDetailSideBarPresentedKey: EnvironmentKey { static let defaultValue: ((Bool) -> Void)? = nil } diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Editor/TodoEditorView.swift b/Application/Presentation/PresentationShared/Sources/Todo/Editor/TodoEditorView.swift index e51cfb16..991e11c4 100644 --- a/Application/Presentation/PresentationShared/Sources/Todo/Editor/TodoEditorView.swift +++ b/Application/Presentation/PresentationShared/Sources/Todo/Editor/TodoEditorView.swift @@ -59,7 +59,7 @@ public struct TodoEditorView: View { } .prominentAlert(store, state: \.alert, action: \.alert) // 사이드바가 있는 창은 작성 중인 속성을 세부 정보 사이드바에 표시 - .detailSideBar { + .compositionRight { ScrollView { TodoSideBarProperties( editorStore: store, From 9923f07779ab2abb8f0271a4ea71388b401ea903 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 02/25] =?UTF-8?q?refactor:=20Todo=20=EC=84=B8=EB=B6=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=82=AC=EC=9D=B4=EB=93=9C=EB=B0=94?= =?UTF-8?q?=EB=8F=84=20compositionRight=EB=A1=9C=20=EC=98=AC=EB=A6=AC?= =?UTF-8?q?=EA=B3=A0=20DetailSideBarTarget=EA=B3=BC=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=EA=B0=92=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Composition/CompositionView.swift | 19 ++--- .../Composition/DetailSideBarFeature.swift | 34 -------- .../Entry/Sources/Composition/TabScreen.swift | 5 +- .../DetailSideBarFeatureTests.swift | 77 ------------------- .../HomeTab/Sources/Home/HomeView.swift | 6 +- .../Record/GoalDetail/GoalDetailView.swift | 8 +- .../Sources/Todo/List/TodoListView.swift | 10 ++- .../Sources/PushNotificationListView.swift | 13 +++- .../Common/Component/DetailPanel.swift | 1 - .../Common/Component/DetailSideBar.swift | 62 +-------------- .../Extension/EnvironmentValues+.swift | 20 ----- .../Sources/Profile/ProfileView.swift | 21 +++-- .../TodayTab/Sources/TodayView.swift | 11 +-- 13 files changed, 54 insertions(+), 233 deletions(-) delete mode 100644 Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift index 82378cab..2d7f2a54 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift @@ -125,20 +125,15 @@ struct CompositionView: View { showsSideBar ? { store.send(.detailSideBar(.binding(.set(\.isPresented, $0)))) } : nil ) } right: { content in - // 탭 화면이 올린 내용이 있으면 그 내용, 없으면 고른 대상의 속성 표시 + // 탭 화면이 올린 내용, 올린 내용이 없으면 안내 표시 if showsSideBar && store.detailSideBar.isPresented { - if let content { - DetailSideBar { - store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) - } content: { + DetailSideBar { + store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) + } content: { + if let content { content - } - } else { - DetailSideBar( - target: store.detailSideBar.targets[selectedTab], - windowEvent: windowEvent - ) { - store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) + } else { + DetailSideBarPlaceholder() } } } diff --git a/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift b/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift index 72e3474c..efd0c4f5 100644 --- a/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift +++ b/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift @@ -13,47 +13,13 @@ struct DetailSideBarFeature { @ObservableState struct State: Equatable { var isPresented = false - // 탭마다 대상을 고르는 화면, 대상이 없어도 나타난 순서대로 위치 - var selections: [AppTab: [Selection]] = [:] - - // 탭마다 지금 고른 대상, 대상을 고른 화면 중 가장 나중에 나타난 화면의 대상 - var targets: [AppTab: DetailSideBarTarget] { - selections.compactMapValues { $0.last { $0.target != nil }?.target } - } - } - - struct Selection: Equatable { - let owner: UUID - var target: DetailSideBarTarget? } enum Action: BindableAction, Equatable { case binding(BindingAction) - case targetChanged(AppTab, DetailSideBarTarget?, owner: UUID) - case ownerRemoved(AppTab, owner: UUID) } var body: some ReducerOf { BindingReducer() - Reduce { state, action in - switch action { - case .binding: - break - case .targetChanged(let tab, let target, let owner): - // 대상을 바꿔도 화면이 나타난 순서의 자리 유지 - var selections = state.selections[tab, default: []] - if let index = selections.firstIndex(where: { $0.owner == owner }) { - selections[index].target = target - } else { - selections.append(Selection(owner: owner, target: target)) - } - state.selections[tab] = selections - case .ownerRemoved(let tab, let owner): - // 사라지는 화면은 자기 자리만 지우고, 그 아래 화면이 고른 대상을 다시 표시 - state.selections[tab]?.removeAll { $0.owner == owner } - } - - return .none - } } } diff --git a/Application/Presentation/Entry/Sources/Composition/TabScreen.swift b/Application/Presentation/Entry/Sources/Composition/TabScreen.swift index 4d02fd90..956707ac 100644 --- a/Application/Presentation/Entry/Sources/Composition/TabScreen.swift +++ b/Application/Presentation/Entry/Sources/Composition/TabScreen.swift @@ -25,9 +25,6 @@ struct TabScreen: View { content .environment(\.isTabContentActive, isVisible) .environment(\.sideBarRequest, store.sideBar.requests[tab]) - // 좁은 창에서도 고른 대상을 기록해 넓은 창으로 바뀌면 바로 세부 정보 사이드바에 표시 - .environment(\.selectDetailSideBarTarget) { store.send(.detailSideBar(.targetChanged(tab, $0, owner: $1))) } - .environment(\.removeDetailSideBarTarget) { store.send(.detailSideBar(.ownerRemoved(tab, owner: $0))) } // 고른 탭 화면이 올린 세부 정보 사이드바 내용만 창에 전달 .transformPreference(DetailSideBarContentPreferenceKey.self) { content in if !isSelected { @@ -63,7 +60,7 @@ struct TabScreen: View { windowEvent: windowEvent ) case .notification: - PushNotificationListView(isSelected: isSelected) + PushNotificationListView(isSelected: isSelected, windowEvent: windowEvent) case .profile: ProfileView( isSelected: isSelected, diff --git a/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift b/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift deleted file mode 100644 index 962171f1..00000000 --- a/Application/Presentation/Entry/Tests/Composition/DetailSideBarFeatureTests.swift +++ /dev/null @@ -1,77 +0,0 @@ -// -// DetailSideBarFeatureTests.swift -// EntryTests -// -// Created by opfic on 11/25/26. -// - -import Foundation -import PresentationShared -import Testing -@testable import Entry - -@MainActor -struct DetailSideBarFeatureTests { - @Test("DetailSideBarFeature는 사라지는 화면이 다른 화면이 고른 세부 정보 사이드바 대상을 지우지 않게 한다") - func DetailSideBarFeature는_사라지는_화면이_다른_화면이_고른_세부_정보_사이드바_대상을_지우지_않게_한다() async { - let store = TestStore(initialState: DetailSideBarFeature.State()) { - DetailSideBarFeature() - } - store.exhaustivity = .off(showSkippedAssertions: false) - let screen = DetailSideBarTarget.todo(id: "screen", isEditable: false) - let goal = UUID() - let category = UUID() - - await store.send(.targetChanged(.home, screen, owner: goal)) - await store.send(.targetChanged(.home, screen, owner: category)) - await store.send(.ownerRemoved(.home, owner: goal)) - - #expect(store.state.targets[.home] == screen) - - await store.send(.ownerRemoved(.home, owner: category)) - - #expect(store.state.targets[.home] == nil) - } - - @Test("DetailSideBarFeature는 위 화면이 사라지면 아래 화면이 고른 세부 정보 사이드바 대상을 다시 표시한다") - func DetailSideBarFeature는_위_화면이_사라지면_아래_화면이_고른_세부_정보_사이드바_대상을_다시_표시한다() async { - let store = TestStore(initialState: DetailSideBarFeature.State()) { - DetailSideBarFeature() - } - store.exhaustivity = .off(showSkippedAssertions: false) - let screen = DetailSideBarTarget.todo(id: "screen", isEditable: false) - let list = UUID() - let editor = UUID() - - await store.send(.targetChanged(.home, .todo(id: "todo", isEditable: true), owner: list)) - await store.send(.targetChanged(.home, screen, owner: editor)) - await store.send(.targetChanged(.home, .todo(id: "other", isEditable: true), owner: list)) - - #expect(store.state.targets[.home] == screen) - - await store.send(.ownerRemoved(.home, owner: editor)) - - #expect(store.state.targets[.home] == .todo(id: "other", isEditable: true)) - } - - @Test("DetailSideBarFeature는 먼저 나타난 화면이 나중에 대상을 골라도 나중에 나타난 화면의 대상을 유지한다") - func DetailSideBarFeature는_먼저_나타난_화면이_나중에_대상을_골라도_나중에_나타난_화면의_대상을_유지한다() async { - let store = TestStore(initialState: DetailSideBarFeature.State()) { - DetailSideBarFeature() - } - store.exhaustivity = .off(showSkippedAssertions: false) - let screen = DetailSideBarTarget.todo(id: "screen", isEditable: false) - let list = UUID() - let editor = UUID() - - await store.send(.targetChanged(.home, nil, owner: list)) - await store.send(.targetChanged(.home, screen, owner: editor)) - await store.send(.targetChanged(.home, .todo(id: "todo", isEditable: true), owner: list)) - - #expect(store.state.targets[.home] == screen) - - await store.send(.ownerRemoved(.home, owner: editor)) - - #expect(store.state.targets[.home] == .todo(id: "todo", isEditable: true)) - } -} diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index 1c9a3ba0..abb7bbb7 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -73,7 +73,7 @@ public struct HomeView: View { } else if usesDesktopLayout, let goalStore = store.scope(state: \.sheet?.goalDetailState, action: \.sheet.presented.goalDetail) { // 홈 자리에 개발 목표를 표시하고 기록 작성은 오른쪽 칸에 표시 - GoalDetailView(store: goalStore) + GoalDetailView(store: goalStore, windowEvent: windowEvent) .id(goalDetailID) } else if usesPaneLayout, let editorStore = store.scope( @@ -107,7 +107,7 @@ public struct HomeView: View { .hiddenInPane(usesDesktopLayout), interactivePop: true ) { goalStore in - GoalDetailView(store: goalStore) + GoalDetailView(store: goalStore, windowEvent: windowEvent) } } .desktopNavigationTransition() @@ -357,11 +357,9 @@ public struct HomeView: View { HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) } case .reorderTodo: if let manageStore = sheetStore.scope(state: \.categoryManageState, action: \.categoryManage) { - // 넓은 창으로 바뀌어 닫히는 시트가 칸으로 연 화면의 세부 정보 사이드바를 가져가지 않음 CategoryManageView(store: manageStore) { store.send(.sheet(.dismiss)) } - .environment(\.selectDetailSideBarTarget, nil) } case .goalCreate: if let goalStore = sheetStore.scope(state: \.goalCreateState, action: \.goalCreate) { diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index 474fe11b..2ac913a7 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -15,6 +15,7 @@ public struct GoalDetailView: View { @Environment(\.usesDesktopLayout) private var usesDesktopLayout @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac @Bindable var store: StoreOf + let windowEvent: TodoEditorWindowEvent public var body: some View { // 좁은 창은 홈 내비게이션에 쌓고, 사이드바가 있으면 홈 내비게이션 안의 칸으로 표시 @@ -135,7 +136,12 @@ public struct GoalDetailView: View { showsBackOnDesktop: true ) .environment(\.showsPaneTitleBar, usesDesktopLayout) - .detailSideBarTarget(.todo(id: $0.todoId, isEditable: false)) + .compositionRight { + if let todoId = store.todoDetail?.todoId { + TodoDetailSideBarView(todoId: todoId, isEditable: false, windowEvent: windowEvent) + .id(todoId) + } + } } .onAppear { store.send(.view(.appear(onDesktop: usesDesktopLayout))) } } diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift index 42396f59..f4cd2b4c 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift @@ -85,9 +85,13 @@ struct TodoListView: View { } ) } - .detailSideBarTarget( - store.selectedTodoId.map { .todo(id: $0, isEditable: true, revision: store.detailRevision) } - ) + // 옆 칸에 연 Todo의 속성은 세부 정보 사이드바에 표시하고, 목록에서 바꾸면 다시 조회 + .compositionRight(isActive: store.selectedTodoId != nil) { + if let todoId = store.selectedTodoId { + TodoDetailSideBarView(todoId: todoId, isEditable: true, windowEvent: windowEvent) + .id("\(todoId)-\(store.detailRevision)") + } + } .prominentAlert(store, state: \.alert, action: \.alert) .onReceive(windowSubmits) { _ in // 상세 칸에서 편집한 Todo를 옆 목록에도 반영 diff --git a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift index e834b0d6..0c03b002 100644 --- a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift +++ b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift @@ -13,8 +13,9 @@ public struct PushNotificationListView: View { @Environment(\.usesDesktopLayout) private var usesDesktopLayout @State private var store: StoreOf private let isSelected: Bool + private let windowEvent: TodoEditorWindowEvent - public init(isSelected: Bool) { + public init(isSelected: Bool, windowEvent: TodoEditorWindowEvent) { @Dependency(\.fetchPushNotificationQueryUseCase) var fetchQueryUseCase self._store = State(initialValue: Store( initialState: PushNotificationListFeature.State( @@ -24,6 +25,7 @@ public struct PushNotificationListView: View { PushNotificationListFeature() }) self.isSelected = isSelected + self.windowEvent = windowEvent } public var body: some View { @@ -49,9 +51,12 @@ public struct PushNotificationListView: View { ) } // 오른쪽 칸은 칸 제목 줄 정보 버튼 대신 창 오른쪽 세부 정보 사이드바에 속성 표시 - .detailSideBarTarget( - showsPane ? store.selectedTodoId.map { .todo(id: $0.id, isEditable: false) } : nil - ) + .compositionRight(isActive: showsPane && store.selectedTodoId != nil) { + if let todoId = store.selectedTodoId?.id { + TodoDetailSideBarView(todoId: todoId, isEditable: false, windowEvent: windowEvent) + .id(todoId) + } + } } .prominentAlert(store, state: \.alert, action: \.alert) .prominentSheet(item: sheetStore.activePresentation(when: isSelected && !usesDesktopLayout)) { store in diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/DetailPanel.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/DetailPanel.swift index bb5f5f27..4d804394 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/DetailPanel.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/DetailPanel.swift @@ -56,7 +56,6 @@ private struct DetailPanelFrame: View { // 판 안 제목 줄은 창 사이드바를 펴거나 세부 정보 사이드바를 여는 버튼 없이 표시 .environment(\.expandSideBar, nil) .environment(\.showDetailSideBar, nil) - .environment(\.selectDetailSideBarTarget, nil) .environment(\.windowControlsInset, 0) .environment(\.showsPaneTitleBar, false) .frame(maxWidth: .infinity, maxHeight: .infinity) diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift index 5e7de785..9729d9a7 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/DetailSideBar.swift @@ -7,13 +7,6 @@ import SwiftUI -// 세부 정보 사이드바에 속성을 표시할 대상 -public enum DetailSideBarTarget: Hashable { - // 고칠 수 없는 활동 기록 Todo는 읽기 전용 - // 다른 곳에서 바꾼 Todo를 다시 조회하도록 목록이 올리는 revision - case todo(id: String, isEditable: Bool, revision: Int = 0) -} - // 사이드바가 있는 창 오른쪽에 두는 세부 정보 사이드바 public struct DetailSideBar: View { private let onClose: () -> Void @@ -55,34 +48,6 @@ public struct DetailSideBar: View { } } -public extension DetailSideBar where Content == DetailSideBarTargetContent { - init( - target: DetailSideBarTarget?, - windowEvent: TodoEditorWindowEvent?, - onClose: @escaping () -> Void - ) { - self.init(onClose: onClose) { - DetailSideBarTargetContent(target: target, windowEvent: windowEvent) - } - } -} - -// 창이 그리는 사이드바의 대상별 내용 -public struct DetailSideBarTargetContent: View { - let target: DetailSideBarTarget? - let windowEvent: TodoEditorWindowEvent? - - public var body: some View { - switch target { - case .todo(let id, let isEditable, _): - TodoDetailSideBarView(todoId: id, isEditable: isEditable, windowEvent: windowEvent) - .id(target) - case nil: - DetailSideBarPlaceholder() - } - } -} - // 고른 대상이 없을 때의 안내 public struct DetailSideBarPlaceholder: View { public init() { } @@ -102,11 +67,6 @@ public struct DetailSideBarPlaceholder: View { } public extension View { - // 지금 고른 대상을 세부 정보 사이드바에 표시 - func detailSideBarTarget(_ target: DetailSideBarTarget?) -> some View { - modifier(DetailSideBarTargetModifier(target: target)) - } - // 이 화면의 세부 정보 사이드바 내용, 사이드바가 있는 창에서 SplitShell 오른쪽에 표시 // 화면은 내용만 올리고 사이드바는 CompositionView가 그림 func compositionRight( @@ -141,25 +101,7 @@ public struct DetailSideBarContentPreferenceKey: PreferenceKey { } } -private struct DetailSideBarTargetModifier: ViewModifier { - @Environment(\.selectDetailSideBarTarget) private var selectDetailSideBarTarget - @Environment(\.removeDetailSideBarTarget) private var removeDetailSideBarTarget - @State private var owner = UUID() - let target: DetailSideBarTarget? - - func body(content: Content) -> some View { - content - .onAppear { selectDetailSideBarTarget?(target, owner) } - .onChange(of: target) { _, target in - selectDetailSideBarTarget?(target, owner) - } - // 화면을 벗어나면 고른 대상 해제 - .onDisappear { removeDetailSideBarTarget?(owner) } - } -} - private struct CompositionRightModifier: ViewModifier { - @Environment(\.selectDetailSideBarTarget) private var selectDetailSideBarTarget @State private var id = UUID() // 화면을 벗어나 가려진 동안은 내용을 올리지 않음 @State private var isAppeared = false @@ -167,8 +109,8 @@ private struct CompositionRightModifier: ViewModifier { let sideBarContent: () -> SideBarContent func body(content: Content) -> some View { - // 세부 정보 사이드바 대상을 고를 수 없는 곳(상세 판, 좁은 창 시트)은 내용을 올리지 않음 - let isShown = isActive && isAppeared && selectDetailSideBarTarget != nil + // 상세 판과 시트는 따로 덮는 화면이라 그 안에서 올린 내용은 창까지 오지 않음 + let isShown = isActive && isAppeared content .transformPreference(DetailSideBarContentPreferenceKey.self) { value in diff --git a/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift b/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift index 1c629398..d0392795 100644 --- a/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift +++ b/Application/Presentation/PresentationShared/Sources/Extension/EnvironmentValues+.swift @@ -45,18 +45,6 @@ public extension EnvironmentValues { set { self[ExpandSideBarKey.self] = newValue } } - // 고른 대상과 고른 화면을 세부 정보 사이드바에 알리는 동작, 메인 창 탭 화면 안에서만 있음 - var selectDetailSideBarTarget: ((DetailSideBarTarget?, UUID) -> Void)? { - get { self[SelectDetailSideBarTargetKey.self] } - set { self[SelectDetailSideBarTargetKey.self] = newValue } - } - - // 화면이 사라질 때 세부 정보 사이드바에서 그 화면을 빼는 동작, 메인 창 탭 화면 안에서만 있음 - var removeDetailSideBarTarget: ((UUID) -> Void)? { - get { self[RemoveDetailSideBarTargetKey.self] } - set { self[RemoveDetailSideBarTargetKey.self] = newValue } - } - // 세부 정보 사이드바를 열고 닫는 동작, 세부 정보 사이드바가 있는 창 안에서만 있음 var setDetailSideBarPresented: ((Bool) -> Void)? { get { self[SetDetailSideBarPresentedKey.self] } @@ -141,14 +129,6 @@ public extension EnvironmentValues { static let defaultValue: (() -> Void)? = nil } - private struct SelectDetailSideBarTargetKey: EnvironmentKey { - static let defaultValue: ((DetailSideBarTarget?, UUID) -> Void)? = nil - } - - private struct RemoveDetailSideBarTargetKey: EnvironmentKey { - static let defaultValue: ((UUID) -> Void)? = nil - } - private struct SetDetailSideBarPresentedKey: EnvironmentKey { static let defaultValue: ((Bool) -> Void)? = nil } diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index fa54593f..f13c582b 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -86,15 +86,20 @@ public struct ProfileView: View { TodoDetailPane(todoId: nil, showEditButton: false) } } - .detailSideBarTarget(store.selectedTodoRoute?.detailSideBarTarget) + .compositionRight(isActive: store.selectedTodoRoute?.todo != nil) { + if let todo = store.selectedTodoRoute?.todo { + TodoDetailSideBarView(todoId: todo.id, isEditable: todo.isEditable, windowEvent: windowEvent) + .id(todo.id) + } + } // 좁은 창으로 바뀌면 상세 판을 숨기고 넓어지면 다시 표시 .detailPanel(item: $store.panelTodoRoute.activePresentation(when: isSelected && usesDesktopLayout)) { route in - if case .todo(let todoId, let isEditable, _)? = route.detailSideBarTarget { + if let todo = route.todo { TodoDetailPanel( - todoId: todoId, + todoId: todo.id, location: Text("nav_profile", bundle: PresentationResources.bundle), - isEditable: isEditable, - windowEvent: isEditable ? windowEvent : nil, + isEditable: todo.isEditable, + windowEvent: todo.isEditable ? windowEvent : nil, onMoveToPane: { store.send(.binding(.set(\.panelTodoRoute, nil))) store.send(.binding(.set(\.selectedTodoRoute, route))) @@ -341,10 +346,10 @@ public enum ProfileRoute: Hashable, Identifiable { private extension ProfileRoute { // 활동 기록 Todo는 고칠 수 없어 읽기 전용으로 표시 - var detailSideBarTarget: DetailSideBarTarget? { + var todo: (id: String, isEditable: Bool)? { switch self { - case .activity(let todoId): .todo(id: todoId, isEditable: false) - case .recentTodo(let todoId): .todo(id: todoId, isEditable: true) + case .activity(let todoId): (todoId, false) + case .recentTodo(let todoId): (todoId, true) default: nil } } diff --git a/Application/Presentation/TodayTab/Sources/TodayView.swift b/Application/Presentation/TodayTab/Sources/TodayView.swift index 492d520c..02df6acd 100644 --- a/Application/Presentation/TodayTab/Sources/TodayView.swift +++ b/Application/Presentation/TodayTab/Sources/TodayView.swift @@ -163,11 +163,12 @@ public struct TodayView: View { } : nil ) } - .detailSideBarTarget( - sections.flatMap(\.items) - .first { $0.id == store.selectedTodoId } - .map { .todo(id: $0.id, isEditable: true) } - ) + .compositionRight(isActive: sections.flatMap(\.items).contains { $0.id == store.selectedTodoId }) { + if let todoId = store.selectedTodoId { + TodoDetailSideBarView(todoId: todoId, isEditable: true, windowEvent: windowEvent) + .id(todoId) + } + } .navigationDestination( for: TodayRoute.self, interactivePop: { _ in true }, From 75a531e7ea5886f408251a1bd2e872638c8b34f1 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 03/25] =?UTF-8?q?refactor:=20CompositionContainer=EC=97=90?= =?UTF-8?q?=20compositionEditor,=20compositionSheet,=20compositionCenter?= =?UTF-8?q?=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98=EA=B3=A0=20=ED=99=88?= =?UTF-8?q?=EA=B3=BC=20=ED=95=98=EC=9C=84=20=ED=99=94=EB=A9=B4=EC=97=90=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Category/CategoryManageView.swift | 22 +-- .../HomeTab/Sources/Home/HomeView.swift | 123 +++++++--------- .../Record/Detail/RecordDetailView.swift | 11 +- .../Record/GoalDetail/GoalDetailView.swift | 12 +- .../Sources/Todo/List/TodoListView.swift | 3 +- .../Component/CompositionContainer.swift | 138 ++++++++++++++++++ 6 files changed, 205 insertions(+), 104 deletions(-) create mode 100644 Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift diff --git a/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift b/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift index 8b81d551..b23a7330 100644 --- a/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift +++ b/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift @@ -102,26 +102,18 @@ struct CategoryManageView: View { } .background((usesDesktopLayout ? Color.background : .secondaryBackground).ignoresSafeArea()) // 사이드바가 있으면 고른 카테고리를 시트 대신 세부 정보 사이드바에 표시 - .prominentSheet( - item: $store.scope(state: \.categorySheet, action: \.categorySheet) - .activePresentation(when: isTabContentActive && !usesDesktopLayout) - ) { sheetStore in + .compositionSheet(item: $store.scope(state: \.categorySheet, action: \.categorySheet)) { sheetStore in CategoryManageSheet(store: sheetStore) - } - .prominentAlert(store, state: \.alert, action: \.alert) - .compositionRight(isActive: usesDesktopLayout) { - if let sheetStore = store.scope(state: \.categorySheet, action: \.categorySheet.presented) { - ScrollView { - CategoryEditForm(store: sheetStore) { - if let item = store.preferences.first(where: { $0.id == sheetStore.category.id }) { - store.send(.tapDeleteUserCategory(item)) - } + } right: { sheetStore in + ScrollView { + CategoryEditForm(store: sheetStore) { + if let item = store.preferences.first(where: { $0.id == sheetStore.category.id }) { + store.send(.tapDeleteUserCategory(item)) } } - } else { - DetailSideBarPlaceholder() } } + .prominentAlert(store, state: \.alert, action: \.alert) // 카테고리 관리를 벗어나면 카테고리를 보여 주던 세부 정보 사이드바도 닫음 .onChange(of: isTabContentActive) { _, isActive in if usesDesktopLayout && !isActive { diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index abb7bbb7..631045b3 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -55,41 +55,43 @@ public struct HomeView: View { .activePresentation(when: isSelected) NavigationStack(path: $router.path) { - Group { - if usesDesktopLayout, - let manageStore = store.scope(state: \.sheet?.categoryManageState, action: \.sheet.presented.categoryManage) { - CategoryManageView(store: manageStore) - } else if usesDesktopLayout, - let goalStore = store.scope(state: \.sheet?.goalCreateState, action: \.sheet.presented.goalCreate) { - // 홈 오른쪽 칸에서 쓰고 연결된 Todo는 세부 정보 사이드바에 표시 - PaneSplitView { - homeContent - } detail: { - GoalCreateView(store: goalStore) - } - .compositionRight { - GoalCreateSideBarContent(store: goalStore) - } - } else if usesDesktopLayout, - let goalStore = store.scope(state: \.sheet?.goalDetailState, action: \.sheet.presented.goalDetail) { - // 홈 자리에 개발 목표를 표시하고 기록 작성은 오른쪽 칸에 표시 - GoalDetailView(store: goalStore, windowEvent: windowEvent) - .id(goalDetailID) - } else if usesPaneLayout, - let editorStore = store.scope( - state: \.fullScreenCover?.todoEditor, - action: \.fullScreenCover.presented.todoEditor - ) { - // 홈 오른쪽 칸에서 새 Todo 작성 - PaneSplitView { - homeContent - } detail: { - TodoEditorView(store: editorStore, onClose: { store.send(.fullScreenCover(.dismiss)) }) - } - } else { - homeContent + // 사이드바가 있으면 새 개발 목표와 새 Todo를 홈 오른쪽 칸에서 작성 + PaneSplitView(splitsOnDesktop: store.sheet?.goalCreateState != nil || store.showTodoEditor) { + homeContent + } detail: { + if let goalStore = store.scope(state: \.sheet?.goalCreateState, action: \.sheet.presented.goalCreate) { + GoalCreateView(store: goalStore) + } else if let editorStore = store.scope( + state: \.fullScreenCover?.todoEditor, + action: \.fullScreenCover.presented.todoEditor + ) { + TodoEditorView(store: editorStore, onClose: { store.send(.fullScreenCover(.dismiss)) }) } } + // 새 개발 목표에 연결한 Todo는 세부 정보 사이드바에 표시 + .compositionRight(isActive: store.sheet?.goalCreateState != nil) { + if let goalStore = store.scope(state: \.sheet?.goalCreateState, action: \.sheet.presented.goalCreate) { + GoalCreateSideBarContent(store: goalStore) + } + } + // 사이드바가 있으면 카테고리 관리를 시트 대신 홈 자리에 표시 + .compositionCenter( + item: $store.scope(state: \.sheet?.categoryManageState, action: \.sheet.categoryManage), + narrow: .sheet, + isActive: isSelected + ) { manageStore in + CategoryManageView(store: manageStore) { + store.send(.sheet(.dismiss)) + } + } + // 좁은 창은 개발 목표를 홈 내비게이션에 쌓고, 넓어지면 같은 상태를 홈 자리에 표시하고 기록 작성은 오른쪽 칸에 표시 + .compositionCenter( + item: $store.scope(state: \.sheet?.goalDetailState, action: \.sheet.goalDetail), + narrow: .push + ) { goalStore in + GoalDetailView(store: goalStore, windowEvent: windowEvent) + .id(goalDetailID) + } .navigationDestination( for: HomeRoute.self, interactivePop: { @@ -101,14 +103,6 @@ public struct HomeView: View { }, destination: { destinationView($0).environment(\.showsPaneTitleBar, usesPaneLayout) } ) - // 좁은 창은 개발 목표를 홈 내비게이션에 쌓고, 넓어지면 같은 상태를 홈 자리에 표시 - .navigationDestination( - item: $store.scope(state: \.sheet?.goalDetailState, action: \.sheet.goalDetail) - .hiddenInPane(usesDesktopLayout), - interactivePop: true - ) { goalStore in - GoalDetailView(store: goalStore, windowEvent: windowEvent) - } } .desktopNavigationTransition() // 사이드바 구조로 바뀌면 쌓아 연 Todo 상세는 내리고 카테고리 목록 옆 칸에 표시 @@ -156,12 +150,10 @@ public struct HomeView: View { } } .prominentAlert(store, state: \.alert, action: \.alert) + // 좁은 창의 새로 만들기 .prominentSheet( item: Binding( - get: { - showsSheetAsPane || showsPickerAsPopover || goalDetailID != nil - ? nil : sheetBinding.wrappedValue - }, + get: { store.showContentPicker && !showsPickerAsPopover ? sheetBinding.wrappedValue : nil }, // 앞 시트가 늦게 닫히며 보내는 닫힘이 칸이나 팝오버로 연 화면을 지우지 않도록 지금 상태로 판단 set: { sheet in // 내비게이션에 쌓은 개발 목표는 시트 닫힘으로 지우지 않음 @@ -174,13 +166,21 @@ public struct HomeView: View { guard !(usesPaneLayout && store.showContentPicker) else { return } sheetBinding.wrappedValue = sheet } - ), - content: sheetContent - ) - .fullScreenCover( + ) + ) { _ in + HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) } + } + // 좁은 창은 새 개발 목표를 닫기, 저장 버튼으로만 닫는 시트로 작성 + .compositionEditor( + item: $store.scope(state: \.sheet?.goalCreateState, action: \.sheet.goalCreate) + .activePresentation(when: isSelected), + narrow: .sheet + ) { goalStore in + GoalCreateView(store: goalStore) + } + .compositionEditor( item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover) - .activePresentation(when: isSelected) - .hiddenInPane(usesPaneLayout && store.showTodoEditor), + .activePresentation(when: isSelected), content: coverContent ) } @@ -350,27 +350,6 @@ public struct HomeView: View { } } - @ViewBuilder - private func sheetContent(_ sheetStore: Store) -> some View { - switch sheetStore.state { - case .contentPicker: - HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) } - case .reorderTodo: - if let manageStore = sheetStore.scope(state: \.categoryManageState, action: \.categoryManage) { - CategoryManageView(store: manageStore) { - store.send(.sheet(.dismiss)) - } - } - case .goalCreate: - if let goalStore = sheetStore.scope(state: \.goalCreateState, action: \.goalCreate) { - GoalCreateView(store: goalStore) - } - case .goalDetail: - // 개발 목표는 시트 대신 홈 내비게이션에 쌓음 - EmptyView() - } - } - @ViewBuilder private func coverContent( _ coverStore: Store diff --git a/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift index 8f92c003..345ae29c 100644 --- a/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift @@ -63,15 +63,8 @@ public struct RecordDetailView: View { .duoToolbarVisibility(showsBackButton: true) .onAppear { store.send(.view(.appear(onDesktop: usesDesktopLayout))) } .prominentAlert(store, state: \.alert, action: \.alert) - // 좁은 창의 기록 정정은 닫기·저장·확정 버튼으로만 닫는 전체 화면 - .fullScreenCover( - item: editor.hiddenInPane { usesDesktopLayout || isHidden() } - ) { _ in - correctionEditor - } - .prominentSheet( - item: editor.hiddenInPane { !usesDesktopLayout || isHidden() } - ) { _ in + // 기록 정정은 좁은 창에서 닫기, 저장, 확정 버튼으로만 닫는 전체 화면이고 넓은 창에서 시트 + .compositionEditor(item: editor.hiddenInPane(isHidden), inPane: false) { _ in correctionEditor } .navigationDestination( diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index 2ac913a7..1f012f1e 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -75,11 +75,10 @@ public struct GoalDetailView: View { ) } } - // 좁은 창은 닫기·저장·확정 버튼으로만 닫는 전체 화면 - // 넓은 창으로 바뀌어 칸에 옮겨 그린 뒤 늦게 닫히는 전체 화면은 작성 중인 기록을 지우지 않음 - .fullScreenCover( + // 좁은 창은 닫기, 저장, 확정 버튼으로만 닫는 전체 화면 + .compositionEditor( item: $store.scope(state: \.recordEditor, action: \.recordEditor) - .hiddenInPane { usesDesktopLayout || store.shownOnDesktop == true } + .hiddenInPane { store.shownOnDesktop == true } ) { editorStore in RecordEditorView( store: editorStore, @@ -92,9 +91,10 @@ public struct GoalDetailView: View { GoalTodoLinkSheet(store: $0) } // 좁은 창은 새 개발 목표와 같은 시트로 수정하고 닫기, 저장 버튼으로만 닫음 - .prominentSheet( + .compositionEditor( item: $store.scope(state: \.goalEdit, action: \.goalEdit) - .hiddenInPane { usesDesktopLayout || store.shownOnDesktop == true } + .hiddenInPane { store.shownOnDesktop == true }, + narrow: .sheet ) { GoalCreateView(store: $0) } diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift index f4cd2b4c..3e00efbc 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift @@ -97,10 +97,9 @@ struct TodoListView: View { // 상세 칸에서 편집한 Todo를 옆 목록에도 반영 store.send(.view(.windowTodoUpdated)) } - .fullScreenCover( + .compositionEditor( item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover) .activePresentation(when: isTabContentActive) - .hiddenInPane(usesPaneLayout) ) { coverStore in fullScreenCoverContent(coverStore) } diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift new file mode 100644 index 00000000..aa9f9b2a --- /dev/null +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -0,0 +1,138 @@ +// +// CompositionContainer.swift +// PresentationShared +// +// Created by opfic on 11/27/26. +// + +import SwiftUI + +// 좁은 창에서 띄우는 컨테이너 +public enum CompositionNarrow { + case sheet + case cover + case push +} + +public extension View { + // 저장이나 닫기 버튼으로만 닫는 작성 화면 + // 좁은 창은 전체 화면이나 시트로 띄우고, 사이드바가 있는 창은 PaneSplitView의 detail이 그림 + // inPane이 거짓이면 사이드바가 있는 창에서도 시트로 띄움 + func compositionEditor( + item: Binding, + narrow: CompositionNarrow = .cover, + inPane: Bool = true, + @ViewBuilder content: @escaping (Item) -> Content + ) -> some View { + modifier(CompositionEditorModifier(item: item, narrow: narrow, inPane: inPane, editor: content)) + } + + // 바꾸면 바로 저장하는 시트 + // 좁은 창은 시트로 띄우고, 사이드바가 있는 창은 SplitShell 오른쪽 세부 정보 사이드바에 표시 + func compositionSheet( + item: Binding, + @ViewBuilder sheet: @escaping (Item) -> Sheet, + @ViewBuilder right: @escaping (Item) -> Right + ) -> some View { + modifier(CompositionSheetModifier(item: item, sheet: sheet, right: right)) + } + + // 좁은 창은 시트로 띄우거나 내비게이션에 쌓고, 사이드바가 있는 창은 이 화면 대신 내비게이션 루트에 그림 + // isActive가 거짓이면 좁은 창에서 띄우지 않음 + func compositionCenter( + item: Binding, + narrow: CompositionNarrow, + isActive: Bool = true, + @ViewBuilder content: @escaping (Item) -> Content + ) -> some View { + modifier(CompositionCenterModifier(item: item, narrow: narrow, isActive: isActive, center: content)) + } +} + +private struct CompositionEditorModifier: ViewModifier { + @Environment(\.usesDesktopLayout) private var usesDesktopLayout + let item: Binding + let narrow: CompositionNarrow + let inPane: Bool + let editor: (Item) -> Editor + + func body(content: Content) -> some View { + // 넓은 창으로 바뀌어 칸에 옮겨 그린 뒤 늦게 닫히는 화면은 작성 중인 초안을 지우지 않음 + let narrowItem = item.hiddenInPane(usesDesktopLayout) + + switch (narrow, inPane) { + case (.cover, true): + content + .fullScreenCover(item: narrowItem, content: editor) + case (.sheet, true): + content + .prominentSheet(item: narrowItem, content: editor) + case (.cover, false): + content + .fullScreenCover(item: narrowItem, content: editor) + .prominentSheet(item: item.hiddenInPane(!usesDesktopLayout), content: editor) + case (.sheet, false): + content + .prominentSheet(item: item, content: editor) + case (.push, _): + content + .navigationDestination(item: narrowItem, interactivePop: true, destination: editor) + } + } +} + +private struct CompositionCenterModifier: ViewModifier { + @Environment(\.usesDesktopLayout) private var usesDesktopLayout + let item: Binding + let narrow: CompositionNarrow + let isActive: Bool + let center: (Item) -> Center + + func body(content: Content) -> some View { + // 창 폭이 바뀌어도 좁은 창의 표시를 같은 화면에 두어, 넓어진 뒤 늦게 닫히는 표시가 상태를 지우지 않음 + let narrowItem = item.activePresentation(when: isActive).hiddenInPane(usesDesktopLayout) + let shown = Group { + if usesDesktopLayout, let value = item.wrappedValue { + center(value) + } else { + content + } + } + + switch narrow { + case .sheet: + shown + .prominentSheet(item: narrowItem, content: center) + case .cover: + shown + .fullScreenCover(item: narrowItem, content: center) + case .push: + shown + .navigationDestination(item: narrowItem, interactivePop: true, destination: center) + } + } +} + +private struct CompositionSheetModifier: ViewModifier { + @Environment(\.isTabContentActive) private var isTabContentActive + @Environment(\.usesDesktopLayout) private var usesDesktopLayout + let item: Binding + let sheet: (Item) -> Sheet + let right: (Item) -> Right + + func body(content: Content) -> some View { + content + .prominentSheet( + item: item.activePresentation(when: isTabContentActive && !usesDesktopLayout), + content: sheet + ) + // 고른 항목이 없으면 세부 정보 사이드바에 안내 표시 + .compositionRight(isActive: usesDesktopLayout) { + if let value = item.wrappedValue { + right(value) + } else { + DetailSideBarPlaceholder() + } + } + } +} From 7717fa2085a99758af958ebb1dcb2c0806e63981 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 04/25] =?UTF-8?q?refactor:=20compositionDetail=EC=9D=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EA=B3=A0=20=EA=B0=9C=EB=B0=9C=20?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=EC=9D=98=20=EA=B8=B0=EB=A1=9D=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=EC=99=80=20=EB=B2=84=EC=A0=84=20=EC=9D=B4=EB=A0=A5?= =?UTF-8?q?=EC=97=90=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Record/GoalDetail/GoalDetailView.swift | 14 ++---- .../History/RecordVersionHistoryView.swift | 12 ++---- .../Component/CompositionContainer.swift | 43 +++++++++++++++++++ 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index 1f012f1e..0ee16761 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -98,20 +98,14 @@ public struct GoalDetailView: View { ) { GoalCreateView(store: $0) } - .navigationDestination( - item: $store.scope(state: \.recordDetail, action: \.recordDetail) - .hiddenInPane { usesDesktopLayout || isHidden() }, - interactivePop: true + // 사이드바가 있는 창은 기록을 사이드바까지 덮는 상세 판으로 열고 버전 이력은 판 안에서 이동 + .compositionDetail( + item: $store.scope(state: \.recordDetail, action: \.recordDetail).hiddenInPane(isHidden) ) { _ in if let detailStore = store.scope(state: \.recordDetailContent, action: \.recordDetailContent) { RecordDetailView(store: detailStore, onUpdate: { store.send(.view(.refresh)) }) } - } - // 사이드바가 있는 창은 기록을 사이드바까지 덮는 상세 판으로 열고 버전 이력은 판 안에서 이동 - .detailPanel( - item: $store.scope(state: \.recordDetail, action: \.recordDetail) - .hiddenInPane { !usesDesktopLayout || isHidden() } - ) { _ in + } panel: { _ in NavigationStack { if let detailStore = store.scope(state: \.recordDetailContent, action: \.recordDetailContent) { RecordDetailView(store: detailStore, onUpdate: { store.send(.view(.refresh)) }) diff --git a/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift b/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift index 9b72c7b3..7bc2f227 100644 --- a/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift @@ -64,19 +64,13 @@ struct RecordVersionHistoryView: View { .safeAreaInset(edge: .top, spacing: 0) { topBar } .background(Color.background.ignoresSafeArea()) .duoToolbarVisibility(showsBackButton: true) - .navigationDestination( - item: versionDetail.hiddenInPane { usesDesktopLayout || isHidden() }, - interactivePop: true - ) { destination in + // 사이드바가 있는 창은 이전 버전을 사이드바까지 덮는 상세 판으로 열기 + .compositionDetail(item: versionDetail.hiddenInPane(isHidden)) { destination in RecordVersionDetailView( store: store, version: destination.version ) - } - // 사이드바가 있는 창은 이전 버전을 사이드바까지 덮는 상세 판으로 열기 - .detailPanel( - item: versionDetail.hiddenInPane { !usesDesktopLayout || isHidden() } - ) { destination in + } panel: { destination in RecordVersionDetailView( store: store, version: destination.version diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index aa9f9b2a..9cfa59d0 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -15,6 +15,19 @@ public enum CompositionNarrow { } public extension View { + // 읽는 화면 + // 좁은 창은 내비게이션에 쌓거나 시트로 띄우고, 사이드바가 있는 창은 사이드바까지 덮는 상세 판으로 띄움 + // inPane이 참이면 사이드바가 있는 창에서 상세 판 대신 PaneSplitView의 detail이 그림 + func compositionDetail( + item: Binding, + narrow: CompositionNarrow = .push, + inPane: Bool = false, + @ViewBuilder content: @escaping (Item) -> Content, + @ViewBuilder panel: @escaping (Item) -> Panel + ) -> some View { + modifier(CompositionDetailModifier(item: item, narrow: narrow, inPane: inPane, detail: content, panel: panel)) + } + // 저장이나 닫기 버튼으로만 닫는 작성 화면 // 좁은 창은 전체 화면이나 시트로 띄우고, 사이드바가 있는 창은 PaneSplitView의 detail이 그림 // inPane이 거짓이면 사이드바가 있는 창에서도 시트로 띄움 @@ -49,6 +62,36 @@ public extension View { } } +private struct CompositionDetailModifier: ViewModifier { + @Environment(\.usesDesktopLayout) private var usesDesktopLayout + let item: Binding + let narrow: CompositionNarrow + let inPane: Bool + let detail: (Item) -> Detail + let panel: (Item) -> Panel + + func body(content: Content) -> some View { + // 창 폭이 바뀌면 같은 상태를 짝이 되는 컨테이너가 다시 그리고, 빠지는 쪽의 늦은 닫힘은 상태를 지우지 않음 + let narrowItem = item.hiddenInPane(usesDesktopLayout) + let panelItem = item.hiddenInPane(!usesDesktopLayout || inPane) + + switch narrow { + case .push: + content + .navigationDestination(item: narrowItem, interactivePop: true, destination: detail) + .detailPanel(item: panelItem, content: panel) + case .sheet: + content + .prominentSheet(item: narrowItem, content: detail) + .detailPanel(item: panelItem, content: panel) + case .cover: + content + .fullScreenCover(item: narrowItem, content: detail) + .detailPanel(item: panelItem, content: panel) + } + } +} + private struct CompositionEditorModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout let item: Binding From 1ef398bd779727d6786d52d92104cc428274cbb7 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 05/25] =?UTF-8?q?refactor:=20Todo=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=EA=B3=BC=20=EA=B2=80=EC=83=89=EC=9D=98=20Todo=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=EB=A5=BC=20TodoListFeature,=20SearchFeature=EC=9D=98?= =?UTF-8?q?=20detail=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HomeTab/Sources/Home/HomeView.swift | 22 +---- .../Record/GoalDetail/GoalDetailFeature.swift | 18 ++-- .../Record/GoalDetail/GoalDetailView.swift | 12 +-- .../Sources/Search/SearchFeature.swift | 13 ++- .../HomeTab/Sources/Search/SearchView.swift | 39 +++------ .../Todo/List/TodoListFeature+Effects.swift | 7 +- .../Sources/Todo/List/TodoListFeature.swift | 33 ++++++-- .../Sources/Todo/List/TodoListView.swift | 80 ++++++++---------- .../Record/GoalDetailTodoFeatureTests.swift | 2 +- .../Todo/TodoListFeatureTestDoubles.swift | 23 +++++- .../Tests/Todo/TodoListFeatureTests.swift | 50 +++++++---- .../Component/CompositionContainer.swift | 18 +++- .../Todo/Detail/TodoDetailFeature.swift | 28 +++++-- .../Sources/Todo/Detail/TodoDetailPanel.swift | 82 ++++++++----------- .../Todo/Detail/TodoDetailSideBarView.swift | 6 ++ 15 files changed, 229 insertions(+), 204 deletions(-) diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index 631045b3..c18e067e 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -97,7 +97,6 @@ public struct HomeView: View { interactivePop: { switch $0 { case .category: true - case .todo: true case .search: true } }, @@ -105,13 +104,6 @@ public struct HomeView: View { ) } .desktopNavigationTransition() - // 사이드바 구조로 바뀌면 쌓아 연 Todo 상세는 내리고 카테고리 목록 옆 칸에 표시 - .closesPushedDetail { - router.path.removeAll { - if case .todo = $0 { return true } - return false - } - } .preference(key: SideBarLocationPreferenceKey.self, value: sideBarLocation) .preference( key: SideBarContentPreferenceKey.self, @@ -370,29 +362,17 @@ public struct HomeView: View { store: Store(initialState: TodoListFeature.State(category: item.todoCategory)) { TodoListFeature() }, - windowEvent: windowEvent, - onSelectTodo: { router.push(.todo(TodoIdItem(id: $0))) } - ) - .id(item.id) - case .todo(let item): - TodoDetailView( - store: Store( - initialState: TodoDetailFeature.State(todoId: item.id, showEditButton: true) - ) { - TodoDetailFeature() - }, windowEvent: windowEvent ) .id(item.id) case .search: - SearchView(isOnTop: router.path.last == .search) { router.push(.todo(TodoIdItem(id: $0))) } + SearchView(windowEvent: windowEvent) } } } public enum HomeRoute: Hashable { case category(TodoCategoryItem) - case todo(TodoIdItem) case search } diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift index 69c0ffa7..d4ccfb33 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift @@ -32,7 +32,8 @@ struct GoalDetailFeature { // 넓은 창의 칸과 시트가 같은 상태를 그려 창 폭이 바뀌어도 작성 중인 기록 유지 @Presents var recordEditor: RecordEditorFeature.State? @Presents var recordDetail: RecordDetailDestination? - @Presents var todoDetail: TodoDetailDestination? + // 연결한 Todo 상세, 창 폭과 상관없이 개발 목표 위에 쌓음 + @Presents var todoDetail: TodoDetailFeature.State? @Presents var todoLinkSheet: GoalTodoLinkFeature.State? // 창 폭이 바뀌어 기록 상세 표시가 잠깐 닫혀도 진행 중인 조회·되돌리기와 안에서 연 화면을 잃지 않도록 따로 보관하는 상세 상태 var recordDetailContent: RecordDetailFeature.State? @@ -81,7 +82,7 @@ struct GoalDetailFeature { case recordEditor(PresentationAction) case recordDetail(PresentationAction) case recordDetailContent(RecordDetailFeature.Action) - case todoDetail(PresentationAction) + case todoDetail(PresentationAction) case todoLinkSheet(PresentationAction) case binding(BindingAction) case view(ViewAction) @@ -163,8 +164,6 @@ struct GoalDetailFeature { } case .recordDetail, .recordDetailContent: break - case .todoDetail(.dismiss): - state.todoDetail = nil case .todoDetail: break case .todoLinkSheet(.dismiss), @@ -288,7 +287,7 @@ struct GoalDetailFeature { case .view(.selectTodo(let todoId)): guard state.linkedTodos.contains(where: { $0.id == todoId }), state.todoDetail == nil else { break } - state.todoDetail = TodoDetailDestination(todoId: todoId) + state.todoDetail = TodoDetailFeature.State(todoId: todoId, showEditButton: false) case .view(.selectStatus(let status)): guard let goalStatus = state.goalStatus, !state.isLoading, @@ -348,6 +347,9 @@ struct GoalDetailFeature { .ifLet(\.$todoLinkSheet, action: \.todoLinkSheet) { GoalTodoLinkFeature() } + .ifLet(\.$todoDetail, action: \.todoDetail) { + TodoDetailFeature() + } } } @@ -437,9 +439,3 @@ struct RecordDetailDestination: Equatable, Identifiable { var id: String { record.id } let record: DevelopmentRecord } - -@ObservableState -struct TodoDetailDestination: Equatable, Identifiable { - var id: String { todoId } - let todoId: String -} diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index 0ee16761..f97274f3 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -118,17 +118,7 @@ public struct GoalDetailView: View { interactivePop: true ) { // 사이드바가 있으면 Todo 목록 옆 칸의 상세와 같은 칸 모양으로 표시하고 뒤로 가면 개발 목표로 돌아감 - TodoDetailView( - store: Store( - initialState: TodoDetailFeature.State( - todoId: $0.todoId, - showEditButton: false - ) - ) { - TodoDetailFeature() - }, - showsBackOnDesktop: true - ) + TodoDetailView(store: $0, showsBackOnDesktop: true) .environment(\.showsPaneTitleBar, usesDesktopLayout) .compositionRight { if let todoId = store.todoDetail?.todoId { diff --git a/Application/Presentation/HomeTab/Sources/Search/SearchFeature.swift b/Application/Presentation/HomeTab/Sources/Search/SearchFeature.swift index 9bcdbe0f..8228234b 100644 --- a/Application/Presentation/HomeTab/Sources/Search/SearchFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Search/SearchFeature.swift @@ -15,14 +15,14 @@ struct SearchFeature { @ObservableState struct State: Equatable { @Presents var alert: AlertState? + // 연 결과 상세, 좁은 창은 홈 내비게이션에 쌓고 사이드바가 있는 창은 사이드바까지 덮는 상세 판에 표시 + @Presents var detail: TodoDetailFeature.State? var loading = LoadingFeature.State() var isSearching = false var searchQuery = "" var todos: [SearchTodoItem] = [] var recentQueries = OrderedSet() var showAllTodos = false - // Mac에서 사이드바까지 덮는 상세 판에 연 Todo - var panelTodo: TodoIdItem? let contentsLimit = 5 init(recentQueries: [String] = []) { @@ -53,7 +53,9 @@ struct SearchFeature { enum Action: BindableAction, Equatable { case onAppear case alert(PresentationAction) + case detail(PresentationAction) case binding(BindingAction) + case selectTodo(String) case addRecentQuery(String) case removeRecentQuery(String) case clearRecentQueries @@ -97,6 +99,10 @@ struct SearchFeature { } case .alert: break + case .detail: + break + case .selectTodo(let todoId): + state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: true) case .binding(\.isSearching): if !state.isSearching { return Self.cancelSearchEffect(isLoading: state.isLoading) @@ -151,6 +157,9 @@ struct SearchFeature { return .none } .ifLet(\.$alert, action: \.alert) + .ifLet(\.$detail, action: \.detail) { + TodoDetailFeature() + } } } diff --git a/Application/Presentation/HomeTab/Sources/Search/SearchView.swift b/Application/Presentation/HomeTab/Sources/Search/SearchView.swift index 8a496aa1..8492fa50 100644 --- a/Application/Presentation/HomeTab/Sources/Search/SearchView.swift +++ b/Application/Presentation/HomeTab/Sources/Search/SearchView.swift @@ -17,14 +17,12 @@ struct SearchView: View { @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.deviceType) private var deviceType @State private var store: StoreOf - // 홈 내비게이션에 쌓아 연 검색에서 Todo 상세를 홈 내비게이션에 쌓는 동작 - private let onSelectTodo: (String) -> Void - // 홈 내비게이션 맨 위에 있는지 여부, 아래에 깔린 동안은 상세 판을 띄우지 않음 - private let isOnTop: Bool + // 좁은 창에서 쌓아 연 결과 상세의 편집을 Mac 편집 창과 같은 경로로 전달 + private let windowEvent: TodoEditorWindowEvent? // 열 때마다 빈 입력칸으로 시작하고 최근 검색은 열 때 읽음 - // 닫으면 Store와 함께 진행 중인 검색 요청과 상세 판도 사라짐 - init(isOnTop: Bool, onSelectTodo: @escaping (String) -> Void) { + // 닫으면 Store와 함께 진행 중인 검색 요청과 상세도 사라짐 + init(windowEvent: TodoEditorWindowEvent?) { @Dependency(\.homeFetchRecentSearchQueriesUseCase) var fetchRecentSearchQueriesUseCase self._store = State(initialValue: Store( initialState: SearchFeature.State( @@ -33,26 +31,14 @@ struct SearchView: View { ) { SearchFeature() }) - self.onSelectTodo = onSelectTodo - self.isOnTop = isOnTop + self.windowEvent = windowEvent } var body: some View { content { todoId in - // 사이드바가 있는 창은 사이드바까지 덮는 상세 판으로 열기 - // 좁은 창에서 쌓아 연 상세도 기억해 넓어지면 같은 Todo를 상세 판으로 표시 - store.send(.binding(.set(\.panelTodo, TodoIdItem(id: todoId)))) - if !usesDesktopLayout { - onSelectTodo(todoId) - } + store.send(.selectTodo(todoId)) } .duoToolbarVisibility(showsBackButton: true) - // 좁은 창에서 쌓아 연 결과 상세를 내리면 넓어져도 상세 판으로 다시 열지 않음 - .onAppear { - if !usesDesktopLayout { - store.send(.binding(.set(\.panelTodo, nil))) - } - } } private func content(onSelectTodo: @escaping (String) -> Void) -> some View { @@ -90,13 +76,14 @@ struct SearchView: View { } .background(Color.background.ignoresSafeArea()) .prominentAlert(store, state: \.alert, action: \.alert) - // 좁은 창으로 바뀌면 상세 판을 숨기고 넓어지면 다시 표시 - // 쌓아 연 상세를 편집하는 중에 넓어지면 편집을 마치고 상세가 내려간 뒤 표시 - .detailPanel(item: $store.panelTodo.activePresentation(when: usesDesktopLayout && isOnTop)) { item in + // 좁은 창은 홈 내비게이션에 쌓고, 사이드바가 있는 창은 사이드바까지 덮는 상세 판에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail(item: $store.scope(state: \.detail, action: \.detail)) { detailStore in + TodoDetailView(store: detailStore, windowEvent: windowEvent) + } panel: { detailStore in TodoDetailPanel( - todoId: item.id, - location: Text("search_title", bundle: PresentationResources.bundle), - isEditable: true + store: detailStore, + location: Text("search_title", bundle: PresentationResources.bundle) ) } } diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature+Effects.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature+Effects.swift index ad1f5cdc..31a479f6 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature+Effects.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature+Effects.swift @@ -74,9 +74,10 @@ extension TodoListFeature { func swipeTodoEffect(_ todo: TodoListItem, state: inout State) -> Effect { guard state.todos.contains(where: { $0.id == todo.id }) else { return .none } state.undoTodoId = todo.id - // 지운 Todo의 상세 칸은 되돌리기와 관계없이 바로 닫음 - if state.selectedTodoId == todo.id { - state.selectedTodoId = nil + // 지운 Todo의 상세는 되돌리기와 관계없이 바로 닫음 + if state.detail?.todoId == todo.id { + state.detail = nil + state.showsDetailInPane = false } Self.setTodoHidden(&state, todoId: todo.id, isHidden: true) return deleteEffect(todo) diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift index dc3cc309..bb4182da 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift @@ -17,6 +17,10 @@ struct TodoListFeature { struct State: Equatable { @Presents var alert: AlertState? @Presents var fullScreenCover: FullScreenCoverState? + // 연 Todo 상세, 좁은 창은 내비게이션에 쌓고 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + @Presents var detail: TodoDetailFeature.State? + // 사이드바가 있는 창에서 상세 판 대신 목록 오른쪽 칸에 표시 + var showsDetailInPane = false var category: TodoCategory var todos: [TodoListItem] = [] var query: TodoQuery @@ -24,12 +28,8 @@ struct TodoListFeature { var isSearching = false var loading = LoadingFeature.State() var searchQuery = "" - var selectedTodoId: String? - // 사이드바가 있는 창에서 사이드바까지 덮는 상세 판에 연 Todo - var panelTodo: TodoIdItem? // Mac에서 마우스를 올린 행, 선택 행처럼 둥글게 표시하고 맞닿는 구분선을 숨김 var hoveredTodoId: String? - var detailRevision = 0 var undoTodoId: String? var nextCursor: TodoCursor? @@ -74,6 +74,7 @@ struct TodoListFeature { enum Action: BindableAction { case alert(PresentationAction) case fullScreenCover(PresentationAction) + case detail(PresentationAction) case binding(BindingAction) case view(ViewAction) case store(StoreAction) @@ -86,6 +87,9 @@ struct TodoListFeature { enum ViewAction: Equatable { case refresh + // 사이드바가 있는 창은 연 곳(상세 판이나 오른쪽 칸)의 내용을 바꿈 + case selectTodo(String) + case openTodo(String, inPane: Bool) case swipeTodo(TodoListItem) case resetFilters case finishDeleteToast(String) @@ -147,6 +151,10 @@ struct TodoListFeature { state.fullScreenCover = nil case .fullScreenCover: break + case .detail(.dismiss): + state.showsDetailInPane = false + case .detail: + break case .binding(\.query.sortTarget), .binding(\.query.sortOrder), .binding(\.query.isPinned), .binding(\.query.completionFilter): state.nextCursor = nil @@ -187,6 +195,9 @@ struct TodoListFeature { .ifLet(\.$fullScreenCover, action: \.fullScreenCover) { FullScreenCoverFeature() } + .ifLet(\.$detail, action: \.detail) { + TodoDetailFeature() + } } } @@ -302,6 +313,14 @@ private extension TodoListFeature { switch action { case .refresh: return fetchEffect(query: state.query, cursor: nil, showsIndicator: false) + case .selectTodo(let todoId): + // 이미 연 Todo는 불러온 상세와 열어 둔 시트를 그대로 둠 + if state.detail?.todoId != todoId { + state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: true) + } + case .openTodo(let todoId, let inPane): + state.showsDetailInPane = inPane + return reduce(.selectTodo(todoId), state: &state) case .onAppear: return fetchEffect(query: state.query, cursor: nil) case .windowTodoUpdated: @@ -369,9 +388,9 @@ private extension TodoListFeature { if let index = state.todos.firstIndex(where: { $0.id == todo.id }) { state.todos[index] = todo } - // 상세 칸이 바뀐 완료·중요 상태를 다시 조회하도록 갱신 - if todo.id == state.selectedTodoId { - state.detailRevision += 1 + // 연 상세와 세부 정보 사이드바가 바뀐 완료, 중요 상태를 다시 조회 + if todo.id == state.detail?.todoId { + return .send(.detail(.presented(.fetch))) } case .setTodoHidden(let todoId, let isHidden): Self.setTodoHidden(&state, todoId: todoId, isHidden: isHidden) diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift index 3e00efbc..00b35531 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift @@ -17,32 +17,17 @@ struct TodoListView: View { @Environment(\.usesPaneLayout) private var usesPaneLayout @State private var store: StoreOf private let windowEvent: TodoEditorWindowEvent? - private let onSelectTodo: (String) -> Void - init( - store: StoreOf, - windowEvent: TodoEditorWindowEvent? = nil, - onSelectTodo: @escaping (String) -> Void = { _ in } - ) { + init(store: StoreOf, windowEvent: TodoEditorWindowEvent? = nil) { self.store = store self.windowEvent = windowEvent - self.onSelectTodo = onSelectTodo } var body: some View { // 사이드바가 있는 창은 목록을 창 전체 폭으로 두고 오른쪽 칸에서 연 Todo나 작성 화면이 있을 때만 두 칸으로 나눔 - PaneSplitView(splitsOnDesktop: store.selectedTodoId != nil || store.fullScreenCover != nil) { + PaneSplitView(splitsOnDesktop: store.showsDetailInPane && store.detail != nil || store.fullScreenCover != nil) { TodoListContent(store: store) { todoId in - // 사이드바가 있는 창은 오른쪽 칸을 열지 않았으면 상세 판으로 열고 열었으면 오른쪽 칸 내용을 바꿈 - if usesDesktopLayout && store.selectedTodoId == nil { - store.send(.binding(.set(\.panelTodo, TodoIdItem(id: todoId)))) - return - } - // 칸 화면으로 바뀌면 같은 Todo를 옆 칸에 표시하도록 칸으로 나누지 않은 화면에서도 선택 기억 - store.send(.binding(.set(\.selectedTodoId, todoId))) - if !usesPaneLayout { - onSelectTodo(todoId) - } + store.send(.view(.selectTodo(todoId))) } } detail: { // 칸으로 나눈 화면은 새 Todo를 덮는 화면 대신 상세 칸 자리에서 작성 @@ -52,44 +37,53 @@ struct TodoListView: View { action: \.fullScreenCover.presented.todoEditor ) { TodoEditorView(store: editorStore, onClose: { store.send(.fullScreenCover(.dismiss)) }) - } else { - TodoDetailPane( - todoId: store.selectedTodoId, - showEditButton: true, + } else if store.showsDetailInPane, + let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + TodoDetailView( + store: detailStore, windowEvent: windowEvent, - onClose: usesDesktopLayout ? { store.send(.binding(.set(\.selectedTodoId, nil))) } : nil + isPaneDetail: true, + onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil ) - .id(store.detailRevision) + .environment(\.showsPaneTitleBar, true) + // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 + .id(detailStore.todoId) + } else { + PanePlaceholder() } } - // 좁은 창으로 바뀌면 상세 판을 숨기고 넓어지면 다시 표시 - .detailPanel(item: $store.panelTodo.activePresentation(when: isTabContentActive && usesDesktopLayout)) { item in + // 좁은 창은 목록 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + inPane: store.showsDetailInPane, + isActive: isTabContentActive + ) { detailStore in + TodoDetailView(store: detailStore, windowEvent: windowEvent) + } panel: { detailStore in // 목록에서 빠진 Todo는 지울 경로가 없어 판 메뉴에서 삭제 생략 - let todo = store.todos.first { $0.id == item.id } + let todo = store.todos.first { $0.id == detailStore.todoId } TodoDetailPanel( - todoId: item.id, + store: detailStore, location: Text(TodoCategoryItem(from: store.category).localizedName), - isEditable: true, windowEvent: windowEvent, onMoveToPane: { - store.send(.binding(.set(\.panelTodo, nil))) - store.send(.binding(.set(\.selectedTodoId, item.id))) + store.send(.binding(.set(\.showsDetailInPane, true))) }, onDelete: todo.map { todo in { - store.send(.binding(.set(\.panelTodo, nil))) store.send(.view(.swipeTodo(todo))) presentDeleteTodoToast(todo.id, store: store) } } ) } - // 옆 칸에 연 Todo의 속성은 세부 정보 사이드바에 표시하고, 목록에서 바꾸면 다시 조회 - .compositionRight(isActive: store.selectedTodoId != nil) { - if let todoId = store.selectedTodoId { - TodoDetailSideBarView(todoId: todoId, isEditable: true, windowEvent: windowEvent) - .id("\(todoId)-\(store.detailRevision)") + // 옆 칸에 연 Todo의 속성은 세부 정보 사이드바에 표시 + .compositionRight(isActive: store.showsDetailInPane && store.detail != nil) { + if let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + TodoDetailSideBarView(store: detailStore) + .id(detailStore.todoId) } } .prominentAlert(store, state: \.alert, action: \.alert) @@ -105,12 +99,6 @@ struct TodoListView: View { } .background(Color.background.ignoresSafeArea()) .task { store.send(.view(.onAppear)) } - // 좁은 창에서 쌓아 연 상세를 내리면 넓어져도 오른쪽 칸으로 다시 열지 않음 - .onAppear { - if !usesDesktopLayout { - store.send(.binding(.set(\.selectedTodoId, nil))) - } - } } private var windowSubmits: AnyPublisher { @@ -156,7 +144,7 @@ private struct TodoListContent: View { } else { // 칸으로 나누지 않은 화면은 상세 칸이 없어 선택 표시 생략 let highlightedTodoIds = ( - [store.hoveredTodoId] + (usesPaneLayout ? [store.selectedTodoId, store.panelTodo?.id] : []) + [store.hoveredTodoId] + (usesPaneLayout ? [store.detail?.todoId] : []) ).compactMap { $0 } LazyVStack(alignment: .leading, spacing: 0) { @@ -198,7 +186,7 @@ private struct TodoListContent: View { // 사이드바가 있는 창의 우클릭과 길게 누른 메뉴는 상세 판과 오른쪽 칸으로 여는 항목을 맨 위에 표시 if usesDesktopLayout { Button { - store.send(.binding(.set(\.panelTodo, TodoIdItem(id: todo.id)))) + store.send(.view(.openTodo(todo.id, inPane: false))) } label: { Label { Text("detail_panel_open", bundle: PresentationResources.bundle) @@ -207,7 +195,7 @@ private struct TodoListContent: View { } } Button { - store.send(.binding(.set(\.selectedTodoId, todo.id))) + store.send(.view(.openTodo(todo.id, inPane: true))) } label: { Label { Text("detail_panel_open_in_pane", bundle: PresentationResources.bundle) diff --git a/Application/Presentation/HomeTab/Tests/Record/GoalDetailTodoFeatureTests.swift b/Application/Presentation/HomeTab/Tests/Record/GoalDetailTodoFeatureTests.swift index a264e8ca..74140fb3 100644 --- a/Application/Presentation/HomeTab/Tests/Record/GoalDetailTodoFeatureTests.swift +++ b/Application/Presentation/HomeTab/Tests/Record/GoalDetailTodoFeatureTests.swift @@ -90,7 +90,7 @@ struct GoalDetailTodoFeatureTests { } await store.send(.view(.selectTodo(todo.id))) { - $0.todoDetail = TodoDetailDestination(todoId: todo.id) + $0.todoDetail = TodoDetailFeature.State(todoId: todo.id, showEditButton: false) } } diff --git a/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTestDoubles.swift b/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTestDoubles.swift index f746e701..7d3b5902 100644 --- a/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTestDoubles.swift +++ b/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTestDoubles.swift @@ -29,8 +29,8 @@ final class TodoListStoreTestAdapter { } var showAlert: Bool { store.state.alert != nil } var appliedFilterCount: Int { store.state.appliedFilterCount } - var selectedTodoId: String? { store.state.selectedTodoId } - var detailRevision: Int { store.state.detailRevision } + var detailTodoId: String? { store.state.detail?.todoId } + var showsDetailInPane: Bool { store.state.showsDetailInPane } init( fetchUseCase: FetchTodosUseCase = TodoListFetchTodosUseCaseSpy(), @@ -51,6 +51,7 @@ final class TodoListStoreTestAdapter { $0.todoListDeleteTodoUseCase = deleteUseCase $0.todoListUndoDeleteTodoUseCase = undoDeleteUseCase $0.trackAnalyticsEventUseCase = trackAnalyticsEventUseCase + $0.fetchReferenceItemsUseCase = TodoListFetchReferenceItemsUseCaseStub() $0.continuousClock = ContinuousClock() configureDependencies?(&$0) } @@ -153,8 +154,16 @@ final class TodoListStoreTestAdapter { await store.send(.view(.finishDeleteToast(todoId))) } - func selectTodo(_ todoId: String?) async { - await store.send(.binding(.set(\.selectedTodoId, todoId))) + func selectTodo(_ todoId: String) async { + await store.send(.view(.selectTodo(todoId))) + } + + func openTodo(_ todoId: String, inPane: Bool) async { + await store.send(.view(.openTodo(todoId, inPane: inPane))) + } + + func dismissDetail() async { + await store.send(.detail(.dismiss)) } func tapToggleCompleted(_ todo: TodoListItem) async { @@ -296,6 +305,12 @@ final class TodoListFetchTodoByIdUseCaseSpy: FetchTodoByIdUseCase { } } +final class TodoListFetchReferenceItemsUseCaseStub: FetchReferenceItemsUseCase { + func execute(_ numbers: [Int]) async throws -> [Int: TodoReference] { + [:] + } +} + final class TodoListUpsertTodoUseCaseSpy: UpsertTodoUseCase { var error: Error? var completion: AsyncStream? diff --git a/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTests.swift b/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTests.swift index 980c7bc7..3b671934 100644 --- a/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTests.swift +++ b/Application/Presentation/HomeTab/Tests/Todo/TodoListFeatureTests.swift @@ -370,34 +370,56 @@ struct TodoListFeatureTests { #expect(adapter.todos.isEmpty) } - @Test("swipeTodo는 선택한 Todo를 지울 때만 선택을 해제한다") - func swipeTodo는_선택한_Todo를_지울_때만_선택을_해제한다() async { + @Test("swipeTodo는 연 Todo를 지울 때만 상세를 닫는다") + func swipeTodo는_연_Todo를_지울_때만_상세를_닫는다() async { let selected = TodoListItem(from: makeTodoListTodo(id: "todo-selected"))! let other = TodoListItem(from: makeTodoListTodo(id: "todo-other"))! let adapter = TodoListStoreTestAdapter() await adapter.appendTodos([selected, other]) - await adapter.selectTodo("todo-selected") + await adapter.openTodo("todo-selected", inPane: true) await adapter.swipeTodo(other) - #expect(adapter.selectedTodoId == "todo-selected") + #expect(adapter.detailTodoId == "todo-selected") + #expect(adapter.showsDetailInPane) await adapter.swipeTodo(selected) - #expect(adapter.selectedTodoId == nil) + #expect(adapter.detailTodoId == nil) + #expect(!adapter.showsDetailInPane) await adapter.undoDelete() - #expect(adapter.selectedTodoId == nil) + #expect(adapter.detailTodoId == nil) } - @Test("tapToggleCompleted는 선택한 Todo일 때만 상세 칸을 다시 조회하도록 갱신한다") - func tapToggleCompleted는_선택한_Todo일_때만_상세_칸을_다시_조회하도록_갱신한다() async { + @Test("selectTodo는 연 자리를 유지하고, 상세를 닫으면 오른쪽 칸 표시도 끈다") + func selectTodo는_연_자리를_유지하고_상세를_닫으면_오른쪽_칸_표시도_끈다() async { + let adapter = TodoListStoreTestAdapter() + + await adapter.selectTodo("todo-a") + + #expect(adapter.detailTodoId == "todo-a") + #expect(!adapter.showsDetailInPane) + + await adapter.openTodo("todo-b", inPane: true) + await adapter.selectTodo("todo-c") + + #expect(adapter.detailTodoId == "todo-c") + #expect(adapter.showsDetailInPane) + + await adapter.dismissDetail() + + #expect(adapter.detailTodoId == nil) + #expect(!adapter.showsDetailInPane) + } + + @Test("tapToggleCompleted는 연 Todo일 때만 상세를 다시 조회한다") + func tapToggleCompleted는_연_Todo일_때만_상세를_다시_조회한다() async { let todo = makeTodoListTodo(id: "todo-toggle", isPinned: false, isCompleted: false) let item = TodoListItem(from: todo)! - let adapter = TodoListStoreTestAdapter( - fetchTodoByIdUseCase: TodoListFetchTodoByIdUseCaseSpy(todos: [todo]) - ) + let fetchByIdSpy = TodoListFetchTodoByIdUseCaseSpy(todos: [todo]) + let adapter = TodoListStoreTestAdapter(fetchTodoByIdUseCase: fetchByIdSpy) await adapter.appendTodos([item]) await adapter.tapToggleCompleted(item) @@ -406,16 +428,16 @@ struct TodoListFeatureTests { adapter.todos.first?.isCompleted == true } - #expect(adapter.detailRevision == 0) + #expect(fetchByIdSpy.todoIds == ["todo-toggle"]) await adapter.selectTodo("todo-toggle") await adapter.tapToggleCompleted(adapter.todos[0]) await waitUntil { - adapter.detailRevision == 1 + fetchByIdSpy.todoIds.count == 3 } - #expect(adapter.detailRevision == 1) + #expect(fetchByIdSpy.todoIds == ["todo-toggle", "todo-toggle", "todo-toggle"]) } @Test("tapToggleCompleted와 tapTogglePinned는 조회한 Todo를 갱신해 목록에 반영한다") diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index 9cfa59d0..1427a61f 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -18,14 +18,23 @@ public extension View { // 읽는 화면 // 좁은 창은 내비게이션에 쌓거나 시트로 띄우고, 사이드바가 있는 창은 사이드바까지 덮는 상세 판으로 띄움 // inPane이 참이면 사이드바가 있는 창에서 상세 판 대신 PaneSplitView의 detail이 그림 + // isActive가 거짓이면 창 위에 덮는 시트와 상세 판은 띄우지 않고, 내비게이션에 쌓은 화면은 그대로 둠 func compositionDetail( item: Binding, narrow: CompositionNarrow = .push, inPane: Bool = false, + isActive: Bool = true, @ViewBuilder content: @escaping (Item) -> Content, @ViewBuilder panel: @escaping (Item) -> Panel ) -> some View { - modifier(CompositionDetailModifier(item: item, narrow: narrow, inPane: inPane, detail: content, panel: panel)) + modifier(CompositionDetailModifier( + item: item, + narrow: narrow, + inPane: inPane, + isActive: isActive, + detail: content, + panel: panel + )) } // 저장이나 닫기 버튼으로만 닫는 작성 화면 @@ -67,13 +76,14 @@ private struct CompositionDetailModifier let narrow: CompositionNarrow let inPane: Bool + let isActive: Bool let detail: (Item) -> Detail let panel: (Item) -> Panel func body(content: Content) -> some View { // 창 폭이 바뀌면 같은 상태를 짝이 되는 컨테이너가 다시 그리고, 빠지는 쪽의 늦은 닫힘은 상태를 지우지 않음 let narrowItem = item.hiddenInPane(usesDesktopLayout) - let panelItem = item.hiddenInPane(!usesDesktopLayout || inPane) + let panelItem = item.activePresentation(when: isActive).hiddenInPane(!usesDesktopLayout || inPane) switch narrow { case .push: @@ -82,11 +92,11 @@ private struct CompositionDetailModifier? @Presents public var sheet: SheetState? @Presents public var fullScreenCover: FullScreenCoverState? @@ -26,6 +26,8 @@ public struct TodoDetailFeature { // 좁은 창 세부 정보 시트의 속성 // 시트를 닫아도 저장 결과를 받도록 시트 밖에서 소유 var info: TodoDetailSideBarFeature.State + // 상세 판 안 오른쪽 세부 정보 열을 연 동안 + var isDetailColumnPresented = false public init(todoId: String, showEditButton: Bool) { self.todoId = todoId @@ -33,6 +35,11 @@ public struct TodoDetailFeature { self.info = TodoDetailSideBarFeature.State(todoId: todoId, isEditable: showEditButton) } + // 다른 Todo로 바꾸면 띄운 화면을 새로 만들어 그 Todo를 조회 + public var id: String { + todoId + } + public var isLoading: Bool { loading.isLoading } @@ -84,11 +91,13 @@ public struct TodoDetailFeature { } } - public enum Action { + public enum Action: Equatable { case alert(PresentationAction) case sheet(PresentationAction) case fullScreenCover(PresentationAction) case onAppear + // 화면을 다시 그려도 불러온 Todo를 유지하고, 다른 곳에서 바꾼 Todo는 여는 화면이 다시 조회 + case fetch case fetchFailed case setSheet(SheetState?) case setFullScreenCover(FullScreenCoverState?) @@ -96,15 +105,16 @@ public struct TodoDetailFeature { case setReferenceItems([Int: TodoReferenceItem]) case loading(LoadingFeature.Action) case info(TodoDetailSideBarFeature.Action) + case setDetailColumnPresented(Bool) @CasePathable - public enum Sheet { + public enum Sheet: Equatable { case tapCloseButton case todo(TodoDetailFeature.Action) } @CasePathable - public enum FullScreenCover { + public enum FullScreenCover: Equatable { case todoEditor(TodoEditorFeature.Action) } } @@ -146,6 +156,10 @@ public struct TodoDetailFeature { case .fullScreenCover: break case .onAppear: + // 좁은 창과 넓은 창의 화면을 오가도 같은 상태를 이어 그리므로 처음 한 번만 조회 + guard state.todo == nil else { break } + return fetchTodoEffect(todoId: state.todoId) + case .fetch: return fetchTodoEffect(todoId: state.todoId) case .fetchFailed: state.alert = Self.alertState() @@ -181,13 +195,15 @@ public struct TodoDetailFeature { state.referenceItems = [:] return resolveMarkdownEffect(content: todo.content) case .info(.editor(.saveFailed)): - // 시트를 닫은 뒤 실패한 저장은 상세 화면에서 알림 - if state.sheet != .info { + // 시트를 닫은 뒤 실패한 저장은 상세 화면에서 알림, 상세 판 세부 정보 열에서 실패한 저장은 열에서 알림 + if state.sheet != .info && !state.isDetailColumnPresented { state.info.editor?.alert = nil state.alert = Self.alertState() } case .info: break + case .setDetailColumnPresented(let isPresented): + state.isDetailColumnPresented = isPresented } return .none diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift index 8f2d37e8..cbbba673 100644 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift +++ b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift @@ -6,47 +6,63 @@ // import SwiftUI -import Combine import ComposableArchitecture // 사이드바가 있는 창의 상세 판에 연 보기 전용 Todo // 위쪽 막대의 버튼으로 판 안 오른쪽 세부 정보 열을 열고 닫음 +// 판 메뉴의 중요 표시와 완료도 세부 정보 열과 같은 속성 상태로 바로 저장 public struct TodoDetailPanel: View { @Environment(\.dismiss) private var dismiss - @State private var store: StoreOf + @State private var store: StoreOf private let location: Text private let windowEvent: TodoEditorWindowEvent? // 목록 | 상세 두 칸을 쓰는 화면만 오른쪽 칸으로 옮기기 표시 private let onMoveToPane: (() -> Void)? private let onDelete: (() -> Void)? + // 상세 상태는 연 화면의 Feature가 갖고, 창 폭이 바뀌면 같은 상태를 다른 화면이 이어 그림 public init( - todoId: String, + store: StoreOf, location: Text, - isEditable: Bool, windowEvent: TodoEditorWindowEvent? = nil, onMoveToPane: (() -> Void)? = nil, onDelete: (() -> Void)? = nil ) { - self._store = State(initialValue: Store( - initialState: TodoDetailPanelFeature.State(todoId: todoId, isEditable: isEditable) - ) { - TodoDetailPanelFeature() - }) + self._store = State(initialValue: store) self.location = location self.windowEvent = windowEvent self.onMoveToPane = onMoveToPane self.onDelete = onDelete } + // 프로필 탭이 상세 상태를 Feature로 옮기기 전까지 Todo 식별자로 상세 상태를 만들어 여는 init + public init( + todoId: String, + location: Text, + isEditable: Bool, + windowEvent: TodoEditorWindowEvent? = nil, + onMoveToPane: (() -> Void)? = nil, + onDelete: (() -> Void)? = nil + ) { + self.init( + store: Store(initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: isEditable)) { + TodoDetailFeature() + }, + location: location, + windowEvent: windowEvent, + onMoveToPane: onMoveToPane, + onDelete: onDelete + ) + } + public var body: some View { VStack(spacing: 0) { DetailPanelBar( location: location, - title: Text(verbatim: store.detail.todo.map { "#\($0.number)" } ?? "") + title: Text(verbatim: store.todo.map { "#\($0.number)" } ?? "") ) { Button { - store.send(.binding(.set(\.isDetailColumnPresented, !store.isDetailColumnPresented))) + store.send(.setDetailColumnPresented(!store.isDetailColumnPresented)) } label: { Image(systemName: "sidebar.right") } @@ -56,10 +72,7 @@ public struct TodoDetailPanel: View { } HStack(spacing: 0) { - TodoDetailView( - store: store.scope(state: \.detail, action: \.detail), - windowEvent: windowEvent - ) + TodoDetailView(store: store, windowEvent: windowEvent) if store.isDetailColumnPresented { VStack(spacing: 0) { PaneTitleBar(background: .secondaryBackground) { @@ -67,11 +80,8 @@ public struct TodoDetailPanel: View { } actions: { EmptyView() } - // 저장 결과 전달과 다른 곳에서 고친 값 반영은 판이 맡음 - TodoDetailSideBarView( - store: store.scope(state: \.sideBar, action: \.sideBar), - windowEvent: nil - ) + // 저장 결과 전달과 다른 곳에서 고친 값 반영은 판 안 상세가 맡음 + TodoDetailSideBarView(store: store) } .frame(width: 280 * AdaptiveSize.boardScale) .background(Color.secondaryBackground) @@ -83,32 +93,8 @@ public struct TodoDetailPanel: View { } } } - // 세부 정보 열을 닫아 둔 동안 판 메뉴로 저장하다 실패하면 판에서 알림 표시 - .background { - if !store.isDetailColumnPresented, - let editorStore = store.scope(state: \.sideBar.editor, action: \.sideBar.editor) { - Color.clear - .prominentAlert(editorStore, state: \.alert, action: \.alert) - } - } // 세부 정보 열을 닫아 둔 동안에도 판 메뉴로 중요 표시와 완료를 바꾸도록 속성을 불러옴 - .onAppear { store.send(.sideBar(.onAppear)) } - .onChange(of: store.sideBar.editor?.saveResult) { _, result in - // 판에서 저장한 Todo를 목록과 판 상세에도 반영 - guard case .updated(let todo)? = result else { return } - windowEvent?.submitUpdate(value: TodoEditorWindowValue(todo: todo), todo: todo) - } - .onReceive(windowSubmits) { submit in - // 판이 저장해 보낸 Todo는 다시 받지 않음 - guard case .update(let value, let todo) = submit, - value.matchesEdit(todoId: store.sideBar.todoId), - store.sideBar.editor?.saveResult != .updated(todo) else { return } - store.send(.sideBar(.setTodo(todo))) - } - } - - private var windowSubmits: AnyPublisher { - windowEvent?.submits ?? Empty().eraseToAnyPublisher() + .onAppear { store.send(.info(.onAppear)) } } @ViewBuilder @@ -123,9 +109,9 @@ public struct TodoDetailPanel: View { } Divider() } - if store.sideBar.isEditable, let editor = store.sideBar.editor { + if store.info.isEditable, let editor = store.info.editor { Button { - store.send(.sideBar(.editor(.binding(.set(\.isPinned, !editor.isPinned))))) + store.send(.info(.editor(.binding(.set(\.isPinned, !editor.isPinned))))) } label: { Label { Text(editor.isPinned ? "todo_action_unpin" : "todo_action_pin", bundle: PresentationResources.bundle) @@ -134,7 +120,7 @@ public struct TodoDetailPanel: View { } } Button { - store.send(.sideBar(.editor(.binding(.set(\.isCompleted, !editor.isCompleted))))) + store.send(.info(.editor(.binding(.set(\.isCompleted, !editor.isCompleted))))) } label: { Label { Text( diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailSideBarView.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailSideBarView.swift index a005b745..4d15b4ff 100644 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailSideBarView.swift +++ b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailSideBarView.swift @@ -28,6 +28,12 @@ public struct TodoDetailSideBarView: View { self.windowEvent = windowEvent } + // 열어 둔 Todo 상세와 속성 상태를 함께 쓰는 세부 정보 열 + // 저장 결과 전달과 다른 곳에서 고친 값 반영은 상세 화면이 맡음 + public init(store: StoreOf) { + self.init(store: store.scope(state: \.info, action: \.info), windowEvent: nil) + } + // 상세 판과 세부 정보 시트처럼 바깥 화면이 속성 상태를 함께 쓰는 세부 정보 열 init( store: StoreOf, From a79143975764eabaa626c313f09e6568f9c8d483 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 06/25] =?UTF-8?q?refactor:=20=EC=98=A4=EB=8A=98=20?= =?UTF-8?q?=ED=83=AD=20Todo=20=EC=83=81=EC=84=B8=EB=A5=BC=20TodayFeature?= =?UTF-8?q?=EC=9D=98=20detail=EB=A1=9C=20=EC=98=AE=EA=B8=B0=EA=B3=A0=20Tod?= =?UTF-8?q?ayRoute=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TodayTab/Sources/TodayFeature+State.swift | 11 +- .../TodayTab/Sources/TodayFeature.swift | 56 +++++++--- .../TodayTab/Sources/TodayRoute.swift | 12 --- .../TodayTab/Sources/TodayView.swift | 102 ++++++------------ .../Tests/TodayFeatureTestAssertions.swift | 2 +- .../Tests/TodayFeatureTestDoubles.swift | 20 +++- .../Tests/TodayFeatureTestSpies.swift | 6 ++ .../TodayTab/Tests/TodayFeatureTests.swift | 42 ++++++-- 8 files changed, 144 insertions(+), 107 deletions(-) delete mode 100644 Application/Presentation/TodayTab/Sources/TodayRoute.swift diff --git a/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift b/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift index 666f4ce4..62a058f3 100644 --- a/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift +++ b/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift @@ -33,6 +33,8 @@ extension TodayFeature { @ObservableState struct State: Equatable { @Presents var alert: AlertState? + // 연 Todo 상세, 좁은 창은 내비게이션에 쌓고 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + @Presents var detail: TodoDetailFeature.State? var todos = [TodayTodoItem]() var completedTodayTodos = [TodayTodoItem]() var categories = [TodoCategoryItem]() @@ -40,15 +42,12 @@ extension TodayFeature { var selectedCategoryID: String? var isCategoryFilterPresented = false var isTodoInspectorPresented = false + // 세부 정보 사이드바에 표시하는 Todo, 오른쪽 칸을 열면 칸의 Todo와 같음 var selectedTodoId: String? - // 오른쪽 칸 상세가 모르는 곳에서 고른 Todo가 바뀌면 올려 상세를 다시 만듦 - var detailPaneRevision = 0 - // 사이드바가 있는 창에서 사이드바까지 덮는 상세 판에 연 Todo - var panelTodo: TodoIdItem? // Mac에서 마우스를 올린 행, 선택 행처럼 둥글게 표시하고 맞닿는 구분선을 숨김 var hoveredTodoId: String? - // 사이드바가 있는 창에서 목록 오른쪽 칸을 연 상태, 세부 정보 사이드바만 쓰는 선택과 구분 - var isDetailPanePresented = false + // 사이드바가 있는 창에서 상세 판 대신 목록 오른쪽 칸에 표시, 세부 정보 사이드바만 쓰는 선택과 구분 + var showsDetailInPane = false // 좁은 창 세부 정보 시트의 속성 // 시트를 닫아도 저장 결과를 받도록 시트 밖에서 소유 var todoInfo: TodoDetailSideBarFeature.State? diff --git a/Application/Presentation/TodayTab/Sources/TodayFeature.swift b/Application/Presentation/TodayTab/Sources/TodayFeature.swift index 88199d16..3a4ee216 100644 --- a/Application/Presentation/TodayTab/Sources/TodayFeature.swift +++ b/Application/Presentation/TodayTab/Sources/TodayFeature.swift @@ -42,7 +42,13 @@ struct TodayFeature { enum Action: BindableAction, Equatable { case alert(PresentationAction) + case detail(PresentationAction) case binding(BindingAction) + // 사이드바가 있는 창은 연 곳(상세 판이나 오른쪽 칸)의 내용을 바꿈 + case selectTodo(String) + // 사이드바가 있는 창에서 오른쪽 칸을 열었으면 칸의 Todo도 바꿈 + case inspectTodo(String) + case moveDetailToPane case refresh case fetchData case checkCurrentDate(Date) @@ -90,8 +96,29 @@ struct TodayFeature { switch action { case .alert: break + case .detail(.dismiss): + state.showsDetailInPane = false + case .detail: + break case .binding: break + case .selectTodo(let todoId): + if state.showsDetailInPane { + state.selectedTodoId = todoId + } + // 이미 연 Todo는 불러온 상세와 열어 둔 시트를 그대로 둠 + if state.detail?.todoId != todoId { + state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: true) + } + case .inspectTodo(let todoId): + state.selectedTodoId = todoId + if state.showsDetailInPane && state.detail?.todoId != todoId { + state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: true) + } + case .moveDetailToPane: + guard let todoId = state.detail?.todoId else { break } + state.selectedTodoId = todoId + state.showsDetailInPane = true case .refresh: let interval = prepareTodayInterval(state: &state, now: now) return .concatenate( @@ -165,18 +192,18 @@ struct TodayFeature { state.alert = Self.alertState() case .store(.setTodos(let incomplete, let completedToday, let interval)): guard state.todayInterval == interval else { break } - let selectedItem = state.selectedTodoId.flatMap { latestItem(id: $0, state: state) } + let detailItem = state.detail.flatMap { latestItem(id: $0.todoId, state: state) } state.todos = incomplete state.isIncompleteDataLoaded = true state.completedTodayTodos = completedToday state.isCompletedTodayDataLoaded = true - reloadDetailPaneIfChanged(from: selectedItem, state: &state) + return reloadDetailIfChanged(from: detailItem, state: state) case .store(.setCompletedTodayTodos(let todos, let interval)): guard state.todayInterval == interval else { break } - let selectedItem = state.selectedTodoId.flatMap { latestItem(id: $0, state: state) } + let detailItem = state.detail.flatMap { latestItem(id: $0.todoId, state: state) } state.completedTodayTodos = todos state.isCompletedTodayDataLoaded = true - reloadDetailPaneIfChanged(from: selectedItem, state: &state) + return reloadDetailIfChanged(from: detailItem, state: state) case .store(.setCategories(let categories)): state.categories = categories let visibleCategoryIDs = Set(state.visibleCategories.map(\.id)) @@ -185,11 +212,11 @@ struct TodayFeature { state.selectedCategoryID = nil } case .store(.updateTodo(let item)): - // 인스펙터나 완료 버튼으로 바꾼 Todo는 오른쪽 칸 상세도 다시 만듦 - if item.id == state.selectedTodoId { - state.detailPaneRevision += 1 - } update(item, state: &state) + // 인스펙터나 완료 버튼으로 바꾼 Todo는 연 상세도 다시 조회 + if item.id == state.detail?.todoId { + return .send(.detail(.presented(.fetch))) + } case .store(.removeTodo(let todoId)): state.todos.removeAll { $0.id == todoId } state.completedTodayTodos.removeAll { $0.id == todoId } @@ -203,6 +230,9 @@ struct TodayFeature { .ifLet(\.todoInfo, action: \.todoInfo) { TodoDetailSideBarFeature() } + .ifLet(\.$detail, action: \.detail) { + TodoDetailFeature() + } } } @@ -251,11 +281,11 @@ private extension TodayFeature { } } - // 다시 불러온 목록에서 고른 Todo가 바뀌었으면 오른쪽 칸 상세도 다시 만듦 - func reloadDetailPaneIfChanged(from selectedItem: TodayTodoItem?, state: inout State) { - guard let selectedItem, - latestItem(id: selectedItem.id, state: state)?.updatedAt != selectedItem.updatedAt else { return } - state.detailPaneRevision += 1 + // 다시 불러온 목록에서 연 Todo가 바뀌었으면 상세도 다시 조회 + func reloadDetailIfChanged(from detailItem: TodayTodoItem?, state: State) -> Effect { + guard let detailItem, + latestItem(id: detailItem.id, state: state)?.updatedAt != detailItem.updatedAt else { return .none } + return .send(.detail(.presented(.fetch))) } func prepareTodayInterval(state: inout State, now: Date) -> DateInterval { diff --git a/Application/Presentation/TodayTab/Sources/TodayRoute.swift b/Application/Presentation/TodayTab/Sources/TodayRoute.swift deleted file mode 100644 index c031d73a..00000000 --- a/Application/Presentation/TodayTab/Sources/TodayRoute.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// TodayRoute.swift -// TodayTab -// -// Created by opfic on 7/5/26. -// - -import PresentationShared - -public enum TodayRoute: Hashable { - case todo(TodoIdItem) -} diff --git a/Application/Presentation/TodayTab/Sources/TodayView.swift b/Application/Presentation/TodayTab/Sources/TodayView.swift index 02df6acd..4ee69486 100644 --- a/Application/Presentation/TodayTab/Sources/TodayView.swift +++ b/Application/Presentation/TodayTab/Sources/TodayView.swift @@ -19,7 +19,6 @@ public struct TodayView: View { @Environment(\.windowControlsInset) private var windowControlsInset @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented - @State private var router = NavigationRouter() @State private var store: StoreOf private let isSelected: Bool private let windowEvent: TodoEditorWindowEvent @@ -38,17 +37,17 @@ public struct TodayView: View { } public var body: some View { - NavigationStack(path: $router.path) { + NavigationStack { let sections = store.sections // 사이드바가 있는 창은 목록을 창 전체 폭으로 두고 오른쪽 칸을 열었고 그 Todo가 목록에 있을 때만 두 칸으로 나눔 - let showsPane = store.isDetailPanePresented - && sections.flatMap(\.items).contains { $0.id == store.selectedTodoId } + let showsPane = store.showsDetailInPane + && sections.flatMap(\.items).contains { $0.id == store.detail?.todoId } PaneSplitView(splitsOnDesktop: showsPane) { ScrollView { // 칸으로 나누지 않은 화면은 상세 칸이 없어 선택 표시 생략 let highlightedTodoIds = ( - [store.hoveredTodoId] + (usesPaneLayout ? [store.selectedTodoId, store.panelTodo?.id] : []) + [store.hoveredTodoId] + (usesPaneLayout ? [store.selectedTodoId, store.detail?.todoId] : []) ).compactMap { $0 } LazyVStack(alignment: .leading, spacing: 0) { @@ -69,19 +68,12 @@ public struct TodayView: View { isNavigationEnabled: !store.isTodoInspectorPresented, highlightedTodoIds: highlightedTodoIds, onSelect: { item in - // 사이드바가 있는 창은 오른쪽 칸을 열지 않았으면 상세 판으로 열고 열었으면 오른쪽 칸 내용을 바꿈 - if usesDesktopLayout && !showsPane { - store.send(.binding(.set(\.panelTodo, TodoIdItem(id: item.id)))) - } else if usesPaneLayout { - store.send(.binding(.set(\.selectedTodoId, item.id))) - } else { - router.push(.todo(TodoIdItem(id: item.id))) - } + store.send(.selectTodo(item.id)) }, onInspect: { item in // 사이드바가 있으면 고른 Todo를 창 오른쪽 세부 정보 사이드바에 표시 if usesDesktopLayout { - store.send(.binding(.set(\.selectedTodoId, item.id))) + store.send(.inspectTodo(item.id)) setDetailSideBarPresented?(true) } else { store.send(.showTodoInspector(item)) @@ -135,32 +127,38 @@ public struct TodayView: View { .refreshable { await store.send(.refresh).finish() } .duoToolbarVisibility() } detail: { - let item = sections.flatMap(\.items).first { $0.id == store.selectedTodoId } // 목록에서 빠진 Todo는 선택 안내로 대체 - TodoDetailPane( - todoId: item?.id, - showEditButton: true, - windowEvent: windowEvent, - onClose: usesDesktopLayout ? { store.send(.binding(.set(\.isDetailPanePresented, false))) } : nil - ) - // 인스펙터 등에서 목록 행이 바뀌면 상세 칸도 다시 조회 - .id(store.detailPaneRevision) + if showsPane, let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + TodoDetailView( + store: detailStore, + windowEvent: windowEvent, + isPaneDetail: true, + onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil + ) + .environment(\.showsPaneTitleBar, true) + // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 + .id(detailStore.todoId) + } else { + PanePlaceholder() + } } - // 좁은 창으로 바뀌면 상세 판을 숨기고 넓어지면 다시 표시 - .detailPanel(item: $store.panelTodo.activePresentation(when: isSelected && usesDesktopLayout)) { item in + // 좁은 창은 목록 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + inPane: showsPane, + isActive: isSelected + ) { detailStore in + TodoDetailView(store: detailStore, windowEvent: windowEvent) + } panel: { detailStore in // 목록에서 빠진 Todo는 오른쪽 칸에 그릴 수 없어 판 메뉴에서 오른쪽 칸으로 옮기기 생략 - let isListed = sections.flatMap(\.items).contains { $0.id == item.id } + let isListed = sections.flatMap(\.items).contains { $0.id == detailStore.todoId } TodoDetailPanel( - todoId: item.id, + store: detailStore, location: Text("nav_today", bundle: PresentationResources.bundle), - isEditable: true, windowEvent: windowEvent, - onMoveToPane: isListed ? { - store.send(.binding(.set(\.panelTodo, nil))) - store.send(.binding(.set(\.selectedTodoId, item.id))) - store.send(.binding(.set(\.isDetailPanePresented, true))) - } : nil + onMoveToPane: isListed ? { store.send(.moveDetailToPane) } : nil ) } .compositionRight(isActive: sections.flatMap(\.items).contains { $0.id == store.selectedTodoId }) { @@ -169,28 +167,13 @@ public struct TodayView: View { .id(todoId) } } - .navigationDestination( - for: TodayRoute.self, - interactivePop: { _ in true }, - destination: { destination($0).environment(\.showsPaneTitleBar, usesPaneLayout) } - ) } .desktopNavigationTransition() // 오른쪽 칸에 연 Todo가 목록에서 빠지면 닫기 버튼 없는 선택 안내 대신 오른쪽 칸을 닫음 - // 좁은 창에서 빠져도 닫아 넓어진 뒤 다른 Todo의 세부 정보만 바꿀 때 오른쪽 칸이 열리지 않게 함 - .onChange(of: store.sections.flatMap(\.items).contains { $0.id == store.selectedTodoId }) { _, isListed in - if store.isDetailPanePresented && !isListed { - store.send(.binding(.set(\.isDetailPanePresented, false))) - } - } - // 사이드바 구조로 바뀌면 쌓아 연 상세 화면은 내리고 같은 Todo를 옆 칸에 표시 - .closesPushedDetail { - guard case .todo(let item)? = router.path.last else { return } - // 목록에서 빠진 Todo는 오른쪽 칸에 그릴 수 없어 오른쪽 칸을 열지 않음 - let isListed = store.sections.flatMap(\.items).contains { $0.id == item.id } - store.send(.binding(.set(\.selectedTodoId, item.id))) - store.send(.binding(.set(\.isDetailPanePresented, isListed))) - router.path = [] + // 좁은 창은 쌓아 연 상세를 그대로 두고, 넓어지면 오른쪽 칸 대신 상세 판으로 표시 + .onChange(of: store.sections.flatMap(\.items).contains { $0.id == store.detail?.todoId }) { _, isListed in + guard store.showsDetailInPane && !isListed else { return } + store.send(usesDesktopLayout ? .detail(.dismiss) : .binding(.set(\.showsDetailInPane, false))) } // 사이드바가 있으면 창 오른쪽 세부 정보 사이드바, 좁은 화면과 Duo 펼침은 직접 그린 시트로 표시 .prominentSheet( @@ -238,21 +221,6 @@ public struct TodayView: View { } } - private func destination(_ route: TodayRoute) -> some View { - switch route { - case .todo(let item): - TodoDetailView( - store: Store( - initialState: TodoDetailFeature.State(todoId: item.id, showEditButton: true) - ) { - TodoDetailFeature() - }, - windowEvent: windowEvent - ) - .id(item.id) - } - } - private func monitorDateChanges() async { while !Task.isCancelled { let date = Date() diff --git a/Application/Presentation/TodayTab/Tests/TodayFeatureTestAssertions.swift b/Application/Presentation/TodayTab/Tests/TodayFeatureTestAssertions.swift index f6c03727..c185b0c4 100644 --- a/Application/Presentation/TodayTab/Tests/TodayFeatureTestAssertions.swift +++ b/Application/Presentation/TodayTab/Tests/TodayFeatureTestAssertions.swift @@ -11,7 +11,7 @@ import Domain @testable import TodayTab @MainActor -private func waitUntilTodayMainActor( +func waitUntilTodayMainActor( timeout: Duration = .seconds(1), pollInterval: Duration = .milliseconds(20), _ condition: @escaping @MainActor () -> Bool diff --git a/Application/Presentation/TodayTab/Tests/TodayFeatureTestDoubles.swift b/Application/Presentation/TodayTab/Tests/TodayFeatureTestDoubles.swift index d861888b..cfb9e616 100644 --- a/Application/Presentation/TodayTab/Tests/TodayFeatureTestDoubles.swift +++ b/Application/Presentation/TodayTab/Tests/TodayFeatureTestDoubles.swift @@ -78,7 +78,8 @@ struct TodayStoreTestAdapter: TodayStateDriving { var isTodoInspectorPresented: Bool { store.state.isTodoInspectorPresented } var todoInfoTitle: String? { store.state.todoInfo?.editor?.title } var selectedTodoId: String? { store.state.selectedTodoId } - var detailPaneRevision: Int { store.state.detailPaneRevision } + var detailTodoId: String? { store.state.detail?.todoId } + var showsDetailInPane: Bool { store.state.showsDetailInPane } var visibleCategoryIDs: [String] { store.state.visibleCategories.map(\.id) } var showAlert: Bool { store.state.alert != nil } var isLoading: Bool { store.state.isLoading } @@ -109,6 +110,7 @@ struct TodayStoreTestAdapter: TodayStateDriving { $0.fetchTodoByIdUseCase = fetchTodoByIdUseCase $0.upsertTodoUseCase = upsertUseCase $0.trackAnalyticsEventUseCase = trackAnalyticsEventUseCase + $0.fetchReferenceItemsUseCase = TodayFetchReferenceItemsUseCaseStub() $0.date.now = now $0.continuousClock = ContinuousClock() configureDependencies?(&$0) @@ -149,6 +151,22 @@ struct TodayStoreTestAdapter: TodayStateDriving { await store.send(.store(.updateTodo(item))) } + func openTodo(_ id: String) async { + await store.send(.selectTodo(id)) + } + + func inspectTodo(_ id: String) async { + await store.send(.inspectTodo(id)) + } + + func moveDetailToPane() async { + await store.send(.moveDetailToPane) + } + + func dismissDetail() async { + await store.send(.detail(.dismiss)) + } + func receiveDetailTodo(_ item: TodayTodoItem) async { await store.send(.detailTodoUpdated(item)) } diff --git a/Application/Presentation/TodayTab/Tests/TodayFeatureTestSpies.swift b/Application/Presentation/TodayTab/Tests/TodayFeatureTestSpies.swift index d434f05a..fe4db421 100644 --- a/Application/Presentation/TodayTab/Tests/TodayFeatureTestSpies.swift +++ b/Application/Presentation/TodayTab/Tests/TodayFeatureTestSpies.swift @@ -68,6 +68,12 @@ private actor FetchTodosUseCaseCallRecorder { } } +final class TodayFetchReferenceItemsUseCaseStub: FetchReferenceItemsUseCase { + func execute(_ numbers: [Int]) async throws -> [Int: TodoReference] { + [:] + } +} + final class TodayFetchTodoByIdUseCaseSpy: FetchTodoByIdUseCase { var todos: [Todo] var error: Error? diff --git a/Application/Presentation/TodayTab/Tests/TodayFeatureTests.swift b/Application/Presentation/TodayTab/Tests/TodayFeatureTests.swift index 72397c42..a736c545 100644 --- a/Application/Presentation/TodayTab/Tests/TodayFeatureTests.swift +++ b/Application/Presentation/TodayTab/Tests/TodayFeatureTests.swift @@ -109,25 +109,53 @@ struct TodayFeatureTests { #expect(adapter.showAlert) } - @Test("상세 칸이 저장해 보낸 Todo는 목록 행만 바꾸고 상세 칸은 다시 만들지 않는다") - func 상세_칸이_저장해_보낸_Todo는_목록_행만_바꾸고_상세_칸은_다시_만들지_않는다() async throws { + @Test("상세가 저장해 보낸 Todo는 목록 행만 바꾸고 상세는 다시 조회하지 않는다") + func 상세가_저장해_보낸_Todo는_목록_행만_바꾸고_상세는_다시_조회하지_않는다() async throws { var todo = makeTodayTodo(id: "detail", title: "수정 전") - let adapter = TodayStoreTestAdapter() + let fetchByIdSpy = TodayFetchTodoByIdUseCaseSpy(todos: [todo]) + let adapter = TodayStoreTestAdapter(fetchTodoByIdUseCase: fetchByIdSpy) await adapter.receiveUpdatedTodo(try #require(TodayTodoItem(from: todo))) - await adapter.selectTodo("detail") - let revision = adapter.detailPaneRevision + await adapter.openTodo("detail") todo.title = "상세에서 수정" await adapter.receiveDetailTodo(try #require(TodayTodoItem(from: todo))) #expect(adapter.todos.first?.title == "상세에서 수정") - #expect(adapter.detailPaneRevision == revision) + #expect(fetchByIdSpy.todoIds.isEmpty) todo.title = "목록에서 수정" await adapter.receiveUpdatedTodo(try #require(TodayTodoItem(from: todo))) + await waitUntilTodayMainActor { + !fetchByIdSpy.todoIds.isEmpty + } + #expect(adapter.todos.first?.title == "목록에서 수정") - #expect(adapter.detailPaneRevision == revision + 1) + #expect(fetchByIdSpy.todoIds == ["detail"]) + } + + @Test("오른쪽 칸을 연 동안만 세부 정보로 고른 Todo가 칸의 Todo도 바꾼다") + func 오른쪽_칸을_연_동안만_세부_정보로_고른_Todo가_칸의_Todo도_바꾼다() async { + let adapter = TodayStoreTestAdapter() + + await adapter.openTodo("panel") + await adapter.inspectTodo("inspected") + + #expect(adapter.detailTodoId == "panel") + #expect(adapter.selectedTodoId == "inspected") + + await adapter.moveDetailToPane() + await adapter.inspectTodo("next") + + #expect(adapter.showsDetailInPane) + #expect(adapter.detailTodoId == "next") + #expect(adapter.selectedTodoId == "next") + + await adapter.dismissDetail() + + #expect(adapter.detailTodoId == nil) + #expect(!adapter.showsDetailInPane) + #expect(adapter.selectedTodoId == "next") } @Test("넓은 창으로 바뀌면 세부 정보 시트를 저장 없이 닫고 같은 Todo를 고른다") From 14a21c384d740a6bf4e58518f5d458f0343b16e6 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 07/25] =?UTF-8?q?refactor:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=ED=83=AD=20Todo=20=EC=83=81=EC=84=B8=EB=A5=BC=20PushNotificati?= =?UTF-8?q?onListFeature=EC=9D=98=20detail=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/PushNotificationListFeature.swift | 63 ++++--------- .../Sources/PushNotificationListView.swift | 93 +++++++------------ .../PushNotificationListFeatureTests.swift | 48 ++-------- .../PushNotificationListTestAssertions.swift | 8 +- .../PushNotificationListTestSupport.swift | 23 ++--- 5 files changed, 72 insertions(+), 163 deletions(-) diff --git a/Application/Presentation/NotificationTab/Sources/PushNotificationListFeature.swift b/Application/Presentation/NotificationTab/Sources/PushNotificationListFeature.swift index 8ea49d8c..6f11acd9 100644 --- a/Application/Presentation/NotificationTab/Sources/PushNotificationListFeature.swift +++ b/Application/Presentation/NotificationTab/Sources/PushNotificationListFeature.swift @@ -16,14 +16,14 @@ struct PushNotificationListFeature { @ObservableState struct State: Equatable { @Presents var alert: AlertState? - @Presents var sheet: SheetState? + // 고른 알림의 Todo 상세, 좁은 창은 시트로 띄우고 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + @Presents var detail: TodoDetailFeature.State? var notifications: [PushNotificationItem] = [] var nextCursor: PushNotificationCursor? var query: PushNotificationQuery var selectedNotificationId: String? - var selectedTodoId: TodoIdItem? // 사이드바가 있는 창에서 목록 오른쪽 칸을 연 상태, 닫혀 있으면 고른 Todo를 상세 판으로 표시 - var isDetailPanePresented = false + var showsDetailInPane = false var loading = LoadingFeature.State() var undoNotificationId: String? @@ -44,15 +44,9 @@ struct PushNotificationListFeature { } } - @ObservableState - struct SheetState: Equatable, Identifiable { - let todoId: String - var id: String { todoId } - } - enum Action: BindableAction { case alert(PresentationAction) - case sheet(PresentationAction) + case detail(PresentationAction) case binding(BindingAction) case view(ViewAction) case store(StoreAction) @@ -72,12 +66,6 @@ struct PushNotificationListFeature { case toggleUnreadOnly case resetFilters case selectNotification(String?) - case syncSheetPresentation - case hideSheet - } - - enum Sheet: Equatable { - case tapCloseButton } enum StoreAction: Equatable { @@ -112,13 +100,11 @@ struct PushNotificationListFeature { switch action { case .alert: break - case .sheet(.dismiss), .sheet(.presented(.tapCloseButton)): - state.sheet = nil + case .detail(.dismiss): state.selectedNotificationId = nil - state.selectedTodoId = nil // 오른쪽 칸에서 연 알림을 좁은 창의 시트로 닫으면 다시 넓혀도 빈 오른쪽 칸을 열지 않음 - state.isDetailPanePresented = false - case .sheet: + state.showsDetailInPane = false + case .detail: break case .binding(\.query.timeFilter): state.nextCursor = nil @@ -137,21 +123,12 @@ struct PushNotificationListFeature { return .none } .ifLet(\.$alert, action: \.alert) - .ifLet(\.$sheet, action: \.sheet) { - PushNotificationListSheetFeature() + .ifLet(\.$detail, action: \.detail) { + TodoDetailFeature() } } } -private struct PushNotificationListSheetFeature: Reducer { - typealias State = PushNotificationListFeature.SheetState - typealias Action = PushNotificationListFeature.Action.Sheet - - var body: some ReducerOf { - EmptyReducer() - } -} - private extension PushNotificationListFeature { func reduce( _ action: Action.ViewAction, @@ -229,27 +206,19 @@ private extension PushNotificationListFeature { return refreshForQueryChangeEffect(query: state.query) case .selectNotification(let notificationId): state.selectedNotificationId = notificationId - guard let notificationId else { - state.selectedTodoId = nil - return .none - } - guard let index = state.notifications.firstIndex(where: { $0.id == notificationId }) else { - state.selectedTodoId = nil + guard let notificationId, + let index = state.notifications.firstIndex(where: { $0.id == notificationId }) else { + state.detail = nil return .none } let item = state.notifications[index] - state.selectedTodoId = TodoIdItem(id: item.todoId) + // 같은 Todo의 알림은 불러온 상세와 열어 둔 시트를 그대로 둠 + if state.detail?.todoId != item.todoId { + state.detail = TodoDetailFeature.State(todoId: item.todoId, showEditButton: false) + } guard !item.isRead else { return .none } state.notifications[index].isRead = true return toggleReadEffect(notificationId: item.id, todoId: item.todoId, rollbackRead: false) - case .syncSheetPresentation: - if let todoId = state.selectedTodoId?.id { - state.sheet = .init(todoId: todoId) - } else { - state.sheet = nil - } - case .hideSheet: - state.sheet = nil } return .none diff --git a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift index 0c03b002..d6266d89 100644 --- a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift +++ b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift @@ -30,7 +30,7 @@ public struct PushNotificationListView: View { public var body: some View { // 사이드바가 있는 창에서 오른쪽 칸을 열었을 때만 목록 | 상세 두 칸으로 나눔 - let showsPane = usesDesktopLayout && store.isDetailPanePresented + let showsPane = usesDesktopLayout && store.showsDetailInPane NavigationStack { PaneSplitView(splitsOnDesktop: showsPane) { @@ -44,31 +44,49 @@ public struct PushNotificationListView: View { } .duoToolbarVisibility() } detail: { - TodoDetailPane( - todoId: store.selectedTodoId?.id, - showEditButton: false, - onClose: usesDesktopLayout ? closeDetailPane : nil - ) + if store.showsDetailInPane, + let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + TodoDetailView( + store: detailStore, + isPaneDetail: true, + onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil + ) + .environment(\.showsPaneTitleBar, true) + // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 + .id(detailStore.todoId) + } else { + PanePlaceholder() + } } // 오른쪽 칸은 칸 제목 줄 정보 버튼 대신 창 오른쪽 세부 정보 사이드바에 속성 표시 - .compositionRight(isActive: showsPane && store.selectedTodoId != nil) { - if let todoId = store.selectedTodoId?.id { + .compositionRight(isActive: showsPane && store.detail != nil) { + if let todoId = store.detail?.todoId { TodoDetailSideBarView(todoId: todoId, isEditable: false, windowEvent: windowEvent) .id(todoId) } } } .prominentAlert(store, state: \.alert, action: \.alert) - .prominentSheet(item: sheetStore.activePresentation(when: isSelected && !usesDesktopLayout)) { store in - sheetContent(store) - } - .detailPanel(item: sheetStore.activePresentation(when: isSelected && usesDesktopLayout)) { sheetStore in + // 좁은 창은 시트로 띄우고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + narrow: .sheet, + inPane: store.showsDetailInPane, + isActive: isSelected + ) { detailStore in + NavigationStack { + TodoDetailView(store: detailStore) + } + .environment(\.windowControlsInset, 0) + .environment(\.deviceType, .bar) + .background(Color.background) + } panel: { detailStore in TodoDetailPanel( - todoId: sheetStore.todoId, + store: detailStore, location: Text("nav_push_notifications", bundle: PresentationResources.bundle), - isEditable: false, onMoveToPane: { - store.send(.binding(.set(\.isDetailPanePresented, true))) + store.send(.binding(.set(\.showsDetailInPane, true))) } ) } @@ -77,53 +95,12 @@ public struct PushNotificationListView: View { store.send(.view(.fetchNotifications)) } } - .onChange(of: store.selectedTodoId?.id, initial: true) { - if !showsPane { - store.send(.view(.syncSheetPresentation)) - } - } - // 오른쪽 칸을 열면 상세 판만 닫고, 오른쪽 칸을 닫으면 고른 Todo를 상세 판이나 시트로 표시 - .onChange(of: showsPane) { _, showsPane in - store.send(.view(showsPane ? .hideSheet : .syncSheetPresentation)) - } .overlay { if store.isLoading { LoadingView() } } } - - // 선택을 먼저 비워 오른쪽 칸을 닫을 때 같은 Todo를 상세 판으로 다시 열지 않음 - private func closeDetailPane() { - store.send(.view(.selectNotification(nil))) - store.send(.binding(.set(\.isDetailPanePresented, false))) - } - - @ViewBuilder - private func sheetContent( - _ sheetStore: Store - ) -> some View { - NavigationStack { - TodoDetailView(store: Store( - initialState: TodoDetailFeature.State( - todoId: sheetStore.todoId, - showEditButton: false - ) - ) { - TodoDetailFeature() - }) - .id(sheetStore.todoId) - } - .environment(\.windowControlsInset, 0) - .environment(\.deviceType, .bar) - .background(Color.background) - } - - private var sheetStore: Binding< - Store?> { - $store.scope(state: \.sheet, action: \.sheet) - } } private struct PushNotificationListContent: View { @@ -239,7 +216,7 @@ private struct PushNotificationListContent: View { // 우클릭과 길게 누른 메뉴는 상세 판과 오른쪽 칸으로 여는 항목을 맨 위에 표시 if usesDesktopLayout { Button { - store.send(.binding(.set(\.isDetailPanePresented, false))) + store.send(.binding(.set(\.showsDetailInPane, false))) store.send(.view(.selectNotification(item.id))) } label: { Label { @@ -249,7 +226,7 @@ private struct PushNotificationListContent: View { } } Button { - store.send(.binding(.set(\.isDetailPanePresented, true))) + store.send(.binding(.set(\.showsDetailInPane, true))) store.send(.view(.selectNotification(item.id))) } label: { Label { diff --git a/Application/Presentation/NotificationTab/Tests/PushNotificationListFeatureTests.swift b/Application/Presentation/NotificationTab/Tests/PushNotificationListFeatureTests.swift index 4a53843b..9dbed491 100644 --- a/Application/Presentation/NotificationTab/Tests/PushNotificationListFeatureTests.swift +++ b/Application/Presentation/NotificationTab/Tests/PushNotificationListFeatureTests.swift @@ -309,8 +309,8 @@ struct PushNotificationListFeatureTests { #expect(adapter.notifications.first?.isRead == true) } - @Test("syncSheetPresentation은 선택한 Todo를 시트로 표시한다") - func syncSheetPresentation은_선택한_Todo를_시트로_표시한다() async throws { + @Test("고른 알림의 Todo 상세를 닫으면 고른 알림도 비운다") + func 고른_알림의_Todo_상세를_닫으면_고른_알림도_비운다() async throws { let fetchSpy = PushNotificationListFetchUseCaseSpy(pages: [ PushNotificationPage( items: [ @@ -324,15 +324,12 @@ struct PushNotificationListFeatureTests { await adapter.fetchNotifications() await adapter.selectNotification("notification-1") - await adapter.syncSheetPresentation() + #expect(adapter.detailTodoId == "todo-1") - #expect(adapter.sheetTodoId == "todo-1") + await adapter.dismissDetail() - await adapter.dismissSheet() - - #expect(adapter.sheetTodoId == nil) + #expect(adapter.detailTodoId == nil) #expect(adapter.selectedNotificationId == nil) - #expect(adapter.selectedTodoId == nil) } @Test("오른쪽 칸에서 연 알림을 시트로 옮긴 뒤 닫으면 오른쪽 칸 상태도 닫는다") @@ -348,38 +345,13 @@ struct PushNotificationListFeatureTests { let adapter = PushNotificationListStoreTestAdapter(fetchUseCase: fetchSpy) await adapter.fetchNotifications() - await adapter.setDetailPanePresented(true) - await adapter.selectNotification("notification-1") - // 창이 좁아져 오른쪽 칸 대신 시트로 표시 - await adapter.syncSheetPresentation() - - await adapter.dismissSheet() - - #expect(adapter.selectedTodoId == nil) - #expect(!adapter.isDetailPanePresented) - } - - @Test("hideSheet은 시트만 닫고 선택한 알림과 Todo를 유지한다") - func hideSheet은_시트만_닫고_선택한_알림과_Todo를_유지한다() async throws { - let fetchSpy = PushNotificationListFetchUseCaseSpy(pages: [ - PushNotificationPage( - items: [ - makePushNotification(id: "notification-1", number: 1, isRead: true) - ], - nextCursor: nil - ) - ]) - let adapter = PushNotificationListStoreTestAdapter(fetchUseCase: fetchSpy) - - await adapter.fetchNotifications() + await adapter.setShowsDetailInPane(true) await adapter.selectNotification("notification-1") - await adapter.syncSheetPresentation() - - await adapter.hideSheet() + // 창이 좁아져 오른쪽 칸 대신 같은 상세 상태를 시트로 표시한 뒤 닫음 + await adapter.dismissDetail() - #expect(adapter.sheetTodoId == nil) - #expect(adapter.selectedNotificationId == "notification-1") - #expect(adapter.selectedTodoId?.id == "todo-1") + #expect(adapter.detailTodoId == nil) + #expect(!adapter.showsDetailInPane) } @Test("delete와 undoDelete는 숨김 상태와 최종 제거 상태를 제어한다") diff --git a/Application/Presentation/NotificationTab/Tests/PushNotificationListTestAssertions.swift b/Application/Presentation/NotificationTab/Tests/PushNotificationListTestAssertions.swift index 9ce79977..41f24461 100644 --- a/Application/Presentation/NotificationTab/Tests/PushNotificationListTestAssertions.swift +++ b/Application/Presentation/NotificationTab/Tests/PushNotificationListTestAssertions.swift @@ -139,10 +139,10 @@ func verifySelectNotification( await adapter.selectNotification("notification-1") let selectedNotificationId = adapter.selectedNotificationId - let selectedTodoId = adapter.selectedTodoId + let detailTodoId = adapter.detailTodoId let notifications = adapter.notifications #expect(selectedNotificationId == "notification-1") - #expect(selectedTodoId?.id == "todo-1") + #expect(detailTodoId == "todo-1") #expect(notifications.first?.isRead == true) await waitUntilMainActor { @@ -152,9 +152,9 @@ func verifySelectNotification( await adapter.selectNotification(nil) let resetSelectedNotificationId = adapter.selectedNotificationId - let resetSelectedTodoId = adapter.selectedTodoId + let resetDetailTodoId = adapter.detailTodoId #expect(resetSelectedNotificationId == nil) - #expect(resetSelectedTodoId == nil) + #expect(resetDetailTodoId == nil) } @MainActor diff --git a/Application/Presentation/NotificationTab/Tests/PushNotificationListTestSupport.swift b/Application/Presentation/NotificationTab/Tests/PushNotificationListTestSupport.swift index 7e1801c4..a62f55de 100644 --- a/Application/Presentation/NotificationTab/Tests/PushNotificationListTestSupport.swift +++ b/Application/Presentation/NotificationTab/Tests/PushNotificationListTestSupport.swift @@ -19,7 +19,7 @@ protocol PushNotificationListStateDriving { var query: PushNotificationQuery { get } var nextCursor: PushNotificationCursor? { get } var selectedNotificationId: String? { get } - var selectedTodoId: TodoIdItem? { get } + var detailTodoId: String? { get } var appliedFilterCount: Int { get } func startObserving() async @@ -45,10 +45,9 @@ struct PushNotificationListStoreTestAdapter: PushNotificationListStateDriving { var query: PushNotificationQuery { store.state.query } var nextCursor: PushNotificationCursor? { store.state.nextCursor } var selectedNotificationId: String? { store.state.selectedNotificationId } - var selectedTodoId: TodoIdItem? { store.state.selectedTodoId } + var detailTodoId: String? { store.state.detail?.todoId } var appliedFilterCount: Int { store.state.appliedFilterCount } - var sheetTodoId: String? { store.state.sheet?.todoId } - var isDetailPanePresented: Bool { store.state.isDetailPanePresented } + var showsDetailInPane: Bool { store.state.showsDetailInPane } init( fetchUseCase: FetchPushNotificationsUseCase = PushNotificationListFetchUseCaseSpy(), @@ -148,20 +147,12 @@ struct PushNotificationListStoreTestAdapter: PushNotificationListStateDriving { await store.send(.view(.finishDeleteToast(notificationId))) } - func syncSheetPresentation() async { - await store.send(.view(.syncSheetPresentation)) + func dismissDetail() async { + await store.send(.detail(.dismiss)) } - func dismissSheet() async { - await store.send(.sheet(.dismiss)) - } - - func setDetailPanePresented(_ isPresented: Bool) async { - await store.send(.binding(.set(\.isDetailPanePresented, isPresented))) - } - - func hideSheet() async { - await store.send(.view(.hideSheet)) + func setShowsDetailInPane(_ showsDetailInPane: Bool) async { + await store.send(.binding(.set(\.showsDetailInPane, showsDetailInPane))) } func finishEffects() async { From 40631b5833482f09fd8f41ae2a45bc432ed3c647 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 08/25] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=ED=95=84?= =?UTF-8?q?=20=ED=83=AD=20Todo=20=EC=83=81=EC=84=B8=EB=A5=BC=20ProfileFeat?= =?UTF-8?q?ure=EC=9D=98=20detail=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Todo/Detail/TodoDetailPanel.swift | 20 --- .../Sources/Profile/ActivityCard.swift | 3 +- .../Sources/Profile/ProfileFeature.swift | 23 +++- .../Sources/Profile/ProfileView.swift | 127 ++++++------------ .../Sources/Profile/RecentActivityCard.swift | 3 +- .../Settings/DesktopSettingsView.swift | 6 +- .../Tests/Profile/ProfileFeatureTests.swift | 22 +++ 7 files changed, 92 insertions(+), 112 deletions(-) diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift index cbbba673..dbf1c104 100644 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift +++ b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanel.swift @@ -35,26 +35,6 @@ public struct TodoDetailPanel: View { self.onDelete = onDelete } - // 프로필 탭이 상세 상태를 Feature로 옮기기 전까지 Todo 식별자로 상세 상태를 만들어 여는 init - public init( - todoId: String, - location: Text, - isEditable: Bool, - windowEvent: TodoEditorWindowEvent? = nil, - onMoveToPane: (() -> Void)? = nil, - onDelete: (() -> Void)? = nil - ) { - self.init( - store: Store(initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: isEditable)) { - TodoDetailFeature() - }, - location: location, - windowEvent: windowEvent, - onMoveToPane: onMoveToPane, - onDelete: onDelete - ) - } - public var body: some View { VStack(spacing: 0) { DetailPanelBar( diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift b/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift index 7639039f..21d2c3a5 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift @@ -196,7 +196,8 @@ struct ActivityCard: View { // 행 배치를 바꾸지 않고 선택한 행 배경만 바깥으로 넓힘 // 선택 표시는 다른 목록 행과 같은 회색 .background { - if usesPaneLayout && store.selectedTodoRoute == .activity(activity.todoId) { + if usesPaneLayout && store.showsDetailInPane + && store.detail?.todoId == activity.todoId && store.detail?.showEditButton == false { RoundedRectangle(cornerRadius: CornerRadius.control) .fill(Color.fill) .padding(.horizontal, -8) diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift index ba0f6c21..b78a986f 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift @@ -54,16 +54,21 @@ struct ProfileFeature { var dayActivitiesByDate: [Date: [HeatmapActivityItem]] = [:] var selectedActivityKinds: Set = [.created, .completed, .deleted] var selectedDay: HeatmapDay? - var selectedTodoRoute: ProfileRoute? - // 사이드바가 있는 창에서 사이드바까지 덮는 상세 판에 연 Todo - var panelTodoRoute: ProfileRoute? + // 활동 기록이나 최근 Todo에서 연 Todo 상세, 활동 기록 Todo는 고칠 수 없어 편집 버튼 없이 표시 + // 좁은 창은 내비게이션에 쌓고 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + @Presents var detail: TodoDetailFeature.State? + // 사이드바가 있는 창에서 상세 판 대신 오른쪽 칸에 표시 + var showsDetailInPane = false var showDoneButton = false var loading = LoadingFeature.State() } enum Action: BindableAction { case alert(PresentationAction) + case detail(PresentationAction) case binding(BindingAction) + // 사이드바가 있는 창은 연 곳(상세 판이나 오른쪽 칸)의 내용을 바꿈 + case selectTodo(String, isEditable: Bool) case startObserving case fetchData case refresh @@ -119,6 +124,15 @@ struct ProfileFeature { state.alert = nil case .alert: break + case .detail(.dismiss): + state.showsDetailInPane = false + case .detail: + break + case .selectTodo(let todoId, let isEditable): + // 이미 연 Todo는 불러온 상세와 열어 둔 시트를 그대로 둠 + if state.detail?.todoId != todoId || state.detail?.showEditButton != isEditable { + state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: isEditable) + } case .binding(\.isCreatedActivitySelected): return updateHeatmapActivityKindsEffectIfNeeded(.created, state: state) case .binding(\.isCompletedActivitySelected): @@ -243,6 +257,9 @@ struct ProfileFeature { return .none } .ifLet(\.$alert, action: \.alert) + .ifLet(\.$detail, action: \.detail) { + TodoDetailFeature() + } } } diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index f13c582b..3a7ca9b4 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -40,17 +40,17 @@ public struct ProfileView: View { public var body: some View { NavigationStack(path: path) { // 사이드바가 있는 창은 프로필을 창 전체 폭으로 두고 오른쪽 칸으로 옮긴 Todo가 있을 때만 두 칸으로 나눔 - PaneSplitView(splitsOnDesktop: store.selectedTodoRoute != nil) { + PaneSplitView(splitsOnDesktop: store.showsDetailInPane && store.detail != nil) { ScrollView { // 카드 없이 각 섹션이 페이지 여백을 가짐 LazyVStack(alignment: .leading, spacing: 0) { UserInfoCard(store: store, isSelected: isSelected) ActivityCard(store: store) { todoId in - showTodo(.activity(todoId)) + store.send(.selectTodo(todoId, isEditable: false)) } ProfileGoalSummary(store: store) RecentActivityCard(store: store) { todoId in - showTodo(.recentTodo(todoId)) + store.send(.selectTodo(todoId, isEditable: true)) } } .padding(.bottom, 24) @@ -69,49 +69,55 @@ public struct ProfileView: View { } .background(Color.background) } detail: { - let closeDetailPane: (() -> Void)? = usesDesktopLayout - ? { store.send(.binding(.set(\.selectedTodoRoute, nil))) } : nil - - switch store.selectedTodoRoute { - case .activity(let todoId): - TodoDetailPane(todoId: todoId, showEditButton: false, onClose: closeDetailPane) - case .recentTodo(let todoId): - TodoDetailPane( - todoId: todoId, - showEditButton: true, - windowEvent: windowEvent, - onClose: closeDetailPane + if store.showsDetailInPane, + let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + // 활동 기록 Todo는 고칠 수 없어 편집 결과를 받을 창 이벤트 없이 표시 + TodoDetailView( + store: detailStore, + windowEvent: detailStore.showEditButton ? windowEvent : nil, + isPaneDetail: true, + onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil ) - default: - TodoDetailPane(todoId: nil, showEditButton: false) - } - } - .compositionRight(isActive: store.selectedTodoRoute?.todo != nil) { - if let todo = store.selectedTodoRoute?.todo { - TodoDetailSideBarView(todoId: todo.id, isEditable: todo.isEditable, windowEvent: windowEvent) - .id(todo.id) + .environment(\.showsPaneTitleBar, true) + // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 + .id(detailStore.todoId) + } else { + PanePlaceholder() } } - // 좁은 창으로 바뀌면 상세 판을 숨기고 넓어지면 다시 표시 - .detailPanel(item: $store.panelTodoRoute.activePresentation(when: isSelected && usesDesktopLayout)) { route in - if let todo = route.todo { - TodoDetailPanel( - todoId: todo.id, - location: Text("nav_profile", bundle: PresentationResources.bundle), - isEditable: todo.isEditable, - windowEvent: todo.isEditable ? windowEvent : nil, - onMoveToPane: { - store.send(.binding(.set(\.panelTodoRoute, nil))) - store.send(.binding(.set(\.selectedTodoRoute, route))) - } + .compositionRight(isActive: store.showsDetailInPane && store.detail != nil) { + if let detail = store.detail { + TodoDetailSideBarView( + todoId: detail.todoId, + isEditable: detail.showEditButton, + windowEvent: windowEvent ) + .id(detail.todoId) } } + // 좁은 창은 프로필 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + inPane: store.showsDetailInPane, + isActive: isSelected + ) { detailStore in + TodoDetailView(store: detailStore, windowEvent: detailStore.showEditButton ? windowEvent : nil) + } panel: { detailStore in + TodoDetailPanel( + store: detailStore, + location: Text("nav_profile", bundle: PresentationResources.bundle), + windowEvent: detailStore.showEditButton ? windowEvent : nil, + onMoveToPane: { + store.send(.binding(.set(\.showsDetailInPane, true))) + } + ) + } .navigationDestination( for: ProfileRoute.self, interactivePop: { switch $0 { - case .settings, .theme, .activity, .recentTodo: true + case .settings, .theme: true default: false } }, @@ -121,16 +127,6 @@ public struct ProfileView: View { .desktopNavigationTransition() // 창 폭이 바뀌어 같은 설정을 다시 쌓거나 내릴 때 밀리는 효과 없이 바꿈 .transaction(value: usesDesktopLayout) { $0.disablesAnimations = true } - // 사이드바 구조로 바뀌면 쌓아 연 Todo 상세는 내리고 같은 Todo를 옆 칸에 표시 - .closesPushedDetail { - switch router.path.last { - case .activity?, .recentTodo?: - let route = router.path.removeLast() - store.send(.binding(.set(\.selectedTodoRoute, route))) - default: - break - } - } // 사이드바 요청으로 처음 여는 탭도 그 요청을 반영 .onChange(of: sideBarRequest, initial: true) { _, request in switch request?.action { @@ -244,18 +240,6 @@ public struct ProfileView: View { ) } - // 칸 화면은 옆 칸에 상세를 열고 나머지는 화면 이동 - // 사이드바가 있는 창은 오른쪽 칸을 열지 않았으면 상세 판으로 열고 열었으면 오른쪽 칸 내용을 바꿈 - private func showTodo(_ route: ProfileRoute) { - if usesDesktopLayout && store.selectedTodoRoute == nil { - store.send(.binding(.set(\.panelTodoRoute, route))) - } else if usesPaneLayout { - store.send(.binding(.set(\.selectedTodoRoute, route))) - } else { - router.push(route) - } - } - @ViewBuilder private func destinationView(_ route: ProfileRoute) -> some View { switch route { @@ -263,18 +247,6 @@ public struct ProfileView: View { SettingsView(store: settingsStore) { route in settingsStore.send(.select(route)) } - case .activity(let todoId): - TodoDetailView(store: Store( - initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: false) - ) { - TodoDetailFeature() - }) - case .recentTodo(let todoId): - TodoDetailView(store: Store( - initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: true) - ) { - TodoDetailFeature() - }, windowEvent: windowEvent) case .theme, .pushNotification, .account, .information: settingsPage(route) } @@ -297,7 +269,7 @@ public struct ProfileView: View { store: settingsStore.scope(state: \.account, action: \.account), settingsStore: settingsStore ) - case .settings, .activity, .recentTodo, .information: + case .settings, .information: EmptyView() } } @@ -333,8 +305,6 @@ private struct ProfileGoalSummary: View { public enum ProfileRoute: Hashable, Identifiable { case settings - case activity(String) - case recentTodo(String) case theme case pushNotification case account @@ -343,14 +313,3 @@ public enum ProfileRoute: Hashable, Identifiable { public var id: Self { self } } - -private extension ProfileRoute { - // 활동 기록 Todo는 고칠 수 없어 읽기 전용으로 표시 - var todo: (id: String, isEditable: Bool)? { - switch self { - case .activity(let todoId): (todoId, false) - case .recentTodo(let todoId): (todoId, true) - default: nil - } - } -} diff --git a/Application/Presentation/ProfileTab/Sources/Profile/RecentActivityCard.swift b/Application/Presentation/ProfileTab/Sources/Profile/RecentActivityCard.swift index 2bc14bc1..fb147da7 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/RecentActivityCard.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/RecentActivityCard.swift @@ -36,7 +36,8 @@ struct RecentActivityCard: View { } label: { RecentTodoRow( todo: todo, - isSelected: usesPaneLayout && store.selectedTodoRoute == .recentTodo(todo.id) + isSelected: usesPaneLayout && store.showsDetailInPane + && store.detail?.todoId == todo.id && store.detail?.showEditButton == true ) .todoDetailPreview(todoId: todo.id) } diff --git a/Application/Presentation/ProfileTab/Sources/Settings/DesktopSettingsView.swift b/Application/Presentation/ProfileTab/Sources/Settings/DesktopSettingsView.swift index 7ee2fead..24de779e 100644 --- a/Application/Presentation/ProfileTab/Sources/Settings/DesktopSettingsView.swift +++ b/Application/Presentation/ProfileTab/Sources/Settings/DesktopSettingsView.swift @@ -158,7 +158,7 @@ public struct DesktopSettingsView: View { // 위쪽 줄 구분선과 첫 항목 사이 여백 .contentMargins(.top, isiOSAppOnMac ? 20 * AdaptiveSize.boardScale : 24, for: .scrollContent) .background(Color.background) - case .settings, .activity, .recentTodo: + case .settings: EmptyView() } } @@ -178,7 +178,7 @@ private extension ProfileRoute { String(localized: "settings_account_section", bundle: PresentationResources.bundle) case .information: String(localized: "settings_information", bundle: PresentationResources.bundle) - case .settings, .activity, .recentTodo: + case .settings: "" } } @@ -193,7 +193,7 @@ private extension ProfileRoute { "person" case .information: "info.circle" - case .settings, .activity, .recentTodo: + case .settings: "" } } diff --git a/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift b/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift index 2bd3a6f3..9084aa4a 100644 --- a/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift +++ b/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift @@ -317,6 +317,28 @@ private final class UpdateHeatmapActivityTypesUseCaseSpy: UpdateHeatmapActivityT func execute(_ activityTypes: [String]) { self.activityTypes.append(activityTypes) } + + @Test("ProfileFeature는 고른 Todo를 연 자리에서 바꾸고, 상세를 닫으면 오른쪽 칸 표시도 끈다") + func ProfileFeature는_고른_Todo를_연_자리에서_바꾸고_상세를_닫으면_오른쪽_칸_표시도_끈다() async { + let store = TestStore(initialState: ProfileFeature.State()) { + ProfileFeature() + } + + await store.send(.selectTodo("activity", isEditable: false)) { + $0.detail = TodoDetailFeature.State(todoId: "activity", showEditButton: false) + } + await store.send(.binding(.set(\.showsDetailInPane, true))) { + $0.showsDetailInPane = true + } + // 같은 Todo도 최근 Todo에서 고르면 편집할 수 있는 상세로 바꿈 + await store.send(.selectTodo("activity", isEditable: true)) { + $0.detail = TodoDetailFeature.State(todoId: "activity", showEditButton: true) + } + await store.send(.detail(.dismiss)) { + $0.detail = nil + $0.showsDetailInPane = false + } + } } @MainActor From 03298e064a0edc28b73055a78a947116f63ff469 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 09/25] =?UTF-8?q?refactor:=20=EC=9C=84=EC=A0=AF=EA=B3=BC?= =?UTF-8?q?=20=ED=91=B8=EC=8B=9C=20=EC=95=8C=EB=A6=BC=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=97=B0=20Todo=20=EC=83=81=EC=84=B8=EB=A5=BC=20=EB=A3=A8?= =?UTF-8?q?=ED=8A=B8=20Feature=EA=B0=80=20TodoDetailFeature.State=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=B4=EA=B4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entry/Sources/Root/Feature.swift | 34 ++++--------------- .../Entry/Sources/Root/RootView.swift | 18 +++------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/Application/Presentation/Entry/Sources/Root/Feature.swift b/Application/Presentation/Entry/Sources/Root/Feature.swift index c5fe27a2..11106d10 100644 --- a/Application/Presentation/Entry/Sources/Root/Feature.swift +++ b/Application/Presentation/Entry/Sources/Root/Feature.swift @@ -22,7 +22,8 @@ struct Feature { @ObservableState struct State: Equatable { @Presents var alert: AlertState? - @Presents var sheet: SheetState? + // 위젯과 푸시 알림으로 연 보기 전용 Todo 상세 + @Presents var sheet: TodoDetailFeature.State? var hasCheckedAppUpdate = false var isAppUpdateRequired = false var isNetworkConnected = true @@ -36,17 +37,11 @@ struct Feature { var isObservingTheme = false } - @ObservableState - struct SheetState: Equatable, Identifiable { - let todoId: String - var id: String { todoId } - } - enum Action: Equatable { case alert(PresentationAction) case appUpdateCheckCompleted(Bool) case composition(CompositionFeature.Action) - case sheet(PresentationAction) + case sheet(PresentationAction) case onAppear case presentTodoDetail(String) case openWidgetRoute(WidgetRoute) @@ -58,10 +53,6 @@ struct Feature { enum Alert: Equatable { case tapUpdateButton } - - enum Sheet: Equatable { - case tapCloseButton - } } @Dependency(\.observeAuthSessionUseCase) var observeAuthSessionUseCase @@ -87,8 +78,6 @@ struct Feature { state.alert = Self.appUpdateAlertState() case .composition: break - case .sheet(.dismiss), .sheet(.presented(.tapCloseButton)): - state.sheet = nil case .sheet: break case .onAppear: @@ -116,7 +105,7 @@ struct Feature { return effect case .presentTodoDetail(let todoId): - state.sheet = .init(todoId: todoId) + state.sheet = TodoDetailFeature.State(todoId: todoId, showEditButton: false) case .openWidgetRoute(let route): // 로그아웃 상태면 로그인 화면만 보이고 위젯 경로는 버림 guard state.signIn != false else { break } @@ -127,7 +116,7 @@ struct Feature { case .tab(let tab): return .send(.composition(.selectTab(tab))) case .todayTodo(let id): - state.sheet = .init(todoId: id) + state.sheet = TodoDetailFeature.State(todoId: id, showEditButton: false) } case .networkStatusChanged(let isConnected): let wasConnected = state.isNetworkConnected @@ -166,7 +155,7 @@ struct Feature { case .tab(let tab): composition.selectedTab = tab case .todayTodo(let id): - state.sheet = .init(todoId: id) + state.sheet = TodoDetailFeature.State(todoId: id, showEditButton: false) case nil: break } @@ -181,20 +170,11 @@ struct Feature { } .ifLet(\.$alert, action: \.alert) .ifLet(\.$sheet, action: \.sheet) { - SheetFeature() + TodoDetailFeature() } } } -private struct SheetFeature: Reducer { - typealias State = Feature.SheetState - typealias Action = Feature.Action.Sheet - - var body: some ReducerOf { - EmptyReducer() - } -} - extension DependencyValues { var appStoreURL: URL? { get { self[AppStoreURLKey.self] } diff --git a/Application/Presentation/Entry/Sources/Root/RootView.swift b/Application/Presentation/Entry/Sources/Root/RootView.swift index bd0ae654..b0a3dcda 100644 --- a/Application/Presentation/Entry/Sources/Root/RootView.swift +++ b/Application/Presentation/Entry/Sources/Root/RootView.swift @@ -48,7 +48,11 @@ public struct RootView: View { } .prominentAlert(store, state: \.alert, action: \.alert) .prominentSheet(item: $store.scope(state: \.sheet, action: \.sheet)) { sheetStore in - sheetContent(todoId: sheetStore.todoId) + NavigationStack { + TodoDetailView(store: sheetStore) + } + .environment(\.deviceType, .bar) + .background(Color.background) } .onReceive(pushNotificationTodoIdPublisher) { todoId in store.send(.presentTodoDetail(todoId)) @@ -57,16 +61,4 @@ public struct RootView: View { // 글자 크기를 정하지 않은 글자도 Mac 크기로 표시 .font(AdaptiveSize.macFontSize(.body).map { .system(size: $0) }) } - - private func sheetContent(todoId: String) -> some View { - NavigationStack { - TodoDetailView(store: Store( - initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: false) - ) { - TodoDetailFeature() - }) - } - .environment(\.deviceType, .bar) - .background(Color.background) - } } From 59268ffad308109325a173d6948994efb748fee6 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 10/25] =?UTF-8?q?refactor:=20TodoDetailPane,=20TodoDetailP?= =?UTF-8?q?anelFeature=EC=99=80=20PaneSplitView=EC=9D=98=20isDetailPresent?= =?UTF-8?q?ing=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Todo/List/TodoListView.swift | 6 +- .../Sources/PushNotificationListView.swift | 2 +- .../Common/Component/PanePlaceholder.swift | 30 ++++++++ .../Common/Component/PaneSplitView.swift | 50 +------------ .../Sources/Todo/Detail/TodoDetailPane.swift | 70 ------------------- .../Todo/Detail/TodoDetailPanelFeature.swift | 43 ------------ .../Sources/Todo/Detail/TodoDetailView.swift | 2 - .../Tests/Todo/TodoDetailFeatureTests.swift | 57 +++++++++++++++ .../Sources/Profile/ProfileFeature.swift | 6 +- .../Sources/Profile/ProfileView.swift | 2 +- .../TodayTab/Sources/TodayView.swift | 2 +- 11 files changed, 98 insertions(+), 172 deletions(-) create mode 100644 Application/Presentation/PresentationShared/Sources/Common/Component/PanePlaceholder.swift delete mode 100644 Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPane.swift delete mode 100644 Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanelFeature.swift diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift index 00b35531..e99be1f1 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift @@ -14,7 +14,6 @@ import PresentationShared struct TodoListView: View { @Environment(\.isTabContentActive) private var isTabContentActive @Environment(\.usesDesktopLayout) private var usesDesktopLayout - @Environment(\.usesPaneLayout) private var usesPaneLayout @State private var store: StoreOf private let windowEvent: TodoEditorWindowEvent? @@ -31,8 +30,7 @@ struct TodoListView: View { } } detail: { // 칸으로 나눈 화면은 새 Todo를 덮는 화면 대신 상세 칸 자리에서 작성 - if usesPaneLayout, - let editorStore = store.scope( + if let editorStore = store.scope( state: \.fullScreenCover?.todoEditor, action: \.fullScreenCover.presented.todoEditor ) { @@ -43,7 +41,7 @@ struct TodoListView: View { store: detailStore, windowEvent: windowEvent, isPaneDetail: true, - onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil + onClose: { store.send(.detail(.dismiss)) } ) .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 diff --git a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift index d6266d89..b2fbe69e 100644 --- a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift +++ b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift @@ -49,7 +49,7 @@ public struct PushNotificationListView: View { TodoDetailView( store: detailStore, isPaneDetail: true, - onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil + onClose: { store.send(.detail(.dismiss)) } ) .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/PanePlaceholder.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/PanePlaceholder.swift new file mode 100644 index 00000000..11be70d2 --- /dev/null +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/PanePlaceholder.swift @@ -0,0 +1,30 @@ +// +// PanePlaceholder.swift +// PresentationShared +// +// Created by opfic on 11/13/26. +// + +import SwiftUI + +// 상세 칸에서 고른 항목이 없을 때 표시하는 안내 +public struct PanePlaceholder: View { + public init() {} + + public var body: some View { + VStack(spacing: 12) { + Image(systemName: "doc.text") + .font(.adaptive(.largeTitle)) + .foregroundStyle(Color.tertiaryLabel) + Text("pane_select_detail", bundle: PresentationResources.bundle) + .font(.adaptive(.callout)) + .foregroundStyle(Color.secondaryLabel) + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + // 목록 칸 제목 줄과 구분선 높이 맞춤 + .safeAreaInset(edge: .top, spacing: 0) { + PaneTitleBar(Text(verbatim: "")) + } + .background(Color.background) + } +} diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift index 4372d727..7d172058 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift @@ -13,8 +13,6 @@ public struct PaneSplitView: View { @State private var width = CGFloat.infinity // 경계선을 끌어 정한 목록 칸 폭, 없으면 기본 폭 @State private var primaryWidth: CGFloat? - // 상세 칸이 편집 화면처럼 화면을 덮는 표시를 띄운 동안 - @State private var isDetailPresenting = false // 상세 칸에 작성 화면을 그린 동안 @State private var isDetailEditing = false // 사이드바가 있는 창은 따로 정한 화면만 두 칸으로 나눔 @@ -60,23 +58,19 @@ public struct PaneSplitView: View { value = nil } } - // 좁은 창으로 바뀌어도 상세 칸이 띄운 편집 화면이 닫히지 않도록 폭 0으로 남겨 두고 닫히면 해제 - if showsDetail || isDetailPresenting { + // 좁은 창으로 바뀌면 상세 칸을 빼고, 같은 상태를 화면이 좁은 창의 표시로 이어 그림 + if showsDetail { // 상세 칸이 기본 폭보다 좁으면 내용을 줄이지 않고 잘라서 표시 Color.clear .overlay(alignment: .leading) { detail() - .frame(minWidth: showsDetail ? paneWidth : 0, maxWidth: .infinity) + .frame(minWidth: paneWidth, maxWidth: .infinity) // 사이드바 펴기 버튼은 왼쪽 칸 제목 줄에만 표시 .environment(\.expandSideBar, nil) - .onPreferenceChange(PaneDetailPresentingPreferenceKey.self) { isPresenting in - isDetailPresenting = isPresenting - } .onPreferenceChange(PaneDetailEditingPreferenceKey.self) { isEditing in isDetailEditing = isEditing } } - .frame(maxWidth: showsDetail ? .infinity : 0) .mask { Rectangle() } @@ -101,44 +95,6 @@ public struct PaneSplitView: View { } } -public extension View { - // 사이드바 구조로 바뀌면 좁은 창에서 쌓아 연 상세 화면을 내리는 동작 - // 상세 화면이 편집 화면을 띄운 동안에는 닫힌 뒤 실행 - func closesPushedDetail(_ action: @escaping () -> Void) -> some View { - modifier(PushedDetailCloser(action: action)) - } -} - -private struct PushedDetailCloser: ViewModifier { - @Environment(\.usesDesktopLayout) private var usesDesktopLayout - @State private var isDetailPresenting = false - let action: () -> Void - - func body(content: Content) -> some View { - content - .onPreferenceChange(PaneDetailPresentingPreferenceKey.self) { isPresenting in - isDetailPresenting = isPresenting - if usesDesktopLayout && !isPresenting { - action() - } - } - .onChange(of: usesDesktopLayout) { _, isDesktop in - if isDesktop && !isDetailPresenting { - action() - } - } - } -} - -// 상세 칸이 편집 화면처럼 화면을 덮는 표시를 띄웠는지 전달 -struct PaneDetailPresentingPreferenceKey: PreferenceKey { - static let defaultValue = false - - static func reduce(value: inout Bool, nextValue: () -> Bool) { - value = value || nextValue() - } -} - // 상세 칸에 저장·닫기 버튼으로만 닫는 작성 화면을 그렸는지 전달 public struct PaneDetailEditingPreferenceKey: PreferenceKey { public static let defaultValue = false diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPane.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPane.swift deleted file mode 100644 index 34f02bcb..00000000 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPane.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// TodoDetailPane.swift -// PresentationShared -// -// Created by opfic on 11/13/26. -// - -import SwiftUI -import ComposableArchitecture - -// 사이드바가 있는 창에서 목록 오른쪽 칸의 Todo 상세, 선택 전에는 선택 안내 -public struct TodoDetailPane: View { - private let todoId: String? - private let showEditButton: Bool - private let windowEvent: TodoEditorWindowEvent? - private let onClose: (() -> Void)? - - public init( - todoId: String?, - showEditButton: Bool, - windowEvent: TodoEditorWindowEvent? = nil, - onClose: (() -> Void)? = nil - ) { - self.todoId = todoId - self.showEditButton = showEditButton - self.windowEvent = windowEvent - self.onClose = onClose - } - - public var body: some View { - if let todoId { - TodoDetailView( - store: Store( - initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: showEditButton) - ) { - TodoDetailFeature() - }, - windowEvent: windowEvent, - isPaneDetail: true, - onClose: onClose - ) - .environment(\.showsPaneTitleBar, true) - .id(todoId) - } else { - PanePlaceholder() - } - } -} - -// 상세 칸에서 고른 항목이 없을 때 표시하는 안내 -public struct PanePlaceholder: View { - public init() {} - - public var body: some View { - VStack(spacing: 12) { - Image(systemName: "doc.text") - .font(.adaptive(.largeTitle)) - .foregroundStyle(Color.tertiaryLabel) - Text("pane_select_detail", bundle: PresentationResources.bundle) - .font(.adaptive(.callout)) - .foregroundStyle(Color.secondaryLabel) - } - .frame(maxWidth: .infinity, maxHeight: .infinity) - // 목록 칸 제목 줄과 구분선 높이 맞춤 - .safeAreaInset(edge: .top, spacing: 0) { - PaneTitleBar(Text(verbatim: "")) - } - .background(Color.background) - } -} diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanelFeature.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanelFeature.swift deleted file mode 100644 index 9b76d6f9..00000000 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPanelFeature.swift +++ /dev/null @@ -1,43 +0,0 @@ -// -// TodoDetailPanelFeature.swift -// PresentationShared -// -// Created by opfic on 11/16/26. -// - -import ComposableArchitecture - -// Mac 상세 판의 보기 전용 Todo 상세와 판 안 세부 정보 열 -@Reducer -public struct TodoDetailPanelFeature { - @ObservableState - public struct State: Equatable { - var detail: TodoDetailFeature.State - // 판 메뉴의 중요 표시와 완료도 세부 정보 열과 같이 바로 저장 - var sideBar: TodoDetailSideBarFeature.State - var isDetailColumnPresented = false - - public init(todoId: String, isEditable: Bool) { - self.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: false) - self.sideBar = TodoDetailSideBarFeature.State(todoId: todoId, isEditable: isEditable) - } - } - - public enum Action: BindableAction { - case binding(BindingAction) - case detail(TodoDetailFeature.Action) - case sideBar(TodoDetailSideBarFeature.Action) - } - - public init() { } - - public var body: some ReducerOf { - BindingReducer() - Scope(state: \.detail, action: \.detail) { - TodoDetailFeature() - } - Scope(state: \.sideBar, action: \.sideBar) { - TodoDetailSideBarFeature() - } - } -} diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailView.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailView.swift index 802f13c6..b4dd6b66 100644 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailView.swift +++ b/Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailView.swift @@ -52,8 +52,6 @@ public struct TodoDetailView: View { detailContent(editsInPane: editsInPane) .onAppear { store.send(.onAppear) } - // 좁은 창으로 바뀌어도 편집 화면이 닫히지 않도록 상세 칸을 남겨 두게 알림 - .preference(key: PaneDetailPresentingPreferenceKey.self, value: store.fullScreenCover != nil) // 편집 화면에서 저장하면 창 폭과 상관없이 Mac 편집 창과 같은 경로로 옆 목록에도 전달 // 편집 화면이 닫히며 놓치지 않도록 상세 상태에 남긴 저장 결과로 전달 .onChange(of: store.savedTodo) { _, todo in diff --git a/Application/Presentation/PresentationShared/Tests/Todo/TodoDetailFeatureTests.swift b/Application/Presentation/PresentationShared/Tests/Todo/TodoDetailFeatureTests.swift index 179170f6..6c8e06da 100644 --- a/Application/Presentation/PresentationShared/Tests/Todo/TodoDetailFeatureTests.swift +++ b/Application/Presentation/PresentationShared/Tests/Todo/TodoDetailFeatureTests.swift @@ -284,6 +284,48 @@ struct TodoDetailFeatureTests { #expect(adapter.infoEditor?.tags == ["tag"]) } + @Test("화면을 옮겨 그려 다시 나타나도 다시 조회하지 않고, 다시 조회를 요청하면 조회한다") + func 화면을_옮겨_그려_다시_나타나도_다시_조회하지_않고_다시_조회를_요청하면_조회한다() async { + let todo = makeTodo(id: "todo-1", content: "content") + let fetchSpy = FetchTodoByIdUseCaseSpy(todo: todo) + let adapter = DetailStoreTestAdapter( + fetchUseCase: fetchSpy, + referenceUseCase: FetchReferenceItemsUseCaseSpy(), + todoId: "todo-1" + ) + + adapter.onAppear() + + await waitUntil { + adapter.todo == todo + } + + adapter.onAppear() + adapter.fetch() + + await waitUntil { + fetchSpy.todoIds.count == 2 + } + + #expect(fetchSpy.todoIds == ["todo-1", "todo-1"]) + } + + @Test("상세 판 세부 정보 열에서 저장에 실패하면 열 안 알림을 그대로 둔다") + func 상세_판_세부_정보_열에서_저장에_실패하면_열_안_알림을_그대로_둔다() async { + let upsertSpy = TodoEditorUpsertTodoUseCaseSpy() + upsertSpy.error = DetailTestError.failure + let adapter = makeInfoAdapter(upsertSpy: upsertSpy) + + await adapter.openDetailColumnAndTogglePinned() + + await waitUntil { + adapter.infoEditor?.alert != nil + } + + #expect(adapter.infoEditor?.alert != nil) + #expect(adapter.alert == nil) + } + private func makeInfoAdapter(upsertSpy: TodoEditorUpsertTodoUseCaseSpy) -> DetailStoreTestAdapter { DetailStoreTestAdapter( fetchUseCase: FetchTodoByIdUseCaseSpy(todo: makeTodo()), @@ -369,6 +411,10 @@ private struct DetailStoreTestAdapter: DetailTestAdapter { store.send(.onAppear) } + func fetch() { + store.send(.fetch) + } + func onSheetTodoAppear() { store.send(.sheet(.presented(.todo(.onAppear)))) } func setSheet(_ sheet: TodoDetailFeature.SheetState?) { @@ -412,6 +458,17 @@ private struct DetailStoreTestAdapter: DetailTestAdapter { await openInfo() store.send(.info(.editor(.binding(.set(\.isPinned, true))))) } + + func openDetailColumnAndTogglePinned() async { + store.send(.setDetailColumnPresented(true)) + store.send(.info(.onAppear)) + + await waitUntil { + store.info.editor != nil + } + + store.send(.info(.editor(.binding(.set(\.isPinned, true))))) + } } private func todoDetailState( diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift index b78a986f..eaec6a40 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileFeature.swift @@ -34,6 +34,9 @@ struct ProfileFeature { @ObservableState struct State: Equatable { @Presents var alert: AlertState? + // 활동 기록이나 최근 Todo에서 연 Todo 상세, 활동 기록 Todo는 고칠 수 없어 편집 버튼 없이 표시 + // 좁은 창은 내비게이션에 쌓고 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + @Presents var detail: TodoDetailFeature.State? var name = "" var email = "" var isNetworkConnected = true @@ -54,9 +57,6 @@ struct ProfileFeature { var dayActivitiesByDate: [Date: [HeatmapActivityItem]] = [:] var selectedActivityKinds: Set = [.created, .completed, .deleted] var selectedDay: HeatmapDay? - // 활동 기록이나 최근 Todo에서 연 Todo 상세, 활동 기록 Todo는 고칠 수 없어 편집 버튼 없이 표시 - // 좁은 창은 내비게이션에 쌓고 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 - @Presents var detail: TodoDetailFeature.State? // 사이드바가 있는 창에서 상세 판 대신 오른쪽 칸에 표시 var showsDetailInPane = false var showDoneButton = false diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index 3a7ca9b4..cfba632d 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -76,7 +76,7 @@ public struct ProfileView: View { store: detailStore, windowEvent: detailStore.showEditButton ? windowEvent : nil, isPaneDetail: true, - onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil + onClose: { store.send(.detail(.dismiss)) } ) .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 diff --git a/Application/Presentation/TodayTab/Sources/TodayView.swift b/Application/Presentation/TodayTab/Sources/TodayView.swift index 4ee69486..15f15f15 100644 --- a/Application/Presentation/TodayTab/Sources/TodayView.swift +++ b/Application/Presentation/TodayTab/Sources/TodayView.swift @@ -133,7 +133,7 @@ public struct TodayView: View { store: detailStore, windowEvent: windowEvent, isPaneDetail: true, - onClose: usesDesktopLayout ? { store.send(.detail(.dismiss)) } : nil + onClose: { store.send(.detail(.dismiss)) } ) .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 From 18269b2e51f0765d6da55c664dcb80909dcbe603 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 11/25] =?UTF-8?q?fix:=20ProminentPresentation=EC=9D=B4=20?= =?UTF-8?q?=EB=8B=AB=ED=9E=98=EC=9D=B4=20=EB=81=9D=EB=82=A0=20=EB=95=8C=20?= =?UTF-8?q?=EB=9D=84=EC=9A=B8=20=EB=95=8C=20=EC=9E=A1=EC=9D=80=20=EB=B0=94?= =?UTF-8?q?=EC=9D=B8=EB=94=A9=20=EB=8C=80=EC=8B=A0=20=EC=A7=80=EA=B8=88=20?= =?UTF-8?q?=EB=9D=84=EC=9A=B0=EB=9D=BC=EA=B3=A0=20=ED=95=9C=20=ED=95=AD?= =?UTF-8?q?=EB=AA=A9=EC=9D=84=20=EC=9D=BD=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Common/Component/ProminentPresentation.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/ProminentPresentation.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/ProminentPresentation.swift index c01ebb99..79de76d6 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/ProminentPresentation.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/ProminentPresentation.swift @@ -19,6 +19,8 @@ struct ProminentPresentation: ViewModifier { @State private var isDismissing = false @State private var isShown = false @State private var presented: Item? + // 지금 띄우라고 한 항목이 있는지, 닫힘이 끝날 때 띄울 때 잡아 둔 바인딩 대신 읽음 + @State private var isRequested = false let item: Binding @ViewBuilder let overlay: (Item, Bool, @escaping () -> Void) -> Overlay @@ -30,6 +32,7 @@ struct ProminentPresentation: ViewModifier { content .onChange(of: item.wrappedValue?.id, initial: true) { _, id in + isRequested = id != nil if id == nil { hide(isAnimated: isAnimated) } else { @@ -48,7 +51,7 @@ struct ProminentPresentation: ViewModifier { ), onDismiss: { isDismissing = false - if item.wrappedValue == nil { + if !isRequested { presented = nil } else { // 닫히는 동안 들어온 표시는 닫힘이 끝난 뒤 다시 띄움 From f81894851e59ed75a7aefa2ad76358fa7e62e55a Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 12/25] =?UTF-8?q?fix:=20=EC=8C=93=EC=9D=80=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=97=90=20=EA=B0=80=EB=A0=A4=EC=A7=84=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EB=8F=84=20=EC=B0=BD=20=ED=8F=AD=20=EB=B3=80=ED=99=94?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20CompositionContainer?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=EC=9E=90=EA=B0=80=20LiveLayout=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A7=80=EA=B8=88=20=ED=8F=AD=EC=9D=84=20=EC=9D=BD?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HomeTab/Sources/Home/HomeView.swift | 7 +++- .../Component/CompositionContainer.swift | 37 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index c18e067e..ef8bcd2f 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -100,7 +100,12 @@ public struct HomeView: View { case .search: true } }, - destination: { destinationView($0).environment(\.showsPaneTitleBar, usesPaneLayout) } + destination: { + destinationView($0) + .environment(\.showsPaneTitleBar, usesPaneLayout) + // 위에 쌓은 화면에 가려진 동안에도 창 폭이 바뀐 것을 받아 쌓아 연 상세를 옮김 + .environment(\.usesDesktopLayout, usesDesktopLayout) + } ) } .desktopNavigationTransition() diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index 1427a61f..b2b13616 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -71,8 +71,22 @@ public extension View { } } +// 창 폭이 바뀐 뒤 시스템이 표시할 때 받아 둔 바인딩으로 늦게 닫아도 지금 창 폭으로 거르도록 참조로 보관하는 값 +private final class LiveLayout { + private(set) var usesDesktopLayout = false + private(set) var inPane = false + + // 그릴 때마다 지금 값으로 바꾸고 같은 참조를 돌려줌 + func update(usesDesktopLayout: Bool, inPane: Bool = false) -> LiveLayout { + self.usesDesktopLayout = usesDesktopLayout + self.inPane = inPane + return self + } +} + private struct CompositionDetailModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @State private var layout = LiveLayout() let item: Binding let narrow: CompositionNarrow let inPane: Bool @@ -82,8 +96,10 @@ private struct CompositionDetailModifier some View { // 창 폭이 바뀌면 같은 상태를 짝이 되는 컨테이너가 다시 그리고, 빠지는 쪽의 늦은 닫힘은 상태를 지우지 않음 - let narrowItem = item.hiddenInPane(usesDesktopLayout) - let panelItem = item.activePresentation(when: isActive).hiddenInPane(!usesDesktopLayout || inPane) + let layout = layout.update(usesDesktopLayout: usesDesktopLayout, inPane: inPane) + let narrowItem = item.hiddenInPane { layout.usesDesktopLayout } + let panelItem = item.activePresentation(when: isActive) + .hiddenInPane { !layout.usesDesktopLayout || layout.inPane } switch narrow { case .push: @@ -104,6 +120,7 @@ private struct CompositionDetailModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @State private var layout = LiveLayout() let item: Binding let narrow: CompositionNarrow let inPane: Bool @@ -111,7 +128,8 @@ private struct CompositionEditorModifier: View func body(content: Content) -> some View { // 넓은 창으로 바뀌어 칸에 옮겨 그린 뒤 늦게 닫히는 화면은 작성 중인 초안을 지우지 않음 - let narrowItem = item.hiddenInPane(usesDesktopLayout) + let layout = layout.update(usesDesktopLayout: usesDesktopLayout) + let narrowItem = item.hiddenInPane { layout.usesDesktopLayout } switch (narrow, inPane) { case (.cover, true): @@ -123,7 +141,7 @@ private struct CompositionEditorModifier: View case (.cover, false): content .fullScreenCover(item: narrowItem, content: editor) - .prominentSheet(item: item.hiddenInPane(!usesDesktopLayout), content: editor) + .prominentSheet(item: item.hiddenInPane { !layout.usesDesktopLayout }, content: editor) case (.sheet, false): content .prominentSheet(item: item, content: editor) @@ -136,6 +154,7 @@ private struct CompositionEditorModifier: View private struct CompositionCenterModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @State private var layout = LiveLayout() let item: Binding let narrow: CompositionNarrow let isActive: Bool @@ -143,7 +162,8 @@ private struct CompositionCenterModifier: View func body(content: Content) -> some View { // 창 폭이 바뀌어도 좁은 창의 표시를 같은 화면에 두어, 넓어진 뒤 늦게 닫히는 표시가 상태를 지우지 않음 - let narrowItem = item.activePresentation(when: isActive).hiddenInPane(usesDesktopLayout) + let layout = layout.update(usesDesktopLayout: usesDesktopLayout) + let narrowItem = item.activePresentation(when: isActive).hiddenInPane { layout.usesDesktopLayout } let shown = Group { if usesDesktopLayout, let value = item.wrappedValue { center(value) @@ -169,14 +189,19 @@ private struct CompositionCenterModifier: View private struct CompositionSheetModifier: ViewModifier { @Environment(\.isTabContentActive) private var isTabContentActive @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @State private var layout = LiveLayout() let item: Binding let sheet: (Item) -> Sheet let right: (Item) -> Right func body(content: Content) -> some View { + // 넓은 창으로 바뀌어 세부 정보 사이드바로 옮긴 뒤 늦게 닫히는 시트는 고른 항목을 지우지 않음 + let layout = layout.update(usesDesktopLayout: usesDesktopLayout) + content .prominentSheet( - item: item.activePresentation(when: isTabContentActive && !usesDesktopLayout), + item: item.activePresentation(when: isTabContentActive) + .hiddenInPane { layout.usesDesktopLayout }, content: sheet ) // 고른 항목이 없으면 세부 정보 사이드바에 안내 표시 From 9514568572b78b4002431b8de6b52d37e727a4ed Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 13/25] =?UTF-8?q?fix:=20=EA=B0=9C=EB=B0=9C=20=EB=AA=A9?= =?UTF-8?q?=ED=91=9C=20=EC=83=81=EC=84=B8=20=EC=95=88=20Todo=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=EA=B0=80=20=EC=B0=BD=20=ED=8F=AD=EC=9D=B4=20=EB=B0=94?= =?UTF-8?q?=EB=80=8C=EC=96=B4=EB=8F=84=20=EC=9D=B4=EC=96=B4=EC=A7=80?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Record/GoalDetail/GoalDetailFeature.swift | 13 +++++++++++++ .../Sources/Record/GoalDetail/GoalDetailView.swift | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift index d4ccfb33..2453cc18 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailFeature.swift @@ -54,6 +54,8 @@ struct GoalDetailFeature { var shownOnDesktop: Bool? // 창 폭이 바뀌어 빠지는 자리가 먼저 닫은 기록 상세, 같은 차례에 새 자리가 나타나면 되살림 var dismissedRecordDetail: RecordDetailDestination? + // 창 폭이 바뀌어 빠지는 자리가 먼저 닫은 Todo 상세, 같은 차례에 새 자리가 나타나면 되살림 + var dismissedTodoDetail: TodoDetailFeature.State? var goalTitle: String { goal?.title ?? "" @@ -117,6 +119,7 @@ struct GoalDetailFeature { case todosFailed case transitionFailed case recordDetailDismissed + case todoDetailDismissed } enum Delegate: Equatable { @@ -164,6 +167,11 @@ struct GoalDetailFeature { } case .recordDetail, .recordDetailContent: break + case .todoDetail(.dismiss): + state.dismissedTodoDetail = state.todoDetail + return .run { send in + await send(.store(.todoDetailDismissed)) + } case .todoDetail: break case .todoLinkSheet(.dismiss), @@ -195,6 +203,9 @@ struct GoalDetailFeature { if state.recordDetail == nil { state.recordDetail = state.dismissedRecordDetail } + if state.todoDetail == nil { + state.todoDetail = state.dismissedTodoDetail + } state.recordDetailContent?.restoreDismissedScreens() } state.shownOnDesktop = onDesktop @@ -330,6 +341,8 @@ struct GoalDetailFeature { if state.recordDetail == nil { state.recordDetailContent = nil } + case .store(.todoDetailDismissed): + state.dismissedTodoDetail = nil } return .none diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index f97274f3..28dbc6ab 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -113,8 +113,9 @@ public struct GoalDetailView: View { } .desktopNavigationTransition() } + // 창 폭이 바뀌면 개발 목표가 새 자리에 나타난 뒤에 다시 쌓음 .navigationDestination( - item: $store.scope(state: \.todoDetail, action: \.todoDetail), + item: $store.scope(state: \.todoDetail, action: \.todoDetail).hiddenInPane(isHidden), interactivePop: true ) { // 사이드바가 있으면 Todo 목록 옆 칸의 상세와 같은 칸 모양으로 표시하고 뒤로 가면 개발 목표로 돌아감 From 9121e2abbf3da690ad5e569acce17c354884cda0 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 14/25] =?UTF-8?q?refactor:=20compositionSheet,=20compositi?= =?UTF-8?q?onRight=EC=9D=98=20reveal=EA=B3=BC=20compositionCenter=EC=9D=98?= =?UTF-8?q?=20closesRight=EB=A1=9C=20=EC=84=B8=EB=B6=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=82=AC=EC=9D=B4=EB=93=9C=EB=B0=94=EB=A5=BC=20?= =?UTF-8?q?=EC=97=B4=EA=B3=A0=20=EB=8B=AB=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Category/CategoryManageFeature.swift | 4 ++ .../Sources/Category/CategoryManageView.swift | 21 ++------ .../HomeTab/Sources/Home/HomeView.swift | 11 +---- .../Component/CompositionContainer.swift | 48 +++++++++++++++++-- .../Common/Component/DetailSideBar.swift | 12 ++++- .../TodayTab/Sources/TodayFeature+State.swift | 2 + .../TodayTab/Sources/TodayFeature.swift | 2 + .../TodayTab/Sources/TodayView.swift | 8 ++-- 8 files changed, 73 insertions(+), 35 deletions(-) diff --git a/Application/Presentation/HomeTab/Sources/Category/CategoryManageFeature.swift b/Application/Presentation/HomeTab/Sources/Category/CategoryManageFeature.swift index 634143e4..d2ff8495 100644 --- a/Application/Presentation/HomeTab/Sources/Category/CategoryManageFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Category/CategoryManageFeature.swift @@ -15,6 +15,8 @@ struct CategoryManageFeature { struct State: Equatable { @Presents var categorySheet: CategorySheetState? @Presents var alert: AlertState? + // 추가하거나 고칠 카테고리를 세부 정보 사이드바에 보여 달라고 한 횟수, 바뀌면 닫힌 세부 정보 사이드바를 엶 + var revealCount = 0 var preferences: [TodoCategoryItem] } @@ -128,6 +130,7 @@ struct CategoryManageFeature { case .categorySheet: break case .tapAddUserCategory: + state.revealCount += 1 if let randomHexValue = Color.randomValue.hexValue { // 목록에 새 카테고리를 바로 만들고 고른 채로 시트나 세부 정보 사이드바에 표시 let category = UserTodoCategory( @@ -156,6 +159,7 @@ struct CategoryManageFeature { state.categorySheet?.preferences = preferences return .send(.delegate(.changed(state.preferences))) case .tapEditUserCategory(let item): + state.revealCount += 1 if item.isUserCategory, case .user(let category) = item.category { state.categorySheet = CategorySheetState( category: category, diff --git a/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift b/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift index b23a7330..29b14d4f 100644 --- a/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift +++ b/Application/Presentation/HomeTab/Sources/Category/CategoryManageView.swift @@ -9,10 +9,8 @@ import SwiftUI import PresentationShared struct CategoryManageView: View { - @Environment(\.isTabContentActive) private var isTabContentActive @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac @Environment(\.usesDesktopLayout) private var usesDesktopLayout - @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @Bindable var store: StoreOf // 좁은 창에서 시트로 연 카테고리 관리를 닫는 동작 var onClose: (() -> Void)? @@ -40,9 +38,6 @@ struct CategoryManageView: View { footer: UIHostingConfiguration { Button { store.send(.tapAddUserCategory) - if usesDesktopLayout { - setDetailSideBarPresented?(true) - } } label: { Text("todo_manage_add_category_title", bundle: PresentationResources.bundle) .font(.adaptive(isiOSAppOnMac ? .headline : .subheadline).weight(.semibold)) @@ -65,10 +60,7 @@ struct CategoryManageView: View { CategoryManageRow( item: item, onToggle: { store.send(.tapItem(item)) }, - onEdit: { - store.send(.tapEditUserCategory(item)) - setDetailSideBarPresented?(true) - }, + onEdit: { store.send(.tapEditUserCategory(item)) }, onDelete: { store.send(.tapDeleteUserCategory(item)) }, onSelect: usesDesktopLayout ? { store.send(.selectCategory(item)) } : nil ) @@ -102,7 +94,10 @@ struct CategoryManageView: View { } .background((usesDesktopLayout ? Color.background : .secondaryBackground).ignoresSafeArea()) // 사이드바가 있으면 고른 카테고리를 시트 대신 세부 정보 사이드바에 표시 - .compositionSheet(item: $store.scope(state: \.categorySheet, action: \.categorySheet)) { sheetStore in + .compositionSheet( + item: $store.scope(state: \.categorySheet, action: \.categorySheet), + reveal: store.revealCount + ) { sheetStore in CategoryManageSheet(store: sheetStore) } right: { sheetStore in ScrollView { @@ -114,12 +109,6 @@ struct CategoryManageView: View { } } .prominentAlert(store, state: \.alert, action: \.alert) - // 카테고리 관리를 벗어나면 카테고리를 보여 주던 세부 정보 사이드바도 닫음 - .onChange(of: isTabContentActive) { _, isActive in - if usesDesktopLayout && !isActive { - setDetailSideBarPresented?(false) - } - } } } diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index ef8bcd2f..d7797b72 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -16,7 +16,6 @@ public struct HomeView: View { @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.deviceType) private var deviceType @Environment(\.sideBarRequest) private var sideBarRequest - @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @State private var router = NavigationRouter() @State private var store: StoreOf private let isSelected: Bool @@ -78,7 +77,8 @@ public struct HomeView: View { .compositionCenter( item: $store.scope(state: \.sheet?.categoryManageState, action: \.sheet.categoryManage), narrow: .sheet, - isActive: isSelected + isActive: isSelected, + closesRight: true ) { manageStore in CategoryManageView(store: manageStore) { store.send(.sheet(.dismiss)) @@ -139,13 +139,6 @@ public struct HomeView: View { store.send(.view(.fetchData)) } } - // 카테고리 관리를 벗어나면 카테고리를 보여 주던 세부 정보 사이드바도 닫음 - // 창 폭이 바뀌어 칸과 시트를 오갈 때는 카테고리 관리 상태가 남아 닫지 않음 - .onChange(of: store.sheet?.categoryManageState == nil) { _, isClosed in - if usesDesktopLayout && isClosed { - setDetailSideBarPresented?(false) - } - } .prominentAlert(store, state: \.alert, action: \.alert) // 좁은 창의 새로 만들기 .prominentSheet( diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index b2b13616..d7792197 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -51,23 +51,34 @@ public extension View { // 바꾸면 바로 저장하는 시트 // 좁은 창은 시트로 띄우고, 사이드바가 있는 창은 SplitShell 오른쪽 세부 정보 사이드바에 표시 + // reveal이 바뀌면 사이드바가 있는 창에서 닫힌 세부 정보 사이드바를 엶 func compositionSheet( item: Binding, + reveal: Int = 0, @ViewBuilder sheet: @escaping (Item) -> Sheet, @ViewBuilder right: @escaping (Item) -> Right ) -> some View { - modifier(CompositionSheetModifier(item: item, sheet: sheet, right: right)) + modifier(CompositionSheetModifier(item: item, reveal: reveal, sheet: sheet, right: right)) } // 좁은 창은 시트로 띄우거나 내비게이션에 쌓고, 사이드바가 있는 창은 이 화면 대신 내비게이션 루트에 그림 // isActive가 거짓이면 좁은 창에서 띄우지 않음 + // closesRight가 참이면 사이드바가 있는 창에서 닫거나 탭 화면을 벗어날 때 세부 정보 사이드바도 닫음 + // 창 폭이 바뀌어 시트와 루트를 오갈 때는 상태가 남아 닫지 않음 func compositionCenter( item: Binding, narrow: CompositionNarrow, isActive: Bool = true, + closesRight: Bool = false, @ViewBuilder content: @escaping (Item) -> Content ) -> some View { - modifier(CompositionCenterModifier(item: item, narrow: narrow, isActive: isActive, center: content)) + modifier(CompositionCenterModifier( + item: item, + narrow: narrow, + isActive: isActive, + closesRight: closesRight, + center: content + )) } } @@ -153,17 +164,21 @@ private struct CompositionEditorModifier: View } private struct CompositionCenterModifier: ViewModifier { + @Environment(\.isTabContentActive) private var isTabContentActive @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @State private var layout = LiveLayout() let item: Binding let narrow: CompositionNarrow let isActive: Bool + let closesRight: Bool let center: (Item) -> Center func body(content: Content) -> some View { // 창 폭이 바뀌어도 좁은 창의 표시를 같은 화면에 두어, 넓어진 뒤 늦게 닫히는 표시가 상태를 지우지 않음 let layout = layout.update(usesDesktopLayout: usesDesktopLayout) let narrowItem = item.activePresentation(when: isActive).hiddenInPane { layout.usesDesktopLayout } + let isClosed = item.wrappedValue == nil let shown = Group { if usesDesktopLayout, let value = item.wrappedValue { center(value) @@ -172,16 +187,32 @@ private struct CompositionCenterModifier: View } } + presentedContent(shown, item: narrowItem) + // 루트에 그린 화면을 닫거나 탭 화면을 벗어나면 그 화면이 보여 주던 세부 정보 사이드바도 닫음 + .onChange(of: isClosed) { _, isClosed in + if closesRight && usesDesktopLayout && isClosed { + setDetailSideBarPresented?(false) + } + } + .onChange(of: isTabContentActive) { _, isActive in + if closesRight && usesDesktopLayout && !isActive && !isClosed { + setDetailSideBarPresented?(false) + } + } + } + + @ViewBuilder + private func presentedContent(_ shown: some View, item: Binding) -> some View { switch narrow { case .sheet: shown - .prominentSheet(item: narrowItem, content: center) + .prominentSheet(item: item, content: center) case .cover: shown - .fullScreenCover(item: narrowItem, content: center) + .fullScreenCover(item: item, content: center) case .push: shown - .navigationDestination(item: narrowItem, interactivePop: true, destination: center) + .navigationDestination(item: item, interactivePop: true, destination: center) } } } @@ -189,8 +220,10 @@ private struct CompositionCenterModifier: View private struct CompositionSheetModifier: ViewModifier { @Environment(\.isTabContentActive) private var isTabContentActive @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @State private var layout = LiveLayout() let item: Binding + let reveal: Int let sheet: (Item) -> Sheet let right: (Item) -> Right @@ -212,5 +245,10 @@ private struct CompositionSheetModifier( isActive: Bool = true, + reveal: Int = 0, @ViewBuilder content: @escaping () -> Content ) -> some View { - modifier(CompositionRightModifier(isActive: isActive, sideBarContent: content)) + modifier(CompositionRightModifier(isActive: isActive, reveal: reveal, sideBarContent: content)) } } @@ -102,10 +104,13 @@ public struct DetailSideBarContentPreferenceKey: PreferenceKey { } private struct CompositionRightModifier: ViewModifier { + @Environment(\.usesDesktopLayout) private var usesDesktopLayout + @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @State private var id = UUID() // 화면을 벗어나 가려진 동안은 내용을 올리지 않음 @State private var isAppeared = false let isActive: Bool + let reveal: Int let sideBarContent: () -> SideBarContent func body(content: Content) -> some View { @@ -119,5 +124,10 @@ private struct CompositionRightModifier: ViewModifier { } .onAppear { isAppeared = true } .onDisappear { isAppeared = false } + .onChange(of: reveal) { + if usesDesktopLayout { + setDetailSideBarPresented?(true) + } + } } } diff --git a/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift b/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift index 62a058f3..9b97fe27 100644 --- a/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift +++ b/Application/Presentation/TodayTab/Sources/TodayFeature+State.swift @@ -44,6 +44,8 @@ extension TodayFeature { var isTodoInspectorPresented = false // 세부 정보 사이드바에 표시하는 Todo, 오른쪽 칸을 열면 칸의 Todo와 같음 var selectedTodoId: String? + // 세부 정보 사이드바에 Todo를 보여 달라고 한 횟수, 바뀌면 닫힌 세부 정보 사이드바를 엶 + var revealCount = 0 // Mac에서 마우스를 올린 행, 선택 행처럼 둥글게 표시하고 맞닿는 구분선을 숨김 var hoveredTodoId: String? // 사이드바가 있는 창에서 상세 판 대신 목록 오른쪽 칸에 표시, 세부 정보 사이드바만 쓰는 선택과 구분 diff --git a/Application/Presentation/TodayTab/Sources/TodayFeature.swift b/Application/Presentation/TodayTab/Sources/TodayFeature.swift index 3a4ee216..bcfe2537 100644 --- a/Application/Presentation/TodayTab/Sources/TodayFeature.swift +++ b/Application/Presentation/TodayTab/Sources/TodayFeature.swift @@ -111,6 +111,7 @@ struct TodayFeature { state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: true) } case .inspectTodo(let todoId): + state.revealCount += 1 state.selectedTodoId = todoId if state.showsDetailInPane && state.detail?.todoId != todoId { state.detail = TodoDetailFeature.State(todoId: todoId, showEditButton: true) @@ -157,6 +158,7 @@ struct TodayFeature { case .dismissTodoInspector: state.isTodoInspectorPresented = false case .moveTodoInspectorToSideBar: + state.revealCount += 1 guard state.isTodoInspectorPresented, let info = state.todoInfo else { break } // 고친 값은 이미 저장해 시트만 닫고 같은 Todo를 세부 정보 사이드바에 표시 state.isTodoInspectorPresented = false diff --git a/Application/Presentation/TodayTab/Sources/TodayView.swift b/Application/Presentation/TodayTab/Sources/TodayView.swift index 15f15f15..f33b04dc 100644 --- a/Application/Presentation/TodayTab/Sources/TodayView.swift +++ b/Application/Presentation/TodayTab/Sources/TodayView.swift @@ -18,7 +18,6 @@ public struct TodayView: View { @Environment(\.usesPaneLayout) private var usesPaneLayout @Environment(\.windowControlsInset) private var windowControlsInset @Environment(\.readableContentWidth) private var readableContentWidth - @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @State private var store: StoreOf private let isSelected: Bool private let windowEvent: TodoEditorWindowEvent @@ -74,7 +73,6 @@ public struct TodayView: View { // 사이드바가 있으면 고른 Todo를 창 오른쪽 세부 정보 사이드바에 표시 if usesDesktopLayout { store.send(.inspectTodo(item.id)) - setDetailSideBarPresented?(true) } else { store.send(.showTodoInspector(item)) } @@ -161,7 +159,10 @@ public struct TodayView: View { onMoveToPane: isListed ? { store.send(.moveDetailToPane) } : nil ) } - .compositionRight(isActive: sections.flatMap(\.items).contains { $0.id == store.selectedTodoId }) { + .compositionRight( + isActive: sections.flatMap(\.items).contains { $0.id == store.selectedTodoId }, + reveal: store.revealCount + ) { if let todoId = store.selectedTodoId { TodoDetailSideBarView(todoId: todoId, isEditable: true, windowEvent: windowEvent) .id(todoId) @@ -188,7 +189,6 @@ public struct TodayView: View { .onChange(of: usesDesktopLayout) { _, usesDesktopLayout in if usesDesktopLayout && store.isTodoInspectorPresented { store.send(.moveTodoInspectorToSideBar) - setDetailSideBarPresented?(true) } } // 상단 safe area 배경 From 1f9070c1258170adc64b43a411791375a9a2a5df Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 15/25] =?UTF-8?q?refactor:=20compositionPicker,=20composit?= =?UTF-8?q?ionPickerAnchor=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98=EA=B3=A0?= =?UTF-8?q?=20=ED=94=84=EB=A1=9C=ED=95=84=20=EB=B6=84=EA=B8=B0=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=EC=97=90=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Component/CompositionContainer.swift | 119 +++++++++++++++++- .../Sources/Profile/ActivityCard.swift | 15 +-- .../Sources/Profile/ProfileView.swift | 14 ++- 3 files changed, 128 insertions(+), 20 deletions(-) diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index d7792197..b2533584 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -80,16 +80,42 @@ public extension View { center: content )) } + + // 고르는 화면 + // 좁은 창은 시트로 띄우고, 칸으로 나눈 화면은 compositionPickerAnchor를 붙인 버튼 옆 팝오버로 띄움 + // maxHeight가 없으면 팝오버를 내용 높이에 맞춤 + func compositionPicker( + isPresented: Binding, + isActive: Bool = true, + arrowEdge: Edge? = nil, + maxHeight: CGFloat? = nil, + @ViewBuilder content: @escaping () -> Content + ) -> some View { + modifier(CompositionPickerModifier( + isPresented: isPresented, + isActive: isActive, + arrowEdge: arrowEdge, + maxHeight: maxHeight, + picker: content + )) + } + + // 바깥의 compositionPicker가 칸으로 나눈 화면에서 띄우는 팝오버를 붙일 버튼 + func compositionPickerAnchor() -> some View { + modifier(CompositionPickerAnchorModifier()) + } } // 창 폭이 바뀐 뒤 시스템이 표시할 때 받아 둔 바인딩으로 늦게 닫아도 지금 창 폭으로 거르도록 참조로 보관하는 값 private final class LiveLayout { private(set) var usesDesktopLayout = false + private(set) var usesPaneLayout = false private(set) var inPane = false // 그릴 때마다 지금 값으로 바꾸고 같은 참조를 돌려줌 - func update(usesDesktopLayout: Bool, inPane: Bool = false) -> LiveLayout { + func update(usesDesktopLayout: Bool = false, usesPaneLayout: Bool = false, inPane: Bool = false) -> LiveLayout { self.usesDesktopLayout = usesDesktopLayout + self.usesPaneLayout = usesPaneLayout self.inPane = inPane return self } @@ -252,3 +278,94 @@ private struct CompositionSheetModifier + let arrowEdge: Edge? + let maxHeight: CGFloat? + let content: () -> AnyView +} + +private extension EnvironmentValues { + var compositionPicker: CompositionPickerContent? { + get { self[CompositionPickerKey.self] } + set { self[CompositionPickerKey.self] = newValue } + } + + private struct CompositionPickerKey: EnvironmentKey { + static var defaultValue: CompositionPickerContent? { nil } + } +} + +private struct CompositionPickerModifier: ViewModifier { + @Environment(\.usesPaneLayout) private var usesPaneLayout + @State private var layout = LiveLayout() + let isPresented: Binding + let isActive: Bool + let arrowEdge: Edge? + let maxHeight: CGFloat? + let picker: () -> Picker + + func body(content: Content) -> some View { + // 창 폭이 바뀌어 팝오버와 시트를 오가면 같은 상태를 바뀐 쪽에 다시 그리고, 빠지는 쪽의 늦은 닫힘은 거름 + let layout = layout.update(usesPaneLayout: usesPaneLayout) + let sheetBinding = Binding( + get: { !layout.usesPaneLayout && isPresented.wrappedValue }, + set: { value in + if !layout.usesPaneLayout { + isPresented.wrappedValue = value + } + } + ) + let popoverBinding = Binding( + get: { layout.usesPaneLayout && isPresented.wrappedValue }, + set: { value in + if layout.usesPaneLayout { + isPresented.wrappedValue = value + } + } + ) + + content + .prominentSheet(isPresented: sheetBinding.activePresentation(when: isActive)) { + picker() + } + .environment( + \.compositionPicker, + CompositionPickerContent( + isPresented: popoverBinding.activePresentation(when: isActive), + arrowEdge: arrowEdge, + maxHeight: maxHeight + ) { + AnyView(picker()) + } + ) + } +} + +private struct CompositionPickerAnchorModifier: ViewModifier { + @Environment(\.compositionPicker) private var picker + + func body(content: Content) -> some View { + content + .popover(isPresented: picker?.isPresented ?? .constant(false), arrowEdge: picker?.arrowEdge) { + if let picker { + Group { + // 화면이 낮거나 Duo 접는 선에 걸리면 팝오버 높이를 줄이고 목록을 스크롤 + if let maxHeight = picker.maxHeight { + picker.content() + .frame(width: 320 * AdaptiveSize.boardScale) + .frame(minHeight: 0, idealHeight: maxHeight, maxHeight: maxHeight) + } else { + picker.content() + .frame(width: 320 * AdaptiveSize.boardScale) + .fixedSize(horizontal: false, vertical: true) + } + } + .presentationBackground(Color.secondaryBackground) + .presentationCompactAdaptation(.popover) + } + } + } +} diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift b/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift index 21d2c3a5..827b9221 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ActivityCard.swift @@ -11,7 +11,6 @@ import Domain import PresentationShared struct ActivityCard: View { - @Environment(\.isTabContentActive) private var isTabContentActive @Environment(\.usesPaneLayout) private var usesPaneLayout @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac @Bindable var store: StoreOf @@ -95,19 +94,7 @@ struct ActivityCard: View { } .buttonStyle(.plain) // 칸으로 나눈 화면은 분기 선택을 시트 대신 버튼 옆 팝오버로 표시 - .popover( - isPresented: $store.showQuarterPicker - .hiddenInPane(!usesPaneLayout) - .activePresentation(when: isTabContentActive), - // Mac은 분기 표시 아래로 표시 - arrowEdge: isiOSAppOnMac ? .top : nil - ) { - QuarterPickerSheet(store: store) - .frame(width: 320 * AdaptiveSize.boardScale) - .fixedSize(horizontal: false, vertical: true) - .presentationBackground(Color.secondaryBackground) - .presentationCompactAdaptation(.popover) - } + .compositionPickerAnchor() Spacer() Button { store.send(.moveQuarter(1)) diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index cfba632d..1753f1ad 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -17,6 +17,7 @@ public struct ProfileView: View { @Environment(\.usesPaneLayout) private var usesPaneLayout @Environment(\.deviceType) private var deviceType @Environment(\.sideBarRequest) private var sideBarRequest + @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac @State private var store: StoreOf @State private var router = NavigationRouter() @Bindable private var settingsStore: StoreOf @@ -146,11 +147,14 @@ public struct ProfileView: View { settingsStore.send(.startObserving) } .prominentAlert(store, state: \.alert, action: \.alert) - .prominentSheet( - isPresented: $store.showQuarterPicker - .hiddenInPane(usesPaneLayout) - .activePresentation(when: isSelected) - ) { QuarterPickerSheet(store: store) } + // 좁은 창은 분기 선택을 시트로, 칸으로 나눈 화면은 분기 표시 옆 팝오버로 표시하고 Mac은 분기 표시 아래로 표시 + .compositionPicker( + isPresented: $store.showQuarterPicker, + isActive: isSelected, + arrowEdge: isiOSAppOnMac ? .top : nil + ) { + QuarterPickerSheet(store: store) + } .overlay { if store.isLoading { LoadingView() From cf47cc79523a978f3d86dc8551eb15c892998cbe Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 16/25] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=ED=95=84?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=ED=99=94=EB=A9=B4=EC=9D=84=20SettingsF?= =?UTF-8?q?eature=EC=9D=98=20isListPushed,=20pushedRoute=EB=A1=9C=20?= =?UTF-8?q?=EC=8C=93=EA=B3=A0=20NavigationRouter=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Composition/CompositionFeature.swift | 2 +- .../Composition/CompositionFeatureTests.swift | 4 +- .../Sources/Profile/ProfileView.swift | 81 ++++--------------- .../Sources/Settings/SettingsFeature.swift | 20 +++++ 4 files changed, 40 insertions(+), 67 deletions(-) diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift b/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift index 01c87bb8..d3003f0d 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift @@ -117,7 +117,7 @@ struct CompositionFeature { state.isSettingsPresented = true case .settings(.close): state.isSettingsPresented = false - case .settings(.binding(\.screen)): + case .settings(.binding(\.isListPushed)): guard state.settings.screen == nil, state.isSettingsPresented else { break } // 좁아진 창에서 설정을 닫으면 설정 아래에 있던 프로필 화면 표시 state.isSettingsPresented = false diff --git a/Application/Presentation/Entry/Tests/Composition/CompositionFeatureTests.swift b/Application/Presentation/Entry/Tests/Composition/CompositionFeatureTests.swift index bbffb1db..b3714609 100644 --- a/Application/Presentation/Entry/Tests/Composition/CompositionFeatureTests.swift +++ b/Application/Presentation/Entry/Tests/Composition/CompositionFeatureTests.swift @@ -151,12 +151,12 @@ struct CompositionFeatureTests { await store.send(.view(.sideBarVisibilityChanged(true))) await store.send(.settings(.open)) await store.send(.view(.sideBarVisibilityChanged(false))) - await store.send(.settings(.binding(.set(\.screen, .list)))) + await store.send(.settings(.binding(.set(\.pushedRoute, nil)))) #expect(store.state.isSettingsPresented) #expect(store.state.selectedTab == .home) - await store.send(.settings(.binding(.set(\.screen, nil)))) + await store.send(.settings(.binding(.set(\.isListPushed, false)))) #expect(!store.state.isSettingsPresented) #expect(store.state.selectedTab == .profile) diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index 1753f1ad..736ef23b 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -16,10 +16,8 @@ public struct ProfileView: View { @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.usesPaneLayout) private var usesPaneLayout @Environment(\.deviceType) private var deviceType - @Environment(\.sideBarRequest) private var sideBarRequest @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac @State private var store: StoreOf - @State private var router = NavigationRouter() @Bindable private var settingsStore: StoreOf private let isSelected: Bool private let windowEvent: TodoEditorWindowEvent @@ -39,7 +37,7 @@ public struct ProfileView: View { } public var body: some View { - NavigationStack(path: path) { + NavigationStack { // 사이드바가 있는 창은 프로필을 창 전체 폭으로 두고 오른쪽 칸으로 옮긴 Todo가 있을 때만 두 칸으로 나눔 PaneSplitView(splitsOnDesktop: store.showsDetailInPane && store.detail != nil) { ScrollView { @@ -114,29 +112,27 @@ public struct ProfileView: View { } ) } + // 좁은 창은 설정 목록과 고른 항목 화면을 프로필 위에 쌓고, 사이드바가 있는 창은 창 전체 설정 화면에 그려 쌓지 않음 .navigationDestination( - for: ProfileRoute.self, - interactivePop: { - switch $0 { - case .settings, .theme: true - default: false - } - }, - destination: { destinationView($0).environment(\.showsPaneTitleBar, usesPaneLayout) } - ) + isPresented: $settingsStore.isListPushed.hiddenInPane(usesDesktopLayout), + interactivePop: true + ) { + SettingsView(store: settingsStore) { route in + settingsStore.send(.select(route)) + } + .environment(\.showsPaneTitleBar, usesPaneLayout) + .navigationDestination( + item: $settingsStore.pushedRoute.hiddenInPane(usesDesktopLayout), + interactivePop: settingsStore.pushedRoute == .theme + ) { route in + settingsPage(route) + .environment(\.showsPaneTitleBar, usesPaneLayout) + } + } } .desktopNavigationTransition() // 창 폭이 바뀌어 같은 설정을 다시 쌓거나 내릴 때 밀리는 효과 없이 바꿈 .transaction(value: usesDesktopLayout) { $0.disablesAnimations = true } - // 사이드바 요청으로 처음 여는 탭도 그 요청을 반영 - .onChange(of: sideBarRequest, initial: true) { _, request in - switch request?.action { - case .open(.profile): - router.path = [] - default: - break - } - } .onChange(of: isSelected, initial: true) { _, isSelected in if isSelected { store.send(.fetchData) @@ -213,49 +209,6 @@ public struct ProfileView: View { } } - // 사이드바가 있는 창의 설정은 창 전체 설정 화면에 그리므로 쌓지 않음 - private var path: Binding<[ProfileRoute]> { - Binding( - get: { - guard !usesDesktopLayout else { return router.path } - switch settingsStore.screen { - case .list: - return router.path + [.settings] - case .detail: - return router.path + [.settings, settingsStore.selectedRoute] - case nil: - return router.path - } - }, - set: { path in - let settingsIndex = path.firstIndex(of: .settings) ?? path.endIndex - router.path = Array(path[.. some View { - switch route { - case .settings: - SettingsView(store: settingsStore) { route in - settingsStore.send(.select(route)) - } - case .theme, .pushNotification, .account, .information: - settingsPage(route) - } - } - // 설정에서 고르는 아래 화면 @ViewBuilder private func settingsPage(_ route: ProfileRoute) -> some View { diff --git a/Application/Presentation/ProfileTab/Sources/Settings/SettingsFeature.swift b/Application/Presentation/ProfileTab/Sources/Settings/SettingsFeature.swift index 3e6f3d63..60fb4154 100644 --- a/Application/Presentation/ProfileTab/Sources/Settings/SettingsFeature.swift +++ b/Application/Presentation/ProfileTab/Sources/Settings/SettingsFeature.swift @@ -41,6 +41,26 @@ public struct SettingsFeature { // 열린 설정 화면, 좁은 창은 프로필 화면에 쌓고 사이드바가 있는 창은 창 전체 설정 화면에 표시 public var screen: Screen? + // 좁은 창에서 프로필 위에 쌓은 설정 목록, 뒤로 가면 설정을 닫음 + public var isListPushed: Bool { + get { screen != nil } + set { + if !newValue { + screen = nil + } + } + } + + // 좁은 창에서 설정 목록 위에 쌓은 고른 항목 화면, 뒤로 가면 설정 목록으로 돌아감 + public var pushedRoute: ProfileRoute? { + get { screen == .detail ? selectedRoute : nil } + set { + if newValue == nil && screen == .detail { + screen = .list + } + } + } + public init() { } static func betaTestURL(appEnvironment: String?, testFlightURL: String?) -> URL? { From 7e0664fa3b19847939ae05a4cfa6e49516926f07 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 17/25] =?UTF-8?q?refactor:=20=ED=99=88=20=EB=82=B4?= =?UTF-8?q?=EB=B9=84=EA=B2=8C=EC=9D=B4=EC=85=98=EC=9D=84=20HomeFeature?= =?UTF-8?q?=EC=9D=98=20StackState=EC=99=80=20=ED=99=94=EB=A9=B4=EB=B3=84?= =?UTF-8?q?=20@Presents=EB=A1=9C=20=EC=98=AE=EA=B8=B0=EA=B3=A0=20PaneSplit?= =?UTF-8?q?View=EA=B0=80=20=EC=88=98=EC=A0=95=EC=9E=90=EA=B0=80=20?= =?UTF-8?q?=EC=98=AC=EB=A6=B0=20=EC=83=81=EC=84=B8=20=EC=B9=B8=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=EC=9D=84=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Home/HomeFeature+Effects.swift | 5 +- .../HomeTab/Sources/Home/HomeFeature.swift | 292 +++++++++++------- .../HomeTab/Sources/Home/HomeView.swift | 278 ++++------------- .../Record/Detail/RecordDetailView.swift | 2 +- .../Record/GoalDetail/GoalDetailView.swift | 60 ++-- .../History/RecordVersionHistoryView.swift | 2 +- .../HomeTab/Sources/Search/SearchView.swift | 18 +- .../Sources/Todo/List/TodoListFeature.swift | 2 +- .../Sources/Todo/List/TodoListView.swift | 98 +++--- .../Tests/Home/HomeFeatureTestSupport.swift | 42 +-- .../HomeTab/Tests/Home/HomeFeatureTests.swift | 105 ++++--- .../Sources/PushNotificationListView.swift | 82 +++-- .../Component/CompositionContainer.swift | 107 +++++-- .../Common/Component/PaneSplitView.swift | 56 +++- .../Sources/Common/NavigationRouter.swift | 40 --- .../Sources/Common/SideBarNavigation.swift | 44 +++ .../View+NavigationDestination.swift | 15 +- .../Sources/Profile/ProfileView.swift | 46 ++- .../TodayTab/Sources/TodayView.swift | 49 ++- 19 files changed, 639 insertions(+), 704 deletions(-) delete mode 100644 Application/Presentation/PresentationShared/Sources/Common/NavigationRouter.swift diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeFeature+Effects.swift b/Application/Presentation/HomeTab/Sources/Home/HomeFeature+Effects.swift index 07e395b5..10747d32 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeFeature+Effects.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeFeature+Effects.swift @@ -132,7 +132,10 @@ extension HomeFeature { state.selectedTodoCategory = nil } case .contentPicker: - state.sheet = isPresented ? .contentPicker : state.showContentPicker ? nil : state.sheet + if isPresented { + state.closePresentations() + } + state.showContentPicker = isPresented } } diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift b/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift index cb591993..0127aa41 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift @@ -11,15 +11,27 @@ import PresentationShared @Reducer struct HomeFeature { + // 홈 내비게이션에 쌓는 카테고리 목록과 검색 + @Reducer + enum Path { + case category(TodoListFeature) + case search(SearchFeature) + } + @ObservableState struct State: Equatable { @Presents var alert: AlertState? - @Presents var sheet: SheetState? + @Presents var categoryManage: CategoryManageFeature.State? + @Presents var goalCreate: GoalCreateFeature.State? + // 넓은 창의 홈 자리와 좁은 창의 내비게이션이 같은 상태를 그려 창 폭이 바뀌어도 작성 중인 기록 유지 + @Presents var goalDetail: GoalDetailFeature.State? @Presents var fullScreenCover: FullScreenCoverState? + var path = StackState() // 작성 중인 새 개발 목표나 수정 중인 개발 목표를 버릴지 묻는 동안 미뤄 둔 동작 var actionAfterGoalDiscard: Action? - // 새 개발 목표나 개발 목표 칸을 닫은 뒤 다시 처리할 사이드바 요청 - var sideBarRequestAfterGoalDiscard: SideBarRequest? + var showContentPicker = false + // 사이드바가 있는 창, 사이드바 요청 처리와 사이드바 위치에 사용 + var usesDesktopLayout = false var developmentGoalItems = [DevelopmentGoalItem]() var hasDevelopmentGoalsLoaded = false var hasDevelopmentGoalsLoadFailure = false @@ -33,11 +45,6 @@ struct HomeFeature { var contentPickerHeight = CGFloat.zero var loading = LoadingFeature.State() - var showContentPicker: Bool { - if case .contentPicker? = sheet { return true } - return false - } - var showTodoEditor: Bool { fullScreenCover?.todoEditor != nil } var todoEditorCategory: TodoCategory? { @@ -52,12 +59,47 @@ struct HomeFeature { loading.visibleTargets.contains(LoadingTarget.developmentGoals.target) } + // 사이드바에서 고른 채로 표시할 위치 + var sideBarLocation: SideBarLocation { + if let goalDetail { + return .developmentGoal(goalDetail.goalId) + } + if usesDesktopLayout && categoryManage != nil { + return .todoCategoryManagement + } + if case .search? = path.last { + return .search + } + if case .category(let list)? = path.first { + return .todoCategory(list.category.storageValue) + } + return .home + } + + // 사이드바 Todo, 개발 목표 묶음의 하위 항목 + var sideBarContent: SideBarContent { + SideBarContent( + todoCategories: preferences.filter(\.isVisible), + developmentGoals: developmentGoalItems.map { SideBarGoal(id: $0.id, title: $0.goal.title) } + ) + } + + // 홈 루트에 띄운 화면은 한 번에 하나만 표시 + mutating func closePresentations() { + categoryManage = nil + goalCreate = nil + goalDetail = nil + showContentPicker = false + } } enum Action: BindableAction, Equatable { case alert(PresentationAction) - case sheet(PresentationAction) + case categoryManage(PresentationAction) + case goalCreate(PresentationAction) + case goalDetail(PresentationAction) case fullScreenCover(PresentationAction) + case path(StackActionOf) case binding(BindingAction) case view(ViewAction) case store(StoreAction) @@ -76,12 +118,12 @@ struct HomeFeature { case tapManageTodoCategory case tapTodoCategoryExpansionButton case tapTodoCategory(TodoCategory) - case closeGoalDraftForSideBarRequest(SideBarRequest) + case tapSearch + case sideBarRequested(SideBarRequest) } enum StoreAction: Equatable { case networkStatusChanged(Bool) - case setSheet(SheetState?) case setPresentation(Presentation, Bool) case setAlert(isPresented: Bool) case developmentGoalsLoaded([DevelopmentGoalItem]) @@ -90,66 +132,6 @@ struct HomeFeature { } } - @ObservableState - @CasePathable - enum SheetState: Equatable { - case reorderTodo(CategoryManageFeature.State) - case contentPicker - case goalCreate(GoalCreateFeature.State) - // 넓은 창의 칸과 시트가 같은 상태를 그려 창 폭이 바뀌어도 작성 중인 기록 유지 - case goalDetail(GoalDetailFeature.State) - - var categoryManageState: CategoryManageFeature.State? { - get { - guard case .reorderTodo(let state) = self else { return nil } - return state - } - set { - guard let newValue else { return } - self = .reorderTodo(newValue) - } - } - - var goalCreateState: GoalCreateFeature.State? { - get { - guard case .goalCreate(let state) = self else { return nil } - return state - } - set { - guard let newValue else { return } - self = .goalCreate(newValue) - } - } - - var goalDetailState: GoalDetailFeature.State? { - get { - guard case .goalDetail(let state) = self else { return nil } - return state - } - set { - guard let newValue else { return } - self = .goalDetail(newValue) - } - } - - var isDevelopmentGoalPresentation: Bool { - switch self { - case .goalCreate, .goalDetail: - true - case .reorderTodo, .contentPicker: - false - } - } - } - - @CasePathable - enum Sheet: Equatable { - case tapCloseButton - case categoryManage(CategoryManageFeature.Action) - case goalCreate(GoalCreateFeature.Action) - case goalDetail(GoalDetailFeature.Action) - } - @ObservableState struct FullScreenCoverState: Equatable { var destination: Destination @@ -196,6 +178,7 @@ struct HomeFeature { @Dependency(\.homeFetchRecentDevelopmentRecordUseCase) var recentRecordUseCase @Dependency(\.homeFetchTodosUseCase) var fetchTodosUseCase @Dependency(\.homeUpdateTodoCategoryPreferencesUseCase) var updatePreferencesUseCase + @Dependency(\.homeFetchRecentSearchQueriesUseCase) var fetchRecentSearchQueriesUseCase @Dependency(\.homeNetworkConnectivityUseCase) var networkConnectivityUseCase @Dependency(\.trackAnalyticsEventUseCase) var trackAnalyticsEventUseCase @Dependency(\.continuousClock) var clock @@ -206,17 +189,15 @@ struct HomeFeature { } BindingReducer() Reduce { state, action in - // 새 개발 목표나 개발 목표 수정 칸이 열린 동안 시트 자리를 바꾸는 동작 - if let goal = state.sheet?.goalCreateState ?? state.sheet?.goalDetailState?.goalEdit { + // 새 개발 목표나 개발 목표 수정 칸이 열린 동안 홈 루트에 띄운 화면을 바꾸는 동작 + if let goal = state.goalCreate ?? state.goalDetail?.goalEdit { switch action { case .view(.tapCreateDevelopmentGoal), .view(.tapDevelopmentGoal), .view(.tapManageTodoCategory), .view(.tapTodoCategory), - .view(.closeGoalDraftForSideBarRequest), - .store(.setSheet), .store(.setPresentation(.contentPicker, true)): - // 저장하는 동안 시트 자리를 바꾸면 저장이 취소되어 막음 + // 저장하는 동안 화면을 바꾸면 저장이 취소되어 막음 if goal.isSaving { return .none } @@ -236,8 +217,8 @@ struct HomeFeature { guard let action = state.actionAfterGoalDiscard else { break } state.actionAfterGoalDiscard = nil // 개발 목표 칸에서 바꾼 상태와 기록은 수정을 버리고 칸을 닫아도 홈과 사이드바 목록에 반영 - let refreshesDevelopmentGoals = state.sheet?.goalDetailState != nil - state.sheet = nil + let refreshesDevelopmentGoals = state.goalDetail != nil + state.closePresentations() return refreshesDevelopmentGoals ? .merge(.send(action), .send(.view(.fetchData))) : .send(action) case .alert(.dismiss): state.actionAfterGoalDiscard = nil @@ -248,27 +229,32 @@ struct HomeFeature { state.selectedTodoCategory = nil case .fullScreenCover: break - case .sheet(.dismiss): - let refreshesDevelopmentGoals = state.sheet?.isDevelopmentGoalPresentation == true - state.sheet = nil - if refreshesDevelopmentGoals { - return .send(.view(.fetchData)) - } - case .sheet(.presented(.tapCloseButton)): - state.sheet = nil - case .sheet(.presented(.categoryManage(.delegate(.changed(let preferences))))): + case .categoryManage(.presented(.delegate(.changed(let preferences)))): // 카테고리 관리는 시트와 칸 모두 고친 값을 바로 저장 state.preferences = preferences return delayedTodoCategoryPreferencesUpdateEffect(preferences) - case .sheet(.presented(.goalCreate(.delegate(.saved)))): - state.sheet = nil + case .categoryManage: + break + case .goalCreate(.presented(.delegate(.saved))): + state.goalCreate = nil + return .send(.view(.fetchData)) + case .goalCreate(.presented(.delegate(.close))): + return .send(.goalCreate(.dismiss)) + // 개발 목표 화면을 닫으면 바꾼 목표와 기록을 홈과 사이드바 목록에 반영하고, 이미 닫힌 뒤 늦게 온 닫힘은 다시 불러오지 않음 + case .goalCreate(.dismiss): + guard state.goalCreate != nil else { break } return .send(.view(.fetchData)) - case .sheet(.presented(.goalCreate(.delegate(.close)))): - return .send(.sheet(.dismiss)) + case .goalCreate: + break // 개발 목표 칸에서 고친 제목을 사이드바와 홈 목록에 반영 - case .sheet(.presented(.goalDetail(.delegate(.goalUpdated)))): + case .goalDetail(.presented(.delegate(.goalUpdated))): + return .send(.view(.fetchData)) + case .goalDetail(.dismiss): + guard state.goalDetail != nil else { break } return .send(.view(.fetchData)) - case .sheet: + case .goalDetail: + break + case .path: break case .binding: break @@ -283,12 +269,19 @@ struct HomeFeature { return .none } .ifLet(\.$alert, action: \.alert) - .ifLet(\.$sheet, action: \.sheet) { - SheetFeature() + .ifLet(\.$categoryManage, action: \.categoryManage) { + CategoryManageFeature() + } + .ifLet(\.$goalCreate, action: \.goalCreate) { + GoalCreateFeature() + } + .ifLet(\.$goalDetail, action: \.goalDetail) { + GoalDetailFeature() } .ifLet(\.$fullScreenCover, action: \.fullScreenCover) { FullScreenCoverFeature() } + .forEach(\.path, action: \.path) } } @@ -326,25 +319,30 @@ private extension HomeFeature { ) case .tapCreateDevelopmentGoal: if state.showContentPicker { - state.sheet = nil + state.showContentPicker = false return delayedDevelopmentGoalCreateEffect() } - state.sheet = .goalCreate(GoalCreateFeature.State()) + state.closePresentations() + state.goalCreate = GoalCreateFeature.State() case .tapDevelopmentGoal(let goalID): - state.sheet = .goalDetail(GoalDetailFeature.State(goalId: goalID)) + state.closePresentations() + state.goalDetail = GoalDetailFeature.State(goalId: goalID) case .tapManageTodoCategory: // 이미 연 카테고리 관리는 고르던 카테고리를 그대로 유지 - guard state.sheet?.categoryManageState == nil else { break } - state.sheet = .reorderTodo(CategoryManageFeature.State(preferences: state.preferences)) + guard state.categoryManage == nil else { break } + state.closePresentations() + state.categoryManage = CategoryManageFeature.State(preferences: state.preferences) case .tapTodoCategoryExpansionButton: state.isTodoCategoryExpanded.toggle() case .tapTodoCategory(let category): state.selectedTodoCategory = category - state.sheet = nil + state.closePresentations() return delayedTodoEditorEffect() - case .closeGoalDraftForSideBarRequest(let request): - state.sheet = nil - state.sideBarRequestAfterGoalDiscard = request + case .tapSearch: + // 열 때마다 빈 입력칸으로 시작하고 최근 검색은 열 때 읽음 + state.path.append(.search(SearchFeature.State(recentQueries: fetchRecentSearchQueriesUseCase.execute()))) + case .sideBarRequested(let request): + return sideBarRequested(request, state: &state) } return .none @@ -357,8 +355,6 @@ private extension HomeFeature { switch action { case .networkStatusChanged(let isConnected): state.isNetworkConnected = isConnected - case .setSheet(let sheet): - state.sheet = sheet case .setPresentation(let presentation, let isPresented): Self.setPresentation(&state, presentation: presentation, isPresented: isPresented) case .setAlert(let isPresented): @@ -375,22 +371,80 @@ private extension HomeFeature { return .none } -} - -private struct SheetFeature: Reducer { - typealias State = HomeFeature.SheetState - typealias Action = HomeFeature.Sheet - var body: some ReducerOf { - EmptyReducer() - .ifCaseLet(\.reorderTodo, action: \.categoryManage) { - CategoryManageFeature() + // 사이드바에서 보낸 이동과 작성 요청 + func sideBarRequested(_ request: SideBarRequest, state: inout State) -> Effect { + // 이미 표시 중인 개발 목표를 다시 누르면 다시 열지 않고 쌓아 연 화면만 닫아 개발 목표 첫 화면 표시 + if case .open(.developmentGoal(let goalID)) = request.action, state.goalDetail?.goalId == goalID { + return .send(.goalDetail(.presented(.view(.returnToGoal)))) } - .ifCaseLet(\.goalCreate, action: \.goalCreate) { - GoalCreateFeature() + let goal = state.goalCreate ?? state.goalDetail?.goalEdit + // 작성 중인 새 개발 목표나 수정 중인 개발 목표가 있으면 칸을 닫기 전에 버릴지 물음 + // 버리면 칸을 닫은 뒤 같은 요청을 다시 처리 + if request.action != .createTodo, let goal, goal.hasDraft { + // 저장하는 동안 칸을 바꾸면 저장이 취소되어 막음 + guard !goal.isSaving else { return .none } + state.actionAfterGoalDiscard = .view(.sideBarRequested(request)) + state.alert = Self.discardGoalDraftAlertState(isEditing: goal.goal != nil) + return .none } - .ifCaseLet(\.goalDetail, action: \.goalDetail) { - GoalDetailFeature() + // 사이드바가 있으면 카테고리 관리, 새 개발 목표, 개발 목표를 시트 대신 칸으로 표시 + let showsPane = state.usesDesktopLayout + && (state.categoryManage != nil || state.goalCreate != nil || state.goalDetail != nil) + // 개발 목표 칸을 다른 화면으로 바꾸면 칸에서 바꾼 목표와 기록을 시트를 닫을 때처럼 홈과 사이드바 목록에 반영 + let refreshesDevelopmentGoals = showsPane && (state.goalCreate != nil || state.goalDetail != nil) + // 새 Todo 작성으로 작성 중인 개발 목표를 버릴지 묻는 경우 + var asksGoalDiscard = false + var effects = [Effect]() + // 사이드바로 다른 곳을 열면 칸으로 표시하던 화면은 닫고, 저장하는 동안은 닫지 않음 + if showsPane, case .open = request.action, goal?.isSaving != true { + state.closePresentations() } + switch request.action { + case .open(.home): + state.path.removeAll() + case .open(.todoCategory(let id)): + guard let item = state.preferences.first(where: { $0.id == id }) else { break } + // 같은 카테고리 목록만 쌓여 있으면 보던 목록을 그대로 둠 + if state.path.count == 1, case .category(let list)? = state.path.first, list.category == item.todoCategory { + break + } + state.path = StackState([.category(TodoListFeature.State(category: item.todoCategory))]) + case .open(.developmentGoal(let goalID)): + // 사이드바가 있으면 개발 목표를 홈 루트에 그려 위에 쌓인 목록을 비움 + if state.usesDesktopLayout { + state.path.removeAll() + } + effects.append(.send(.view(.tapDevelopmentGoal(goalID)))) + case .createTodo: + if case .category? = state.path.first, let id = state.path.ids.first { + // 카테고리 목록이 보이면 그 목록이 자기 작성 버튼과 같은 방식으로 작성 + effects.append(.send(.path(.element(id: id, action: .category(.store(.setFullScreenCover(.editor))))))) + } else if state.isNetworkConnected { + // 홈 작성 버튼처럼 연결이 끊기면 열지 않고 쌓아 연 검색도 그대로 둠 + // 쌓아 연 검색은 내리고 홈 작성 버튼과 같은 방식으로 작성 + state.path.removeAll() + asksGoalDiscard = goal.map { !$0.isSaving && $0.hasDraft } ?? false + effects.append(.send(.store(.setPresentation(.contentPicker, true)))) + } + case .manageTodoCategory: + // 카테고리를 불러오기 전 빈 목록으로 저장하지 않도록 무시 + guard !state.preferences.isEmpty else { break } + // 사이드바가 있으면 카테고리 관리 칸을 홈 루트에 그려 위에 쌓인 목록을 비움 + if state.usesDesktopLayout { + state.path.removeAll() + } + effects.append(.send(.view(.tapManageTodoCategory))) + case .open: + break + } + // 버릴지 묻는 중이면 칸이 그대로라 다시 불러오지 않음 + if refreshesDevelopmentGoals && state.actionAfterGoalDiscard == nil && !asksGoalDiscard { + effects.append(.send(.view(.fetchData))) + } + return .concatenate(effects) } } + +extension HomeFeature.Path.State: Equatable {} +extension HomeFeature.Path.Action: Equatable {} diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index d7797b72..4f3d37fd 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -15,8 +15,6 @@ public struct HomeView: View { @Environment(\.windowControlsInset) private var windowControlsInset @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.deviceType) private var deviceType - @Environment(\.sideBarRequest) private var sideBarRequest - @State private var router = NavigationRouter() @State private var store: StoreOf private let isSelected: Bool private let windowEvent: TodoEditorWindowEvent @@ -33,207 +31,67 @@ public struct HomeView: View { } public var body: some View { - let goalDetailID = store.sheet?.goalDetailState?.goalId - let sideBarLocation: SideBarLocation = if let goalDetailID { - .developmentGoal(goalDetailID) - } else if usesDesktopLayout && store.sheet?.categoryManageState != nil { - .todoCategoryManagement - } else if router.path.last == .search { - .search - } else if case .category(let item)? = router.root { - .todoCategory(item.id) - } else { - .home - } - // 사이드바가 있으면 카테고리 관리, 새 개발 목표, 개발 목표를 시트 대신 칸으로 표시 - let showsSheetAsPane = usesDesktopLayout - && (store.sheet?.categoryManageState != nil || store.sheet?.goalCreateState != nil || goalDetailID != nil) - // 칸으로 나눈 화면은 새로 만들기를 시트 대신 만들기 버튼 옆 팝오버로 표시 - let showsPickerAsPopover = usesPaneLayout && store.showContentPicker - let sheetBinding = $store.scope(state: \.sheet, action: \.sheet) - .activePresentation(when: isSelected) - - NavigationStack(path: $router.path) { - // 사이드바가 있으면 새 개발 목표와 새 Todo를 홈 오른쪽 칸에서 작성 - PaneSplitView(splitsOnDesktop: store.sheet?.goalCreateState != nil || store.showTodoEditor) { + NavigationStack(path: $store.scope(state: \.path, action: \.path)) { + PaneSplitView { homeContent - } detail: { - if let goalStore = store.scope(state: \.sheet?.goalCreateState, action: \.sheet.presented.goalCreate) { - GoalCreateView(store: goalStore) - } else if let editorStore = store.scope( - state: \.fullScreenCover?.todoEditor, - action: \.fullScreenCover.presented.todoEditor - ) { - TodoEditorView(store: editorStore, onClose: { store.send(.fullScreenCover(.dismiss)) }) - } } // 새 개발 목표에 연결한 Todo는 세부 정보 사이드바에 표시 - .compositionRight(isActive: store.sheet?.goalCreateState != nil) { - if let goalStore = store.scope(state: \.sheet?.goalCreateState, action: \.sheet.presented.goalCreate) { + .compositionRight(isActive: store.goalCreate != nil) { + if let goalStore = store.scope(state: \.goalCreate, action: \.goalCreate.presented) { GoalCreateSideBarContent(store: goalStore) } } // 사이드바가 있으면 카테고리 관리를 시트 대신 홈 자리에 표시 .compositionCenter( - item: $store.scope(state: \.sheet?.categoryManageState, action: \.sheet.categoryManage), + item: $store.scope(state: \.categoryManage, action: \.categoryManage), narrow: .sheet, isActive: isSelected, closesRight: true ) { manageStore in CategoryManageView(store: manageStore) { - store.send(.sheet(.dismiss)) + store.send(.categoryManage(.dismiss)) } } // 좁은 창은 개발 목표를 홈 내비게이션에 쌓고, 넓어지면 같은 상태를 홈 자리에 표시하고 기록 작성은 오른쪽 칸에 표시 .compositionCenter( - item: $store.scope(state: \.sheet?.goalDetailState, action: \.sheet.goalDetail), + item: $store.scope(state: \.goalDetail, action: \.goalDetail), narrow: .push ) { goalStore in GoalDetailView(store: goalStore, windowEvent: windowEvent) - .id(goalDetailID) + .id(goalStore.goalId) } - .navigationDestination( - for: HomeRoute.self, - interactivePop: { - switch $0 { - case .category: true - case .search: true - } - }, - destination: { - destinationView($0) - .environment(\.showsPaneTitleBar, usesPaneLayout) - // 위에 쌓은 화면에 가려진 동안에도 창 폭이 바뀐 것을 받아 쌓아 연 상세를 옮김 - .environment(\.usesDesktopLayout, usesDesktopLayout) + } destination: { pathStore in + Group { + switch pathStore.case { + case .category(let listStore): + TodoListView(store: listStore, windowEvent: windowEvent) + case .search(let searchStore): + SearchView(store: searchStore, windowEvent: windowEvent) } - ) + } + .stackDestination(usesDesktopLayout: usesDesktopLayout, usesPaneLayout: usesPaneLayout) } .desktopNavigationTransition() - .preference(key: SideBarLocationPreferenceKey.self, value: sideBarLocation) - .preference( - key: SideBarContentPreferenceKey.self, - value: SideBarContent( - todoCategories: store.preferences.filter(\.isVisible), - developmentGoals: store.developmentGoalItems.map { SideBarGoal(id: $0.id, title: $0.goal.title) } - ) - ) - // 사이드바 요청으로 처음 여는 탭도 그 요청을 반영 - .onChange(of: sideBarRequest, initial: true) { _, request in - handleSideBarRequest(request, showsSheetAsPane: showsSheetAsPane) + .onChange(of: usesDesktopLayout, initial: true) { _, usesDesktopLayout in + store.send(.binding(.set(\.usesDesktopLayout, usesDesktopLayout))) } - // 작성 중인 새 개발 목표나 수정 중인 개발 목표를 버린 뒤 미뤄 둔 사이드바 요청 처리 - .onChange(of: store.sideBarRequestAfterGoalDiscard) { _, request in - handleSideBarRequest(request, showsSheetAsPane: showsSheetAsPane) + .compositionLeft(location: store.sideBarLocation, content: store.sideBarContent) { + // 홈이 아닌 탭으로 켜져도 사이드바 하위 항목을 채움 + if !isSelected { + store.send(.view(.fetchData)) + } + } onRequest: { request in + store.send(.view(.sideBarRequested(request))) } .onAppear { store.send(.view(.startObserving)) } - // 사이드바가 있으면 홈이 아닌 탭으로 켜지거나 좁은 창에서 넓어져도 사이드바 하위 항목을 채우도록 불러옴 - .onChange(of: usesDesktopLayout, initial: true) { _, usesDesktopLayout in - if usesDesktopLayout && !isSelected { - store.send(.view(.fetchData)) - } - } .onChange(of: isSelected, initial: true) { _, isSelected in if isSelected { store.send(.view(.fetchData)) } } .prominentAlert(store, state: \.alert, action: \.alert) - // 좁은 창의 새로 만들기 - .prominentSheet( - item: Binding( - get: { store.showContentPicker && !showsPickerAsPopover ? sheetBinding.wrappedValue : nil }, - // 앞 시트가 늦게 닫히며 보내는 닫힘이 칸이나 팝오버로 연 화면을 지우지 않도록 지금 상태로 판단 - set: { sheet in - // 내비게이션에 쌓은 개발 목표는 시트 닫힘으로 지우지 않음 - guard store.sheet?.goalDetailState == nil else { return } - guard !usesDesktopLayout - || store.sheet?.categoryManageState == nil - && store.sheet?.goalCreateState == nil - && store.sheet?.goalDetailState == nil - else { return } - guard !(usesPaneLayout && store.showContentPicker) else { return } - sheetBinding.wrappedValue = sheet - } - ) - ) { _ in - HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) } - } - // 좁은 창은 새 개발 목표를 닫기, 저장 버튼으로만 닫는 시트로 작성 - .compositionEditor( - item: $store.scope(state: \.sheet?.goalCreateState, action: \.sheet.goalCreate) - .activePresentation(when: isSelected), - narrow: .sheet - ) { goalStore in - GoalCreateView(store: goalStore) - } - .compositionEditor( - item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover) - .activePresentation(when: isSelected), - content: coverContent - ) - } - - private func handleSideBarRequest(_ request: SideBarRequest?, showsSheetAsPane: Bool) { - // 이미 표시 중인 개발 목표를 다시 누르면 다시 열지 않고 쌓아 연 화면만 닫아 개발 목표 첫 화면 표시 - if case .open(.developmentGoal(let goalID))? = request?.action, - store.sheet?.goalDetailState?.goalId == goalID { - store.send(.sheet(.presented(.goalDetail(.view(.returnToGoal))))) - return - } - // 작성 중인 새 개발 목표나 수정 중인 개발 목표가 있으면 칸을 닫기 전에 버릴지 물음 - if let request, - request.action != .createTodo, - store.sheet?.goalCreateState?.hasDraft == true || store.sheet?.goalDetailState?.goalEdit?.hasDraft == true { - store.send(.view(.closeGoalDraftForSideBarRequest(request))) - return - } - // 개발 목표 칸을 다른 화면으로 바꾸면 칸에서 바꾼 목표와 기록을 시트를 닫을 때처럼 홈과 사이드바 목록에 반영 - let refreshesDevelopmentGoals = request != nil - && showsSheetAsPane - && store.sheet?.isDevelopmentGoalPresentation == true - // 사이드바로 다른 곳을 열면 칸으로 표시하던 화면은 닫음 - if showsSheetAsPane, case .open = request?.action { - store.send(.store(.setSheet(nil))) - } - switch request?.action { - case .open(.home): - router.path = [] - case .open(.todoCategory(let id)): - guard let item = store.preferences.first(where: { $0.id == id }) else { break } - router.replace(with: .category(item)) - case .open(.developmentGoal(let goalID)): - // 사이드바가 있으면 개발 목표를 홈 루트에 그려 위에 쌓인 목록을 비움 - if usesDesktopLayout { - router.path = [] - } - store.send(.view(.tapDevelopmentGoal(goalID))) - case .createTodo: - // 홈 작성 버튼처럼 연결이 끊기면 열지 않고 쌓아 연 검색도 그대로 둠 - guard store.isNetworkConnected else { break } - // 쌓아 연 검색은 내리고 홈 작성 버튼과 같은 방식으로 작성 - if router.root == .search { - router.path = [] - } - // 카테고리 목록이 보이면 그 목록이 자기 작성 버튼과 같은 방식으로 작성 - guard router.root == nil else { break } - store.send(.store(.setPresentation(.contentPicker, true))) - case .manageTodoCategory: - // 카테고리를 불러오기 전 빈 목록으로 저장하지 않도록 무시 - guard !store.preferences.isEmpty else { break } - // 사이드바가 있으면 카테고리 관리 칸을 홈 루트에 그려 위에 쌓인 목록을 비움 - if usesDesktopLayout { - router.path = [] - } - store.send(.view(.tapManageTodoCategory)) - case .open, nil: - break - } - // 버릴지 묻는 중이면 칸이 그대로라 다시 불러오지 않음 - if refreshesDevelopmentGoals && store.actionAfterGoalDiscard == nil { - store.send(.view(.fetchData)) - } } private var homeContent: some View { @@ -253,6 +111,31 @@ public struct HomeView: View { .sharedBackgroundHidden() } } + // 좁은 창은 새로 만들기를 시트로, 칸으로 나눈 화면은 만들기 버튼 옆 팝오버로 표시 + // 버튼 옆으로 붙으면 위쪽이 상태 표시 영역에 가려지므로 버튼 아래로 표시 + .compositionPicker( + isPresented: $store.showContentPicker, + isActive: isSelected, + arrowEdge: .top, + maxHeight: min(640, store.visibleHeight) + ) { + HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) } + } + // 사이드바가 있으면 새 Todo를 홈 오른쪽 칸에서 작성 + .compositionEditor( + item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover), + isActive: isSelected + ) { coverStore, onClose in + coverContent(coverStore, onClose: onClose) + } + // 좁은 창은 새 개발 목표를 닫기, 저장 버튼으로만 닫는 시트로 작성하고 사이드바가 있으면 홈 오른쪽 칸에서 작성 + .compositionEditor( + item: $store.scope(state: \.goalCreate, action: \.goalCreate), + narrow: .sheet, + isActive: isSelected + ) { goalStore, _ in + GoalCreateView(store: goalStore) + } } private var duoToolbarItems: some ToolbarContent { @@ -260,7 +143,7 @@ public struct HomeView: View { // 접힌 뒤 펼칠 때 레일 아이콘이 사라지는 현상 방지 Group { Button { - router.push(.search) + store.send(.view(.tapSearch)) } label: { Image(systemName: "magnifyingglass") } @@ -281,26 +164,7 @@ public struct HomeView: View { PaneTitleBar(Text("nav_home", bundle: PresentationResources.bundle)) { searchButton HomeCreateButton(store: store) - .popover( - isPresented: Binding( - get: { isSelected && store.showContentPicker }, - // 좁은 창으로 바뀌며 팝오버가 닫혀도 같은 상태를 시트로 다시 그림 - set: { isPresented in - if usesPaneLayout { - store.send(.store(.setPresentation(.contentPicker, isPresented))) - } - } - ), - // 버튼 옆으로 붙으면 위쪽이 상태 표시 영역에 가려지므로 버튼 아래로 표시 - arrowEdge: .top - ) { - HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) } - // 화면이 낮거나 Duo 접는 선에 걸리면 팝오버 높이를 줄이고 목록을 스크롤 - .frame(width: 320 * AdaptiveSize.boardScale) - .frame(minHeight: 0, idealHeight: min(640, store.visibleHeight), maxHeight: min(640, store.visibleHeight)) - .presentationBackground(Color.secondaryBackground) - .presentationCompactAdaptation(.popover) - } + .compositionPickerAnchor() } } else { HStack(spacing: 0) { @@ -325,7 +189,7 @@ public struct HomeView: View { @ViewBuilder private var searchButton: some View { // 모든 기기에서 덮는 화면 대신 홈 내비게이션에 쌓아 열고, 사이드바가 있는 창은 사이드바 옆에 표시 - let openSearch = { router.push(.search) } + let openSearch = { _ = store.send(.view(.tapSearch)) } if !usesPaneLayout { Button(action: openSearch) { @@ -342,36 +206,16 @@ public struct HomeView: View { @ViewBuilder private func coverContent( - _ coverStore: Store + _ coverStore: Store, + onClose: (() -> Void)? ) -> some View { switch coverStore.destination { case .todoEditor: if let todoEditorStore = coverStore.scope(state: \.todoEditor, action: \.todoEditor) { - TodoEditorView(store: todoEditorStore) + TodoEditorView(store: todoEditorStore, onClose: onClose) } } } - - @ViewBuilder - private func destinationView(_ route: HomeRoute) -> some View { - switch route { - case .category(let item): - TodoListView( - store: Store(initialState: TodoListFeature.State(category: item.todoCategory)) { - TodoListFeature() - }, - windowEvent: windowEvent - ) - .id(item.id) - case .search: - SearchView(windowEvent: windowEvent) - } - } -} - -public enum HomeRoute: Hashable { - case category(TodoCategoryItem) - case search } private struct HomeCreateButton: View { @@ -559,7 +403,7 @@ private struct HomeTodoCategoryLink: View { var body: some View { let tileSize = isiOSAppOnMac ? 37 * AdaptiveSize.boardScale : 40 - NavigationLink(value: HomeRoute.category(item)) { + NavigationLink(state: HomeFeature.Path.State.category(TodoListFeature.State(category: item.todoCategory))) { VStack(spacing: 6) { Image(systemName: item.symbolName) .font(.adaptive(.body).weight(.medium)) @@ -609,7 +453,7 @@ private struct HomeContentPicker: View { HStack { if isiOSAppOnMac { Button { - store.send(.sheet(.presented(.tapCloseButton))) + store.send(.store(.setPresentation(.contentPicker, false))) } label: { Image(systemName: "xmark") .font(.adaptive(.body)) @@ -620,7 +464,7 @@ private struct HomeContentPicker: View { .buttonStyle(.plain) } else { Button { - store.send(.sheet(.presented(.tapCloseButton))) + store.send(.store(.setPresentation(.contentPicker, false))) } label: { Image(systemName: "xmark") } @@ -643,7 +487,7 @@ private struct HomeContentPicker: View { background: .secondaryBackground ) { RecordTopBarTextButton(RecordPresentation.text("common_close")) { - store.send(.sheet(.presented(.tapCloseButton))) + store.send(.store(.setPresentation(.contentPicker, false))) } } trailing: { EmptyView() diff --git a/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift index 345ae29c..0d2a3e14 100644 --- a/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift @@ -64,7 +64,7 @@ public struct RecordDetailView: View { .onAppear { store.send(.view(.appear(onDesktop: usesDesktopLayout))) } .prominentAlert(store, state: \.alert, action: \.alert) // 기록 정정은 좁은 창에서 닫기, 저장, 확정 버튼으로만 닫는 전체 화면이고 넓은 창에서 시트 - .compositionEditor(item: editor.hiddenInPane(isHidden), inPane: false) { _ in + .compositionEditor(item: editor.hiddenInPane(isHidden), inPane: false) { _, _ in correctionEditor } .navigationDestination( diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index 28dbc6ab..2e832efb 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -58,50 +58,40 @@ public struct GoalDetailView: View { let isHidden = { !isShown || store.shownOnDesktop != usesDesktopLayout } // 사이드바가 있으면 개발 목표 수정과 기록 작성을 개발 목표 오른쪽 칸에 표시 - return PaneSplitView(splitsOnDesktop: store.goalEdit != nil || store.recordEditor != nil) { + // 좁은 창 표시는 빠지는 자리에서 넓은 창의 개발 목표가 이미 나타났으면 띄우지 않음 + let isNarrowHidden = { store.shownOnDesktop == true && !usesDesktopLayout } + + return PaneSplitView { mainContent - } detail: { - if let editStore = store.scope(state: \.goalEdit, action: \.goalEdit.presented) { - GoalCreateView(store: editStore) - } else if let editorStore = store.scope(state: \.recordEditor, action: \.recordEditor.presented) { - RecordEditorView( - store: editorStore, - onCompletion: { - store.send(.view(.refresh)) - }, - onClose: { - store.send(.recordEditor(.dismiss)) - } - ) - } - } - // 좁은 창은 닫기, 저장, 확정 버튼으로만 닫는 전체 화면 - .compositionEditor( - item: $store.scope(state: \.recordEditor, action: \.recordEditor) - .hiddenInPane { store.shownOnDesktop == true } - ) { editorStore in - RecordEditorView( - store: editorStore, - onCompletion: { - store.send(.view(.refresh)) + // 좁은 창은 닫기, 저장, 확정 버튼으로만 닫는 전체 화면 + .compositionEditor( + item: $store.scope(state: \.recordEditor, action: \.recordEditor) + .hiddenInPane(isNarrowHidden) + ) { editorStore, onClose in + RecordEditorView( + store: editorStore, + onCompletion: { + store.send(.view(.refresh)) + }, + onClose: onClose + ) + } + // 좁은 창은 새 개발 목표와 같은 시트로 수정하고 닫기, 저장 버튼으로만 닫음 + .compositionEditor( + item: $store.scope(state: \.goalEdit, action: \.goalEdit) + .hiddenInPane(isNarrowHidden), + narrow: .sheet + ) { editStore, _ in + GoalCreateView(store: editStore) } - ) } .prominentSheet(item: $store.scope(state: \.todoLinkSheet, action: \.todoLinkSheet)) { GoalTodoLinkSheet(store: $0) } - // 좁은 창은 새 개발 목표와 같은 시트로 수정하고 닫기, 저장 버튼으로만 닫음 - .compositionEditor( - item: $store.scope(state: \.goalEdit, action: \.goalEdit) - .hiddenInPane { store.shownOnDesktop == true }, - narrow: .sheet - ) { - GoalCreateView(store: $0) - } // 사이드바가 있는 창은 기록을 사이드바까지 덮는 상세 판으로 열고 버전 이력은 판 안에서 이동 .compositionDetail( item: $store.scope(state: \.recordDetail, action: \.recordDetail).hiddenInPane(isHidden) - ) { _ in + ) { _, _ in if let detailStore = store.scope(state: \.recordDetailContent, action: \.recordDetailContent) { RecordDetailView(store: detailStore, onUpdate: { store.send(.view(.refresh)) }) } diff --git a/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift b/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift index 7bc2f227..142990ab 100644 --- a/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/History/RecordVersionHistoryView.swift @@ -65,7 +65,7 @@ struct RecordVersionHistoryView: View { .background(Color.background.ignoresSafeArea()) .duoToolbarVisibility(showsBackButton: true) // 사이드바가 있는 창은 이전 버전을 사이드바까지 덮는 상세 판으로 열기 - .compositionDetail(item: versionDetail.hiddenInPane(isHidden)) { destination in + .compositionDetail(item: versionDetail.hiddenInPane(isHidden)) { destination, _ in RecordVersionDetailView( store: store, version: destination.version diff --git a/Application/Presentation/HomeTab/Sources/Search/SearchView.swift b/Application/Presentation/HomeTab/Sources/Search/SearchView.swift index 8492fa50..bde13f8d 100644 --- a/Application/Presentation/HomeTab/Sources/Search/SearchView.swift +++ b/Application/Presentation/HomeTab/Sources/Search/SearchView.swift @@ -16,21 +16,13 @@ struct SearchView: View { @Environment(\.windowControlsInset) private var windowControlsInset @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.deviceType) private var deviceType - @State private var store: StoreOf + @Bindable private var store: StoreOf // 좁은 창에서 쌓아 연 결과 상세의 편집을 Mac 편집 창과 같은 경로로 전달 private let windowEvent: TodoEditorWindowEvent? - // 열 때마다 빈 입력칸으로 시작하고 최근 검색은 열 때 읽음 - // 닫으면 Store와 함께 진행 중인 검색 요청과 상세도 사라짐 - init(windowEvent: TodoEditorWindowEvent?) { - @Dependency(\.homeFetchRecentSearchQueriesUseCase) var fetchRecentSearchQueriesUseCase - self._store = State(initialValue: Store( - initialState: SearchFeature.State( - recentQueries: fetchRecentSearchQueriesUseCase.execute() - ) - ) { - SearchFeature() - }) + // 닫으면 쌓은 상태와 함께 진행 중인 검색 요청과 상세도 사라짐 + init(store: StoreOf, windowEvent: TodoEditorWindowEvent?) { + self.store = store self.windowEvent = windowEvent } @@ -78,7 +70,7 @@ struct SearchView: View { .prominentAlert(store, state: \.alert, action: \.alert) // 좁은 창은 홈 내비게이션에 쌓고, 사이드바가 있는 창은 사이드바까지 덮는 상세 판에 표시 // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 - .compositionDetail(item: $store.scope(state: \.detail, action: \.detail)) { detailStore in + .compositionDetail(item: $store.scope(state: \.detail, action: \.detail)) { detailStore, _ in TodoDetailView(store: detailStore, windowEvent: windowEvent) } panel: { detailStore in TodoDetailPanel( diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift index bb4182da..25a499f3 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListFeature.swift @@ -71,7 +71,7 @@ struct TodoListFeature { } } - enum Action: BindableAction { + enum Action: BindableAction, Equatable { case alert(PresentationAction) case fullScreenCover(PresentationAction) case detail(PresentationAction) diff --git a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift index e99be1f1..37b6e240 100644 --- a/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift +++ b/Application/Presentation/HomeTab/Sources/Todo/List/TodoListView.swift @@ -13,8 +13,7 @@ import PresentationShared struct TodoListView: View { @Environment(\.isTabContentActive) private var isTabContentActive - @Environment(\.usesDesktopLayout) private var usesDesktopLayout - @State private var store: StoreOf + @Bindable private var store: StoreOf private let windowEvent: TodoEditorWindowEvent? init(store: StoreOf, windowEvent: TodoEditorWindowEvent? = nil) { @@ -23,59 +22,51 @@ struct TodoListView: View { } var body: some View { - // 사이드바가 있는 창은 목록을 창 전체 폭으로 두고 오른쪽 칸에서 연 Todo나 작성 화면이 있을 때만 두 칸으로 나눔 - PaneSplitView(splitsOnDesktop: store.showsDetailInPane && store.detail != nil || store.fullScreenCover != nil) { + PaneSplitView { TodoListContent(store: store) { todoId in store.send(.view(.selectTodo(todoId))) } - } detail: { - // 칸으로 나눈 화면은 새 Todo를 덮는 화면 대신 상세 칸 자리에서 작성 - if let editorStore = store.scope( - state: \.fullScreenCover?.todoEditor, - action: \.fullScreenCover.presented.todoEditor - ) { - TodoEditorView(store: editorStore, onClose: { store.send(.fullScreenCover(.dismiss)) }) - } else if store.showsDetailInPane, - let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + // 좁은 창은 목록 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + inPane: store.showsDetailInPane, + isActive: isTabContentActive + ) { detailStore, onClose in TodoDetailView( store: detailStore, windowEvent: windowEvent, - isPaneDetail: true, - onClose: { store.send(.detail(.dismiss)) } + isPaneDetail: onClose != nil, + onClose: onClose ) - .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 .id(detailStore.todoId) - } else { - PanePlaceholder() - } - } - // 좁은 창은 목록 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 - // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 - .compositionDetail( - item: $store.scope(state: \.detail, action: \.detail), - inPane: store.showsDetailInPane, - isActive: isTabContentActive - ) { detailStore in - TodoDetailView(store: detailStore, windowEvent: windowEvent) - } panel: { detailStore in - // 목록에서 빠진 Todo는 지울 경로가 없어 판 메뉴에서 삭제 생략 - let todo = store.todos.first { $0.id == detailStore.todoId } - - TodoDetailPanel( - store: detailStore, - location: Text(TodoCategoryItem(from: store.category).localizedName), - windowEvent: windowEvent, - onMoveToPane: { - store.send(.binding(.set(\.showsDetailInPane, true))) - }, - onDelete: todo.map { todo in - { - store.send(.view(.swipeTodo(todo))) - presentDeleteTodoToast(todo.id, store: store) + } panel: { detailStore in + // 목록에서 빠진 Todo는 지울 경로가 없어 판 메뉴에서 삭제 생략 + let todo = store.todos.first { $0.id == detailStore.todoId } + + TodoDetailPanel( + store: detailStore, + location: Text(TodoCategoryItem(from: store.category).localizedName), + windowEvent: windowEvent, + onMoveToPane: { + store.send(.binding(.set(\.showsDetailInPane, true))) + }, + onDelete: todo.map { todo in + { + store.send(.view(.swipeTodo(todo))) + presentDeleteTodoToast(todo.id, store: store) + } } - } - ) + ) + } + // 칸으로 나눈 화면은 새 Todo를 덮는 화면 대신 상세 칸 자리에서 작성 + .compositionEditor( + item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover), + isActive: isTabContentActive + ) { coverStore, onClose in + fullScreenCoverContent(coverStore, onClose: onClose) + } } // 옆 칸에 연 Todo의 속성은 세부 정보 사이드바에 표시 .compositionRight(isActive: store.showsDetailInPane && store.detail != nil) { @@ -89,12 +80,6 @@ struct TodoListView: View { // 상세 칸에서 편집한 Todo를 옆 목록에도 반영 store.send(.view(.windowTodoUpdated)) } - .compositionEditor( - item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover) - .activePresentation(when: isTabContentActive) - ) { coverStore in - fullScreenCoverContent(coverStore) - } .background(Color.background.ignoresSafeArea()) .task { store.send(.view(.onAppear)) } } @@ -107,12 +92,13 @@ struct TodoListView: View { private func fullScreenCoverContent( _ coverStore: Store< TodoListFeature.FullScreenCoverState, - TodoListFeature.Action.FullScreenCover> + TodoListFeature.Action.FullScreenCover>, + onClose: (() -> Void)? ) -> some View { switch coverStore.destination { case .editor: if let todoEditorStore = coverStore.scope(state: \.todoEditor, action: \.todoEditor) { - TodoEditorView(store: todoEditorStore) + TodoEditorView(store: todoEditorStore, onClose: onClose) } } } @@ -317,7 +303,6 @@ private struct TodoListTopBar: View { @Environment(\.readableContentWidth) private var readableContentWidth @Environment(\.showsPaneTitleBar) private var showsPaneTitleBar @Environment(\.deviceType) private var deviceType - @Environment(\.sideBarRequest) private var sideBarRequest @Namespace private var searchTransition let store: StoreOf @@ -373,11 +358,6 @@ private struct TodoListTopBar: View { } } .background(Color.background, ignoresSafeAreaEdges: .top) - // 사이드바 Todo 메뉴의 작성은 이 목록의 작성 버튼과 같은 방식으로 작성 - .onChange(of: sideBarRequest) { _, request in - guard request?.action == .createTodo else { return } - store.send(.store(.setFullScreenCover(.editor))) - } } @ViewBuilder diff --git a/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTestSupport.swift b/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTestSupport.swift index 611cab13..e6b32c90 100644 --- a/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTestSupport.swift +++ b/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTestSupport.swift @@ -25,15 +25,15 @@ struct StoreTestAdapter { var hasDevelopmentGoalsLoadFailure: Bool { store.state.hasDevelopmentGoalsLoadFailure } var isNetworkConnected: Bool { store.state.isNetworkConnected } var showContentPicker: Bool { store.state.showContentPicker } - var showCategoryManage: Bool { - store.state.sheet?.categoryManageState != nil - } + var showCategoryManage: Bool { store.state.categoryManage != nil } var showTodoEditor: Bool { store.state.showTodoEditor } - var sheet: HomeFeature.SheetState? { store.state.sheet } + var categoryManage: CategoryManageFeature.State? { store.state.categoryManage } + var goalCreate: GoalCreateFeature.State? { store.state.goalCreate } + var goalDetail: GoalDetailFeature.State? { store.state.goalDetail } var alert: AlertState? { store.state.alert } - var sideBarRequestAfterGoalDiscard: SideBarRequest? { store.state.sideBarRequestAfterGoalDiscard } init( + initialState: HomeFeature.State = HomeFeature.State(), fetchPreferencesUseCase: FetchTodoCategoryPreferencesUseCase = FetchTodoCategoryPreferencesUseCaseSpy(), updatePreferencesUseCase: UpdateTodoCategoryPreferencesUseCase = UpdateTodoCategoryPreferencesUseCaseSpy(), networkConnectivityUseCase: ObserveNetworkConnectivityUseCase = ObserveNetworkConnectivityUseCaseSpy(), @@ -45,7 +45,7 @@ struct StoreTestAdapter { ) { let clock = TestClock() self.clock = clock - store = TestStore(initialState: HomeFeature.State()) { + store = TestStore(initialState: initialState) { HomeFeature() } withDependencies: { $0.fetchTodoCategoryPreferencesUseCase = fetchPreferencesUseCase @@ -99,32 +99,29 @@ struct StoreTestAdapter { await store.send(.view(.tapDevelopmentGoal(goalID))) } - func setSheet(_ sheet: HomeFeature.SheetState?) async { - await store.send(.store(.setSheet(sheet))) - } - func tapAddCategoryManageItem() async { - await store.send(.sheet(.presented(.categoryManage(.tapAddUserCategory)))) + await store.send(.categoryManage(.presented(.tapAddUserCategory))) } func tapCategoryManageItem(_ item: TodoCategoryItem) async { - await store.send(.sheet(.presented(.categoryManage(.tapItem(item))))) + await store.send(.categoryManage(.presented(.tapItem(item)))) } func changeCategoryPreferences(_ items: [TodoCategoryItem]) async { - await store.send(.sheet(.presented(.categoryManage(.delegate(.changed(items)))))) + await store.send(.categoryManage(.presented(.delegate(.changed(items))))) } func setGoalCreateSaving() async { - await store.send(.sheet(.presented(.goalCreate(.binding(.set(\.isSaving, true)))))) + await store.send(.goalCreate(.presented(.binding(.set(\.isSaving, true))))) } func setGoalCreateTitle(_ title: String) async { - await store.send(.sheet(.presented(.goalCreate(.binding(.set(\.title, title)))))) + await store.send(.goalCreate(.presented(.binding(.set(\.title, title))))) } - func closeGoalDraftForSideBarRequest(_ request: SideBarRequest) async { - await store.send(.view(.closeGoalDraftForSideBarRequest(request))) + func sideBarRequested(_ request: SideBarRequest) async { + await store.send(.view(.sideBarRequested(request))) + await drainReceivedActions() } func discardGoalDraft() async { @@ -137,7 +134,7 @@ struct StoreTestAdapter { } func goalCreateSaved(_ goal: DevelopmentGoal) async { - await store.send(.sheet(.presented(.goalCreate(.delegate(.saved(goal)))))) + await store.send(.goalCreate(.presented(.delegate(.saved(goal))))) await drainReceivedActions() } @@ -146,8 +143,13 @@ struct StoreTestAdapter { await settle() } - func dismissSheet() async { - await store.send(.sheet(.dismiss)) + func dismissGoalCreate() async { + await store.send(.goalCreate(.dismiss)) + await drainReceivedActions() + } + + func dismissCategoryManage() async { + await store.send(.categoryManage(.dismiss)) await drainReceivedActions() } diff --git a/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift b/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift index cb8e6e2d..ab9e3ff9 100644 --- a/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift +++ b/Application/Presentation/HomeTab/Tests/Home/HomeFeatureTests.swift @@ -127,15 +127,15 @@ struct HomeFeatureTests { await adapter.tapCreateDevelopmentGoal() - #expect(adapter.sheet == .goalCreate(GoalCreateFeature.State())) + #expect(adapter.goalCreate == GoalCreateFeature.State()) - await adapter.dismissSheet() + await adapter.dismissGoalCreate() - #expect(adapter.sheet == nil) + #expect(adapter.goalCreate == nil) await adapter.tapDevelopmentGoal("goal") - #expect(adapter.sheet?.goalDetailState?.goalId == "goal") + #expect(adapter.goalDetail?.goalId == "goal") } @Test("작성 중인 새 개발 목표가 있으면 버릴지 물은 뒤 버리면 고른 목표를 연다") @@ -147,30 +147,30 @@ struct HomeFeatureTests { await adapter.tapDevelopmentGoal("goal") #expect(adapter.alert == HomeFeature.discardGoalDraftAlertState(isEditing: false)) - #expect(adapter.sheet?.goalCreateState?.title == "목표") + #expect(adapter.goalCreate?.title == "목표") await adapter.discardGoalDraft() - #expect(adapter.sheet?.goalDetailState?.goalId == "goal") + #expect(adapter.goalDetail?.goalId == "goal") } @Test("수정 중인 개발 목표가 있으면 버릴지 물은 뒤 버리면 고른 목표를 연다") func 수정_중인_개발_목표가_있으면_버릴지_물은_뒤_버리면_고른_목표를_연다() async throws { - let adapter = StoreTestAdapter() let goal = try makeDevelopmentGoal() - var detail = GoalDetailFeature.State(goalId: goal.id) - detail.goalEdit = GoalCreateFeature.State(goal: goal) - detail.goalEdit?.title = "바꾼 제목" + var state = HomeFeature.State() + state.goalDetail = GoalDetailFeature.State(goalId: goal.id) + state.goalDetail?.goalEdit = GoalCreateFeature.State(goal: goal) + state.goalDetail?.goalEdit?.title = "바꾼 제목" + let adapter = StoreTestAdapter(initialState: state) - await adapter.setSheet(.goalDetail(detail)) await adapter.tapDevelopmentGoal("other") #expect(adapter.alert == HomeFeature.discardGoalDraftAlertState(isEditing: true)) - #expect(adapter.sheet?.goalDetailState?.goalEdit?.title == "바꾼 제목") + #expect(adapter.goalDetail?.goalEdit?.title == "바꾼 제목") await adapter.discardGoalDraft() - #expect(adapter.sheet?.goalDetailState?.goalId == "other") + #expect(adapter.goalDetail?.goalId == "other") } @Test("작성 중인 새 개발 목표를 버리지 않으면 칸을 유지한다") @@ -183,24 +183,25 @@ struct HomeFeatureTests { await adapter.cancelGoalDraftDiscard() #expect(adapter.alert == nil) - #expect(adapter.sheet?.goalCreateState?.title == "목표") + #expect(adapter.goalCreate?.title == "목표") } @Test("작성 중인 새 개발 목표를 버리면 미뤄 둔 사이드바 요청을 다시 처리한다") func 작성_중인_새_개발_목표를_버리면_미뤄_둔_사이드바_요청을_다시_처리한다() async { let adapter = StoreTestAdapter() - let request = SideBarRequest(id: UUID(), action: .open(.home)) + let request = SideBarRequest(id: UUID(), action: .open(.developmentGoal("goal"))) await adapter.tapCreateDevelopmentGoal() await adapter.setGoalCreateTitle("목표") - await adapter.closeGoalDraftForSideBarRequest(request) + await adapter.sideBarRequested(request) - #expect(adapter.sideBarRequestAfterGoalDiscard == nil) + #expect(adapter.alert == HomeFeature.discardGoalDraftAlertState(isEditing: false)) + #expect(adapter.goalDetail == nil) await adapter.discardGoalDraft() - #expect(adapter.sheet == nil) - #expect(adapter.sideBarRequestAfterGoalDiscard == request) + #expect(adapter.goalCreate == nil) + #expect(adapter.goalDetail?.goalId == "goal") } @Test("입력하지 않은 새 개발 목표는 묻지 않고 고른 목표를 연다") @@ -211,31 +212,33 @@ struct HomeFeatureTests { await adapter.tapDevelopmentGoal("goal") #expect(adapter.alert == nil) - #expect(adapter.sheet?.goalDetailState?.goalId == "goal") + #expect(adapter.goalDetail?.goalId == "goal") } @Test("새 개발 목표를 저장하는 동안 시트를 바꾸지 않는다") func 새_개발_목표를_저장하는_동안_시트를_바꾸지_않는다() async { - let adapter = StoreTestAdapter() + var state = HomeFeature.State() + state.usesDesktopLayout = true + let adapter = StoreTestAdapter(initialState: state) await adapter.tapCreateDevelopmentGoal() await adapter.setGoalCreateSaving() await adapter.tapDevelopmentGoal("goal") - await adapter.setSheet(nil) + await adapter.sideBarRequested(SideBarRequest(id: UUID(), action: .open(.home))) - #expect(adapter.sheet?.goalCreateState?.isSaving == true) + #expect(adapter.goalCreate?.isSaving == true) } @Test("수정 중인 개발 목표를 버리고 칸을 닫으면 개발 목표 목록을 다시 조회한다") func 수정_중인_개발_목표를_버리고_칸을_닫으면_개발_목표_목록을_다시_조회한다() async throws { let goalsSpy = FetchDevelopmentGoalsUseCaseSpy() - let adapter = StoreTestAdapter(fetchDevelopmentGoalsUseCase: goalsSpy) let goal = try makeDevelopmentGoal() - var detail = GoalDetailFeature.State(goalId: goal.id) - detail.goalEdit = GoalCreateFeature.State(goal: goal) - detail.goalEdit?.title = "바꾼 제목" + var state = HomeFeature.State() + state.goalDetail = GoalDetailFeature.State(goalId: goal.id) + state.goalDetail?.goalEdit = GoalCreateFeature.State(goal: goal) + state.goalDetail?.goalEdit?.title = "바꾼 제목" + let adapter = StoreTestAdapter(initialState: state, fetchDevelopmentGoalsUseCase: goalsSpy) - await adapter.setSheet(.goalDetail(detail)) await adapter.tapManageTodoCategory() #expect(goalsSpy.queries.isEmpty) @@ -244,45 +247,45 @@ struct HomeFeatureTests { await waitUntil { !goalsSpy.queries.isEmpty } #expect(goalsSpy.queries == [.init(status: .inProgress)]) - #expect(adapter.sheet?.goalDetailState == nil) + #expect(adapter.goalDetail == nil) } @Test("수정 중인 개발 목표를 버리면 미뤄 둔 사이드바 요청을 다시 처리한다") func 수정_중인_개발_목표를_버리면_미뤄_둔_사이드바_요청을_다시_처리한다() async throws { - let adapter = StoreTestAdapter() - let request = SideBarRequest(id: UUID(), action: .open(.home)) + let request = SideBarRequest(id: UUID(), action: .open(.developmentGoal("other"))) let goal = try makeDevelopmentGoal() - var detail = GoalDetailFeature.State(goalId: goal.id) - detail.goalEdit = GoalCreateFeature.State(goal: goal) - detail.goalEdit?.content = "바꾼 설명" + var state = HomeFeature.State() + state.goalDetail = GoalDetailFeature.State(goalId: goal.id) + state.goalDetail?.goalEdit = GoalCreateFeature.State(goal: goal) + state.goalDetail?.goalEdit?.content = "바꾼 설명" + let adapter = StoreTestAdapter(initialState: state) - await adapter.setSheet(.goalDetail(detail)) - await adapter.closeGoalDraftForSideBarRequest(request) + await adapter.sideBarRequested(request) #expect(adapter.alert == HomeFeature.discardGoalDraftAlertState(isEditing: true)) - #expect(adapter.sideBarRequestAfterGoalDiscard == nil) + #expect(adapter.goalDetail?.goalId == goal.id) await adapter.discardGoalDraft() - #expect(adapter.sheet == nil) - #expect(adapter.sideBarRequestAfterGoalDiscard == request) + #expect(adapter.goalDetail?.goalId == "other") } @Test("수정 중인 개발 목표를 저장하는 동안 시트를 바꾸지 않는다") func 수정_중인_개발_목표를_저장하는_동안_시트를_바꾸지_않는다() async throws { - let adapter = StoreTestAdapter() let goal = try makeDevelopmentGoal() - var detail = GoalDetailFeature.State(goalId: goal.id) - detail.goalEdit = GoalCreateFeature.State(goal: goal) - detail.goalEdit?.title = "바꾼 제목" - detail.goalEdit?.isSaving = true + var state = HomeFeature.State() + state.usesDesktopLayout = true + state.goalDetail = GoalDetailFeature.State(goalId: goal.id) + state.goalDetail?.goalEdit = GoalCreateFeature.State(goal: goal) + state.goalDetail?.goalEdit?.title = "바꾼 제목" + state.goalDetail?.goalEdit?.isSaving = true + let adapter = StoreTestAdapter(initialState: state) - await adapter.setSheet(.goalDetail(detail)) await adapter.tapDevelopmentGoal("other") - await adapter.setSheet(nil) + await adapter.sideBarRequested(SideBarRequest(id: UUID(), action: .open(.home))) #expect(adapter.alert == nil) - #expect(adapter.sheet?.goalDetailState?.goalEdit?.isSaving == true) + #expect(adapter.goalDetail?.goalEdit?.isSaving == true) } @Test("새 개발 목표를 저장하면 시트를 닫고 홈 데이터를 다시 조회한다") @@ -296,7 +299,7 @@ struct HomeFeatureTests { await adapter.goalCreateSaved(goal) await waitUntil { adapter.hasDevelopmentGoalsLoaded } - #expect(adapter.sheet == nil) + #expect(adapter.goalCreate == nil) #expect(adapter.developmentGoalItems.map(\.id) == [goal.id]) } @@ -306,11 +309,11 @@ struct HomeFeatureTests { await adapter.tapManageTodoCategory() await adapter.tapAddCategoryManageItem() - let id = adapter.sheet?.categoryManageState?.categorySheet?.category.id + let id = adapter.categoryManage?.categorySheet?.category.id await adapter.tapManageTodoCategory() #expect(id != nil) - #expect(adapter.sheet?.categoryManageState?.categorySheet?.category.id == id) + #expect(adapter.categoryManage?.categorySheet?.category.id == id) } @Test("카테고리 관리에서 바로 저장한 변경은 마지막 값만 저장한다") @@ -339,7 +342,7 @@ struct HomeFeatureTests { await adapter.tapManageTodoCategory() await adapter.changeCategoryPreferences([feature, issue]) - await adapter.dismissSheet() + await adapter.dismissCategoryManage() await adapter.advanceClock(by: .seconds(1)) await waitUntil { !updateSpy.updates.isEmpty } diff --git a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift index b2fbe69e..cd716fee 100644 --- a/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift +++ b/Application/Presentation/NotificationTab/Sources/PushNotificationListView.swift @@ -29,13 +29,10 @@ public struct PushNotificationListView: View { } public var body: some View { - // 사이드바가 있는 창에서 오른쪽 칸을 열었을 때만 목록 | 상세 두 칸으로 나눔 - let showsPane = usesDesktopLayout && store.showsDetailInPane - NavigationStack { - PaneSplitView(splitsOnDesktop: showsPane) { + PaneSplitView { // 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 연 알림을 목록에 선택 표시 - PushNotificationListContent(store: store, showsSelection: usesDesktopLayout) + PushNotificationListContent(store: store) .background(Color.background) .refreshable(isEnabled: PullToRefreshAvailability.isEnabled) { let task = store.send(.view(.refresh)) @@ -43,23 +40,40 @@ public struct PushNotificationListView: View { store.send(.view(.startObserving)) } .duoToolbarVisibility() - } detail: { - if store.showsDetailInPane, - let detailStore = store.scope(state: \.detail, action: \.detail.presented) { - TodoDetailView( - store: detailStore, - isPaneDetail: true, - onClose: { store.send(.detail(.dismiss)) } - ) - .environment(\.showsPaneTitleBar, true) - // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 - .id(detailStore.todoId) - } else { - PanePlaceholder() - } + // 좁은 창은 시트로 띄우고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 오른쪽 칸을 연 동안은 고른 알림이 없어도 칸에 안내 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + narrow: .sheet, + inPane: store.showsDetailInPane, + emptyPane: true, + isActive: isSelected + ) { detailStore, onClose in + if let onClose { + TodoDetailView(store: detailStore, isPaneDetail: true, onClose: onClose) + // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 + .id(detailStore.todoId) + } else { + NavigationStack { + TodoDetailView(store: detailStore) + } + .environment(\.windowControlsInset, 0) + .environment(\.deviceType, .bar) + .background(Color.background) + } + } panel: { detailStore in + TodoDetailPanel( + store: detailStore, + location: Text("nav_push_notifications", bundle: PresentationResources.bundle), + onMoveToPane: { + store.send(.binding(.set(\.showsDetailInPane, true))) + } + ) + } } // 오른쪽 칸은 칸 제목 줄 정보 버튼 대신 창 오른쪽 세부 정보 사이드바에 속성 표시 - .compositionRight(isActive: showsPane && store.detail != nil) { + .compositionRight(isActive: usesDesktopLayout && store.showsDetailInPane && store.detail != nil) { if let todoId = store.detail?.todoId { TodoDetailSideBarView(todoId: todoId, isEditable: false, windowEvent: windowEvent) .id(todoId) @@ -67,29 +81,6 @@ public struct PushNotificationListView: View { } } .prominentAlert(store, state: \.alert, action: \.alert) - // 좁은 창은 시트로 띄우고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 - // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 - .compositionDetail( - item: $store.scope(state: \.detail, action: \.detail), - narrow: .sheet, - inPane: store.showsDetailInPane, - isActive: isSelected - ) { detailStore in - NavigationStack { - TodoDetailView(store: detailStore) - } - .environment(\.windowControlsInset, 0) - .environment(\.deviceType, .bar) - .background(Color.background) - } panel: { detailStore in - TodoDetailPanel( - store: detailStore, - location: Text("nav_push_notifications", bundle: PresentationResources.bundle), - onMoveToPane: { - store.send(.binding(.set(\.showsDetailInPane, true))) - } - ) - } .onChange(of: isSelected, initial: true) { _, isSelected in if isSelected { store.send(.view(.fetchNotifications)) @@ -109,8 +100,6 @@ private struct PushNotificationListContent: View { @Environment(\.windowControlsInset) private var windowControlsInset @ScaledMetric(relativeTo: .body) private var iconSize = 32 let store: StoreOf - // 고른 알림을 상세 판이나 옆 칸에 표시하는 동안 목록 행에 선택 표시 - let showsSelection: Bool @ViewBuilder var body: some View { @@ -150,7 +139,8 @@ private struct PushNotificationListContent: View { LazyVStack(spacing: 0) { ForEach(items) { item in let category = TodoCategoryItem(from: item.todoCategory) - let isSelected = showsSelection && item.id == store.selectedNotificationId + // 사이드바가 있는 창은 고른 알림을 상세 판이나 옆 칸에 표시하는 동안 목록 행에 선택 표시 + let isSelected = usesDesktopLayout && item.id == store.selectedNotificationId HStack(alignment: .top, spacing: 10) { // 테두리 있는 회색 사각형에 카테고리 색 기호 diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index b2533584..2f3e5c23 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -17,20 +17,24 @@ public enum CompositionNarrow { public extension View { // 읽는 화면 // 좁은 창은 내비게이션에 쌓거나 시트로 띄우고, 사이드바가 있는 창은 사이드바까지 덮는 상세 판으로 띄움 - // inPane이 참이면 사이드바가 있는 창에서 상세 판 대신 PaneSplitView의 detail이 그림 - // isActive가 거짓이면 창 위에 덮는 시트와 상세 판은 띄우지 않고, 내비게이션에 쌓은 화면은 그대로 둠 + // inPane이 참이면 사이드바가 있는 창에서 상세 판 대신 이 화면을 감싼 PaneSplitView의 상세 칸에 올림 + // emptyPane이 참이면 고른 항목이 없어도 상세 칸에 안내를 올림 + // isActive가 거짓이면 창 위에 덮는 시트와 상세 판은 띄우지 않고, 내비게이션에 쌓은 화면과 상세 칸은 그대로 둠 + // content는 상세 칸에 그릴 때만 닫는 동작을 받음 func compositionDetail( item: Binding, narrow: CompositionNarrow = .push, inPane: Bool = false, + emptyPane: Bool = false, isActive: Bool = true, - @ViewBuilder content: @escaping (Item) -> Content, + @ViewBuilder content: @escaping (Item, (() -> Void)?) -> Content, @ViewBuilder panel: @escaping (Item) -> Panel ) -> some View { modifier(CompositionDetailModifier( item: item, narrow: narrow, inPane: inPane, + emptyPane: emptyPane, isActive: isActive, detail: content, panel: panel @@ -38,15 +42,25 @@ public extension View { } // 저장이나 닫기 버튼으로만 닫는 작성 화면 - // 좁은 창은 전체 화면이나 시트로 띄우고, 사이드바가 있는 창은 PaneSplitView의 detail이 그림 + // 좁은 창은 전체 화면이나 시트로 띄우고, 사이드바가 있는 창은 이 화면을 감싼 PaneSplitView의 상세 칸에 올림 + // 상세 칸에는 읽는 화면보다 작성 화면을 먼저 올리고, 작성 화면끼리는 바깥에 붙인 수정자의 화면을 올림 // inPane이 거짓이면 사이드바가 있는 창에서도 시트로 띄움 + // isActive가 거짓이면 창 위에 띄우지 않고 상세 칸은 그대로 둠 + // content는 상세 칸에 그릴 때만 닫는 동작을 받음 func compositionEditor( item: Binding, narrow: CompositionNarrow = .cover, inPane: Bool = true, - @ViewBuilder content: @escaping (Item) -> Content + isActive: Bool = true, + @ViewBuilder content: @escaping (Item, (() -> Void)?) -> Content ) -> some View { - modifier(CompositionEditorModifier(item: item, narrow: narrow, inPane: inPane, editor: content)) + modifier(CompositionEditorModifier( + item: item, + narrow: narrow, + inPane: inPane, + isActive: isActive, + editor: content + )) } // 바꾸면 바로 저장하는 시트 @@ -124,11 +138,13 @@ private final class LiveLayout { private struct CompositionDetailModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout @State private var layout = LiveLayout() + @State private var id = UUID() let item: Binding let narrow: CompositionNarrow let inPane: Bool + let emptyPane: Bool let isActive: Bool - let detail: (Item) -> Detail + let detail: (Item, (() -> Void)?) -> Detail let panel: (Item) -> Panel func body(content: Content) -> some View { @@ -138,19 +154,40 @@ private struct CompositionDetailModifier) -> some View { switch narrow { case .push: content - .navigationDestination(item: narrowItem, interactivePop: true, destination: detail) - .detailPanel(item: panelItem, content: panel) + .navigationDestination(item: item, interactivePop: true) { detail($0, nil) } case .sheet: content - .prominentSheet(item: narrowItem.activePresentation(when: isActive), content: detail) - .detailPanel(item: panelItem, content: panel) + .prominentSheet(item: item.activePresentation(when: isActive)) { detail($0, nil) } case .cover: content - .fullScreenCover(item: narrowItem.activePresentation(when: isActive), content: detail) - .detailPanel(item: panelItem, content: panel) + .fullScreenCover(item: item.activePresentation(when: isActive)) { detail($0, nil) } + } + } + + // 상세 칸이 그릴 때마다 지금 고른 항목을 읽음 + @ViewBuilder + private var paneContent: some View { + if let value = item.wrappedValue { + detail(value, { item.wrappedValue = nil }) + .environment(\.showsPaneTitleBar, true) + } else { + PanePlaceholder() } } } @@ -158,33 +195,61 @@ private struct CompositionDetailModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout @State private var layout = LiveLayout() + @State private var id = UUID() let item: Binding let narrow: CompositionNarrow let inPane: Bool - let editor: (Item) -> Editor + let isActive: Bool + let editor: (Item, (() -> Void)?) -> Editor func body(content: Content) -> some View { // 넓은 창으로 바뀌어 칸에 옮겨 그린 뒤 늦게 닫히는 화면은 작성 중인 초안을 지우지 않음 let layout = layout.update(usesDesktopLayout: usesDesktopLayout) - let narrowItem = item.hiddenInPane { layout.usesDesktopLayout } + let activeItem = item.activePresentation(when: isActive) + let narrowItem = activeItem.hiddenInPane { layout.usesDesktopLayout } + + presentedContent(content, activeItem: activeItem, narrowItem: narrowItem, layout: layout) + // 가려진 탭에서도 작성 중인 화면을 상세 칸에 그대로 두도록 isActive와 상관없이 올림 + .transformPreference(PaneDetailContentPreferenceKey.self) { value in + guard inPane, item.wrappedValue != nil else { return } + value = PaneDetailContent(id: id, isEditor: true) { + AnyView(paneContent) + } + } + } + @ViewBuilder + private func presentedContent( + _ content: Content, + activeItem: Binding, + narrowItem: Binding, + layout: LiveLayout + ) -> some View { switch (narrow, inPane) { case (.cover, true): content - .fullScreenCover(item: narrowItem, content: editor) + .fullScreenCover(item: narrowItem) { editor($0, nil) } case (.sheet, true): content - .prominentSheet(item: narrowItem, content: editor) + .prominentSheet(item: narrowItem) { editor($0, nil) } case (.cover, false): content - .fullScreenCover(item: narrowItem, content: editor) - .prominentSheet(item: item.hiddenInPane { !layout.usesDesktopLayout }, content: editor) + .fullScreenCover(item: narrowItem) { editor($0, nil) } + .prominentSheet(item: activeItem.hiddenInPane { !layout.usesDesktopLayout }) { editor($0, nil) } case (.sheet, false): content - .prominentSheet(item: item, content: editor) + .prominentSheet(item: activeItem) { editor($0, nil) } case (.push, _): content - .navigationDestination(item: narrowItem, interactivePop: true, destination: editor) + .navigationDestination(item: narrowItem, interactivePop: true) { editor($0, nil) } + } + } + + // 상세 칸이 그릴 때마다 지금 작성 중인 항목을 읽음 + @ViewBuilder + private var paneContent: some View { + if let value = item.wrappedValue { + editor(value, { item.wrappedValue = nil }) } } } diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift index 7d172058..4c45b94d 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift @@ -8,38 +8,38 @@ import SwiftUI // 사이드바가 있는 창에서 목록 칸 오른쪽에 상세 칸을 나란히 두는 화면 -public struct PaneSplitView: View { +// 상세 칸 내용은 목록 칸 안의 compositionDetail, compositionEditor가 올리고, 올린 내용이 있을 때만 두 칸으로 나눔 +public struct PaneSplitView: View { @Environment(\.usesDesktopLayout) private var usesDesktopLayout @State private var width = CGFloat.infinity // 경계선을 끌어 정한 목록 칸 폭, 없으면 기본 폭 @State private var primaryWidth: CGFloat? // 상세 칸에 작성 화면을 그린 동안 @State private var isDetailEditing = false - // 사이드바가 있는 창은 따로 정한 화면만 두 칸으로 나눔 - private let splitsOnDesktop: Bool + // 목록 칸 안의 수정자가 올린 상세 칸 내용 + @State private var detail: PaneDetailContent? private let primary: Primary - // 상세 칸을 그릴 때만 만들어 칸이 없는 화면에서 상세 내용을 만들지 않음 - private let detail: () -> Detail - public init( - splitsOnDesktop: Bool = true, - @ViewBuilder primary: () -> Primary, - @ViewBuilder detail: @escaping () -> Detail - ) { - self.splitsOnDesktop = splitsOnDesktop + public init(@ViewBuilder primary: () -> Primary) { self.primary = primary() - self.detail = detail } public var body: some View { // 두 칸이 기본 폭으로 함께 들어가지 않는 창은 반씩 나눠 처음부터 상세 칸이 잘리지 않게 함 let paneWidth = min(400, width / 2) - let showsDetail = usesDesktopLayout && splitsOnDesktop + let showsDetail = usesDesktopLayout && detail != nil HStack(spacing: 0) { // 넓은 창과 좁은 창을 오가도 목록 칸을 다시 만들지 않도록 같은 구조로 두고 사이드바 구조에서만 폭 조절 // 경계선은 사이드바 경계선부터 창 오른쪽 끝까지 이동 primary + .onPreferenceChange(PaneDetailContentPreferenceKey.self) { content in + detail = content + } + // 바깥 PaneSplitView로 올라가지 않도록 받은 내용을 비움 + .transformPreference(PaneDetailContentPreferenceKey.self) { content in + content = nil + } .resizablePane( width: primaryWidth, minimumWidth: 0, @@ -59,11 +59,11 @@ public struct PaneSplitView: View { } } // 좁은 창으로 바뀌면 상세 칸을 빼고, 같은 상태를 화면이 좁은 창의 표시로 이어 그림 - if showsDetail { + if showsDetail, let detail { // 상세 칸이 기본 폭보다 좁으면 내용을 줄이지 않고 잘라서 표시 Color.clear .overlay(alignment: .leading) { - detail() + detail .frame(minWidth: paneWidth, maxWidth: .infinity) // 사이드바 펴기 버튼은 왼쪽 칸 제목 줄에만 표시 .environment(\.expandSideBar, nil) @@ -95,6 +95,32 @@ public struct PaneSplitView: View { } } +// 목록 칸 안의 수정자가 올린 상세 칸 내용 +// 같은 수정자가 올린 동안은 같은 값으로 보고, 내용이 읽는 상태가 바뀌면 이 View만 다시 그림 +struct PaneDetailContent: View, Equatable { + let id: UUID + // 저장이나 닫기 버튼으로만 닫는 작성 화면, 읽는 화면보다 먼저 표시 + let isEditor: Bool + let content: () -> AnyView + + var body: some View { + content() + } + + static func == (lhs: Self, rhs: Self) -> Bool { + lhs.id == rhs.id && lhs.isEditor == rhs.isEditor + } +} + +// 목록 칸 안의 화면이 올린 상세 칸 내용 +struct PaneDetailContentPreferenceKey: PreferenceKey { + static var defaultValue: PaneDetailContent? { nil } + + static func reduce(value: inout PaneDetailContent?, nextValue: () -> PaneDetailContent?) { + value = nextValue() ?? value + } +} + // 상세 칸에 저장·닫기 버튼으로만 닫는 작성 화면을 그렸는지 전달 public struct PaneDetailEditingPreferenceKey: PreferenceKey { public static let defaultValue = false diff --git a/Application/Presentation/PresentationShared/Sources/Common/NavigationRouter.swift b/Application/Presentation/PresentationShared/Sources/Common/NavigationRouter.swift deleted file mode 100644 index 76dec79d..00000000 --- a/Application/Presentation/PresentationShared/Sources/Common/NavigationRouter.swift +++ /dev/null @@ -1,40 +0,0 @@ -// -// NavigationRouter.swift -// PresentationShared -// -// Created by 최윤진 on 1/1/26. -// - -import SwiftUI - -@Observable -public final class NavigationRouter { - public var path: [Route] = [] - - public var root: Route? { - path.first - } - - public var detailPath: [Route] { - get { - Array(path.dropFirst()) - } - set { - if let route = root { - path = [route] + newValue - } else { - path = newValue - } - } - } - - public init() {} - - public func replace(with route: Route) { - path = [route] - } - - public func push(_ route: Route) { - path.append(route) - } -} diff --git a/Application/Presentation/PresentationShared/Sources/Common/SideBarNavigation.swift b/Application/Presentation/PresentationShared/Sources/Common/SideBarNavigation.swift index 08ddfe9e..7dd38540 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/SideBarNavigation.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/SideBarNavigation.swift @@ -79,3 +79,47 @@ public struct SideBarContentPreferenceKey: PreferenceKey { value = nextValue() ?? value } } + +public extension View { + // 탭 루트 화면이 사이드바에 표시할 위치와 묶음 하위 항목을 올리고 사이드바 요청을 받음 + // 사이드바가 있는 창으로 켜지거나 좁은 창에서 넓어지면 하위 항목을 채우도록 onLoad 호출 + func compositionLeft( + location: SideBarLocation, + content: SideBarContent, + onLoad: @escaping () -> Void, + onRequest: @escaping (SideBarRequest) -> Void + ) -> some View { + modifier(CompositionLeftModifier( + location: location, + sideBarContent: content, + onLoad: onLoad, + onRequest: onRequest + )) + } +} + +private struct CompositionLeftModifier: ViewModifier { + @Environment(\.sideBarRequest) private var sideBarRequest + @Environment(\.usesDesktopLayout) private var usesDesktopLayout + let location: SideBarLocation + let sideBarContent: SideBarContent + let onLoad: () -> Void + let onRequest: (SideBarRequest) -> Void + + func body(content: Content) -> some View { + content + .preference(key: SideBarLocationPreferenceKey.self, value: location) + .preference(key: SideBarContentPreferenceKey.self, value: sideBarContent) + // 사이드바 요청으로 처음 여는 탭도 그 요청을 반영 + .onChange(of: sideBarRequest, initial: true) { _, request in + if let request { + onRequest(request) + } + } + .onChange(of: usesDesktopLayout, initial: true) { _, usesDesktopLayout in + if usesDesktopLayout { + onLoad() + } + } + } +} diff --git a/Application/Presentation/PresentationShared/Sources/Extension/View+NavigationDestination.swift b/Application/Presentation/PresentationShared/Sources/Extension/View+NavigationDestination.swift index 8ad886f9..c795d053 100644 --- a/Application/Presentation/PresentationShared/Sources/Extension/View+NavigationDestination.swift +++ b/Application/Presentation/PresentationShared/Sources/Extension/View+NavigationDestination.swift @@ -34,15 +34,12 @@ public extension View { } } - func navigationDestination( - for type: Item.Type, - interactivePop: @escaping (Item) -> Bool, - @ViewBuilder destination: @escaping (Item) -> Destination - ) -> some View { - navigationDestination(for: type) { value in - destination(value) - .modifier(NavigationPopGesture(isEnabled: interactivePop(value))) - } + // 경로로 쌓은 화면의 설정, 밀어서 뒤로 가게 함 + // 위에 쌓은 화면에 가려진 동안에도 창 폭이 바뀐 것을 받도록 아래 화면에서 읽은 값을 넣음 + func stackDestination(usesDesktopLayout: Bool, usesPaneLayout: Bool) -> some View { + environment(\.showsPaneTitleBar, usesPaneLayout) + .environment(\.usesDesktopLayout, usesDesktopLayout) + .modifier(NavigationPopGesture(isEnabled: true)) } // 사이드바가 있는 창에서 쌓는 화면을 밀리는 효과 없이 내용만 바꿈 diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index 736ef23b..e8de54d9 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -39,7 +39,7 @@ public struct ProfileView: View { public var body: some View { NavigationStack { // 사이드바가 있는 창은 프로필을 창 전체 폭으로 두고 오른쪽 칸으로 옮긴 Todo가 있을 때만 두 칸으로 나눔 - PaneSplitView(splitsOnDesktop: store.showsDetailInPane && store.detail != nil) { + PaneSplitView { ScrollView { // 카드 없이 각 섹션이 페이지 여백을 가짐 LazyVStack(alignment: .leading, spacing: 0) { @@ -67,21 +67,31 @@ public struct ProfileView: View { } } .background(Color.background) - } detail: { - if store.showsDetailInPane, - let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + // 좁은 창은 프로필 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + inPane: store.showsDetailInPane, + isActive: isSelected + ) { detailStore, onClose in // 활동 기록 Todo는 고칠 수 없어 편집 결과를 받을 창 이벤트 없이 표시 TodoDetailView( store: detailStore, windowEvent: detailStore.showEditButton ? windowEvent : nil, - isPaneDetail: true, - onClose: { store.send(.detail(.dismiss)) } + isPaneDetail: onClose != nil, + onClose: onClose ) - .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 .id(detailStore.todoId) - } else { - PanePlaceholder() + } panel: { detailStore in + TodoDetailPanel( + store: detailStore, + location: Text("nav_profile", bundle: PresentationResources.bundle), + windowEvent: detailStore.showEditButton ? windowEvent : nil, + onMoveToPane: { + store.send(.binding(.set(\.showsDetailInPane, true))) + } + ) } } .compositionRight(isActive: store.showsDetailInPane && store.detail != nil) { @@ -94,24 +104,6 @@ public struct ProfileView: View { .id(detail.todoId) } } - // 좁은 창은 프로필 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 - // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 - .compositionDetail( - item: $store.scope(state: \.detail, action: \.detail), - inPane: store.showsDetailInPane, - isActive: isSelected - ) { detailStore in - TodoDetailView(store: detailStore, windowEvent: detailStore.showEditButton ? windowEvent : nil) - } panel: { detailStore in - TodoDetailPanel( - store: detailStore, - location: Text("nav_profile", bundle: PresentationResources.bundle), - windowEvent: detailStore.showEditButton ? windowEvent : nil, - onMoveToPane: { - store.send(.binding(.set(\.showsDetailInPane, true))) - } - ) - } // 좁은 창은 설정 목록과 고른 항목 화면을 프로필 위에 쌓고, 사이드바가 있는 창은 창 전체 설정 화면에 그려 쌓지 않음 .navigationDestination( isPresented: $settingsStore.isListPushed.hiddenInPane(usesDesktopLayout), diff --git a/Application/Presentation/TodayTab/Sources/TodayView.swift b/Application/Presentation/TodayTab/Sources/TodayView.swift index f33b04dc..f71db173 100644 --- a/Application/Presentation/TodayTab/Sources/TodayView.swift +++ b/Application/Presentation/TodayTab/Sources/TodayView.swift @@ -42,7 +42,7 @@ public struct TodayView: View { let showsPane = store.showsDetailInPane && sections.flatMap(\.items).contains { $0.id == store.detail?.todoId } - PaneSplitView(splitsOnDesktop: showsPane) { + PaneSplitView { ScrollView { // 칸으로 나누지 않은 화면은 상세 칸이 없어 선택 표시 생략 let highlightedTodoIds = ( @@ -124,41 +124,34 @@ public struct TodayView: View { .background(Color.background) .refreshable { await store.send(.refresh).finish() } .duoToolbarVisibility() - } detail: { - // 목록에서 빠진 Todo는 선택 안내로 대체 - if showsPane, let detailStore = store.scope(state: \.detail, action: \.detail.presented) { + // 좁은 창은 목록 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 + // 목록에서 빠진 Todo는 오른쪽 칸에 그리지 않음 + // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 + .compositionDetail( + item: $store.scope(state: \.detail, action: \.detail), + inPane: showsPane, + isActive: isSelected + ) { detailStore, onClose in TodoDetailView( store: detailStore, windowEvent: windowEvent, - isPaneDetail: true, - onClose: { store.send(.detail(.dismiss)) } + isPaneDetail: onClose != nil, + onClose: onClose ) - .environment(\.showsPaneTitleBar, true) // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 .id(detailStore.todoId) - } else { - PanePlaceholder() + } panel: { detailStore in + // 목록에서 빠진 Todo는 오른쪽 칸에 그릴 수 없어 판 메뉴에서 오른쪽 칸으로 옮기기 생략 + let isListed = sections.flatMap(\.items).contains { $0.id == detailStore.todoId } + + TodoDetailPanel( + store: detailStore, + location: Text("nav_today", bundle: PresentationResources.bundle), + windowEvent: windowEvent, + onMoveToPane: isListed ? { store.send(.moveDetailToPane) } : nil + ) } } - // 좁은 창은 목록 위에 쌓고, 사이드바가 있는 창은 상세 판이나 오른쪽 칸에 표시 - // 창 폭이 바뀌면 같은 상세 상태를 바뀐 자리에서 이어 그림 - .compositionDetail( - item: $store.scope(state: \.detail, action: \.detail), - inPane: showsPane, - isActive: isSelected - ) { detailStore in - TodoDetailView(store: detailStore, windowEvent: windowEvent) - } panel: { detailStore in - // 목록에서 빠진 Todo는 오른쪽 칸에 그릴 수 없어 판 메뉴에서 오른쪽 칸으로 옮기기 생략 - let isListed = sections.flatMap(\.items).contains { $0.id == detailStore.todoId } - - TodoDetailPanel( - store: detailStore, - location: Text("nav_today", bundle: PresentationResources.bundle), - windowEvent: windowEvent, - onMoveToPane: isListed ? { store.send(.moveDetailToPane) } : nil - ) - } .compositionRight( isActive: sections.flatMap(\.items).contains { $0.id == store.selectedTodoId }, reveal: store.revealCount From ed3e4d048bb1e2e8211fd041d60b9440b349ef62 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 18/25] =?UTF-8?q?fix:=20=EC=84=B8=EB=B6=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=82=AC=EC=9D=B4=EB=93=9C=EB=B0=94=EC=99=80=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=B9=B8=20=EB=82=B4=EC=9A=A9=EC=9D=B4=20?= =?UTF-8?q?=EB=B0=94=EC=9D=B8=EB=94=A9=EC=9C=BC=EB=A1=9C=20=EC=9D=BD?= =?UTF-8?q?=EB=8A=94=20=ED=95=AD=EB=AA=A9=EC=9D=B4=20=EB=B0=94=EB=80=8C?= =?UTF-8?q?=EB=A9=B4=20=EB=8B=A4=EC=8B=9C=20=EA=B7=B8=EB=A6=AC=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Component/CompositionContainer.swift | 22 ++++++++++++------- .../Common/Component/DetailSideBar.swift | 15 ++++++++----- .../Common/Component/PaneSplitView.swift | 7 ++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift index 2f3e5c23..d471fc8e 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/CompositionContainer.swift @@ -159,7 +159,7 @@ private struct CompositionDetailModifier: View // 가려진 탭에서도 작성 중인 화면을 상세 칸에 그대로 두도록 isActive와 상관없이 올림 .transformPreference(PaneDetailContentPreferenceKey.self) { value in guard inPane, item.wrappedValue != nil else { return } - value = PaneDetailContent(id: id, isEditor: true) { + value = PaneDetailContent(id: id, isEditor: true, key: item.wrappedValue.map { AnyHashable($0.id) }) { AnyView(paneContent) } } @@ -329,13 +329,19 @@ private struct CompositionSheetModifier Content ) -> some View { - modifier(CompositionRightModifier(isActive: isActive, reveal: reveal, sideBarContent: content)) + modifier(CompositionRightModifier(isActive: isActive, reveal: reveal, key: nil, sideBarContent: content)) } } // 화면이 올린 세부 정보 사이드바 내용 -// 같은 화면이 올린 동안은 같은 값으로 보고, 내용이 읽는 상태가 바뀌면 이 View만 다시 그림 +// 같은 화면이 같은 항목을 올린 동안은 같은 값으로 보고, 내용이 읽는 상태가 바뀌면 이 View만 다시 그림 public struct DetailSideBarContent: View, Equatable { let id: UUID + // 내용이 바인딩으로 읽는 항목의 식별자 + // 그리는 중의 바인딩은 만든 때의 값을 돌려주므로 항목이 바뀌면 새 내용으로 보고 다시 전달 + let key: AnyHashable? let content: () -> AnyView public var body: some View { @@ -90,7 +93,7 @@ public struct DetailSideBarContent: View, Equatable { } public static func == (lhs: Self, rhs: Self) -> Bool { - lhs.id == rhs.id + lhs.id == rhs.id && lhs.key == rhs.key } } @@ -103,7 +106,7 @@ public struct DetailSideBarContentPreferenceKey: PreferenceKey { } } -private struct CompositionRightModifier: ViewModifier { +struct CompositionRightModifier: ViewModifier { @Environment(\.usesDesktopLayout) private var usesDesktopLayout @Environment(\.setDetailSideBarPresented) private var setDetailSideBarPresented @State private var id = UUID() @@ -111,6 +114,8 @@ private struct CompositionRightModifier: ViewModifier { @State private var isAppeared = false let isActive: Bool let reveal: Int + // 내용이 바인딩으로 읽는 항목의 식별자 + let key: AnyHashable? let sideBarContent: () -> SideBarContent func body(content: Content) -> some View { @@ -120,7 +125,7 @@ private struct CompositionRightModifier: ViewModifier { content .transformPreference(DetailSideBarContentPreferenceKey.self) { value in guard isShown, value == nil else { return } - value = DetailSideBarContent(id: id) { AnyView(sideBarContent()) } + value = DetailSideBarContent(id: id, key: key) { AnyView(sideBarContent()) } } .onAppear { isAppeared = true } .onDisappear { isAppeared = false } diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift index 4c45b94d..52a4ecb6 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/PaneSplitView.swift @@ -96,11 +96,14 @@ public struct PaneSplitView: View { } // 목록 칸 안의 수정자가 올린 상세 칸 내용 -// 같은 수정자가 올린 동안은 같은 값으로 보고, 내용이 읽는 상태가 바뀌면 이 View만 다시 그림 +// 같은 수정자가 같은 항목을 올린 동안은 같은 값으로 보고, 내용이 읽는 상태가 바뀌면 이 View만 다시 그림 struct PaneDetailContent: View, Equatable { let id: UUID // 저장이나 닫기 버튼으로만 닫는 작성 화면, 읽는 화면보다 먼저 표시 let isEditor: Bool + // 내용이 바인딩으로 읽는 항목의 식별자 + // 그리는 중의 바인딩은 만든 때의 값을 돌려주므로 항목이 바뀌면 새 내용으로 보고 다시 전달 + let key: AnyHashable? let content: () -> AnyView var body: some View { @@ -108,7 +111,7 @@ struct PaneDetailContent: View, Equatable { } static func == (lhs: Self, rhs: Self) -> Bool { - lhs.id == rhs.id && lhs.isEditor == rhs.isEditor + lhs.id == rhs.id && lhs.isEditor == rhs.isEditor && lhs.key == rhs.key } } From 6cc59501c1f4dac768bcdd99cb63b49650e7127f Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 19/25] =?UTF-8?q?refactor:=20SplitShell=20=ED=81=B4?= =?UTF-8?q?=EB=A1=9C=EC=A0=80=20=EC=88=9C=EC=84=9C=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EC=9A=B4=EB=8D=B0,=20=EC=99=BC=EC=AA=BD,=20=EC=98=A4=EB=A5=B8?= =?UTF-8?q?=EC=AA=BD=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Common/Component/SplitShell.swift | 10 ++--- .../Sources/Composition/CompositionView.swift | 38 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift index 9abe8094..ef39e198 100644 --- a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift +++ b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift @@ -8,24 +8,24 @@ import SwiftUI import PresentationShared -// 왼쪽, 가운데, 오른쪽 자리와 창 전체를 덮는 자리만 있는 껍데기 +// 가운데, 왼쪽, 오른쪽 자리와 창 전체를 덮는 자리만 있는 껍데기 // 자리마다 어떤 화면이 언제 나올지는 쓰는 쪽에서 결정 -struct SplitShell: View { +struct SplitShell: View { // 가운데 화면이 올린 세부 정보 사이드바 내용, 오른쪽 자리에 그릴지는 쓰는 쪽에서 결정 @State private var rightContent: DetailSideBarContent? - private let left: Left private let center: Center + private let left: Left private let right: (DetailSideBarContent?) -> Right private let overlay: Overlay init( - @ViewBuilder left: () -> Left, @ViewBuilder center: () -> Center, + @ViewBuilder left: () -> Left, @ViewBuilder right: @escaping (DetailSideBarContent?) -> Right, @ViewBuilder overlay: () -> Overlay ) { - self.left = left() self.center = center() + self.left = left() self.right = right self.overlay = overlay() } diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift index 2d7f2a54..2b07ff10 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift @@ -42,25 +42,6 @@ struct CompositionView: View { let visibleTab = !showsSideBar && store.isSettingsPresented ? AppTab.profile : selectedTab SplitShell { - if showsSideBar && !store.sideBar.isCollapsed { - // 최소는 화살표와 아이콘만 보이는 폭, Mac 최대는 Orca 사이드바와 같은 폭 - TreeSideBar( - store: store.scope(state: \.sideBar, action: \.sideBar), - selectedTab: selectedTab, - unreadPushCount: store.unreadPushCount.count - ) - .resizablePane( - width: store.sideBar.width, - minimumWidth: isiOSAppOnMac ? 72 * AdaptiveSize.boardScale : 84, - idealWidth: sideBarIdealWidth, - maximumWidth: isiOSAppOnMac ? 500 * AdaptiveSize.boardScale : 320 - ) { width in - store.send(.sideBar(.resized(width))) - } - // 칸 자르기 밖이라 잘리지 않도록 바탕은 칸 바깥에서 아래쪽 안전 영역까지 채움 - .background(Color.secondaryBackground, ignoresSafeAreaEdges: .bottom) - } - } center: { ZStack { // iPad는 시스템 탭 바를 쓰지 않아 Mac과 같이 구성 // 넓은 창과 좁은 창을 오가도 탭 화면을 다시 만들지 않음 @@ -124,6 +105,25 @@ struct CompositionView: View { \.setDetailSideBarPresented, showsSideBar ? { store.send(.detailSideBar(.binding(.set(\.isPresented, $0)))) } : nil ) + } left: { + if showsSideBar && !store.sideBar.isCollapsed { + // 최소는 화살표와 아이콘만 보이는 폭, Mac 최대는 Orca 사이드바와 같은 폭 + TreeSideBar( + store: store.scope(state: \.sideBar, action: \.sideBar), + selectedTab: selectedTab, + unreadPushCount: store.unreadPushCount.count + ) + .resizablePane( + width: store.sideBar.width, + minimumWidth: isiOSAppOnMac ? 72 * AdaptiveSize.boardScale : 84, + idealWidth: sideBarIdealWidth, + maximumWidth: isiOSAppOnMac ? 500 * AdaptiveSize.boardScale : 320 + ) { width in + store.send(.sideBar(.resized(width))) + } + // 칸 자르기 밖이라 잘리지 않도록 바탕은 칸 바깥에서 아래쪽 안전 영역까지 채움 + .background(Color.secondaryBackground, ignoresSafeAreaEdges: .bottom) + } } right: { content in // 탭 화면이 올린 내용, 올린 내용이 없으면 안내 표시 if showsSideBar && store.detailSideBar.isPresented { From fcfbee96c22646f406dd0f27f45766623ebd5839 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 20/25] =?UTF-8?q?refactor:=20=EC=99=BC=EC=AA=BD=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=EB=93=9C=EB=B0=94=EB=A5=BC=20=EC=BC=9C?= =?UTF-8?q?=EA=B3=A0=20=EB=81=84=EB=8A=94=20=EC=83=81=ED=83=9C=EB=A5=BC=20?= =?UTF-8?q?SplitShell=EC=9D=B4=20=EB=B3=B4=EA=B4=80=ED=95=98=EA=B3=A0=20le?= =?UTF-8?q?ft=20=ED=81=B4=EB=A1=9C=EC=A0=80=EA=B0=80=20=ED=91=9C=EC=8B=9C?= =?UTF-8?q?=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20=EA=B5=AC=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Common/Component/SplitShell.swift | 29 ++++++++---- .../Sources/Composition/CompositionView.swift | 45 ++++++++----------- .../Sources/Composition/SideBarFeature.swift | 1 - .../Sources/Composition/TreeSideBar.swift | 4 +- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift index ef39e198..1a528a04 100644 --- a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift +++ b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift @@ -11,34 +11,47 @@ import PresentationShared // 가운데, 왼쪽, 오른쪽 자리와 창 전체를 덮는 자리만 있는 껍데기 // 자리마다 어떤 화면이 언제 나올지는 쓰는 쪽에서 결정 struct SplitShell: View { + // 왼쪽 자리를 켜 둔 상태, 켜고 끄는 바인딩으로 가운데와 왼쪽 클로저에 넘김 + @State private var isLeftOn = true // 가운데 화면이 올린 세부 정보 사이드바 내용, 오른쪽 자리에 그릴지는 쓰는 쪽에서 결정 @State private var rightContent: DetailSideBarContent? - private let center: Center - private let left: Left + // 이 폭보다 좁아지면 왼쪽 자리를 끄고 넓어지면 켬, 없으면 창 폭으로 바꾸지 않음 + private let leftFitWidth: CGFloat? + private let center: (Binding) -> Center + private let left: (Binding) -> Left private let right: (DetailSideBarContent?) -> Right private let overlay: Overlay init( - @ViewBuilder center: () -> Center, - @ViewBuilder left: () -> Left, + leftFitWidth: CGFloat? = nil, + @ViewBuilder center: @escaping (Binding) -> Center, + @ViewBuilder left: @escaping (Binding) -> Left, @ViewBuilder right: @escaping (DetailSideBarContent?) -> Right, @ViewBuilder overlay: () -> Overlay ) { - self.center = center() - self.left = left() + self.leftFitWidth = leftFitWidth + self.center = center + self.left = left self.right = right self.overlay = overlay() } var body: some View { HStack(spacing: 0) { - left - center + left($isLeftOn) + center($isLeftOn) .onPreferenceChange(DetailSideBarContentPreferenceKey.self) { content in rightContent = content } right(rightContent) } .overlay { overlay } + .onGeometryChange(for: Bool?.self) { proxy in + leftFitWidth.map { $0 <= proxy.size.width } + } action: { fits in + if let fits { + isLeftOn = fits + } + } } } diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift index 2b07ff10..067adc0c 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift @@ -41,7 +41,9 @@ struct CompositionView: View { // 사이드바가 있는 창에서 연 설정은 좁아지면 고른 탭을 바꾸지 않고 프로필 화면에 이어서 표시 let visibleTab = !showsSideBar && store.isSettingsPresented ? AppTab.profile : selectedTab - SplitShell { + // iPad는 사이드바를 펴면 목록 칸과 상세 칸이 함께 들어가지 않는 창에서 사이드바를 접고 시작 + // 세로 화면처럼 좁은 창에서 상세 칸이 잘리지 않게 함 + SplitShell(leftFitWidth: isiOSAppOnMac ? nil : splitMinimumWidth + sideBarIdealWidth) { $isSideBarOn in ZStack { // iPad는 시스템 탭 바를 쓰지 않아 Mac과 같이 구성 // 넓은 창과 좁은 창을 오가도 탭 화면을 다시 만들지 않음 @@ -91,10 +93,7 @@ struct CompositionView: View { } } // 접은 사이드바는 화면 칸 제목 줄의 버튼으로 다시 폄 - .environment( - \.expandSideBar, - store.sideBar.isCollapsed ? { store.send(.sideBar(.binding(.set(\.isCollapsed, false)))) } : nil - ) + .environment(\.expandSideBar, isSideBarOn ? nil : { isSideBarOn = true }) // 닫힌 세부 정보 사이드바는 화면 칸 제목 줄의 버튼으로 엶 .environment( \.showDetailSideBar, @@ -105,24 +104,26 @@ struct CompositionView: View { \.setDetailSideBarPresented, showsSideBar ? { store.send(.detailSideBar(.binding(.set(\.isPresented, $0)))) } : nil ) - } left: { - if showsSideBar && !store.sideBar.isCollapsed { + } left: { $isSideBarOn in + if showsSideBar && isSideBarOn { // 최소는 화살표와 아이콘만 보이는 폭, Mac 최대는 Orca 사이드바와 같은 폭 TreeSideBar( store: store.scope(state: \.sideBar, action: \.sideBar), selectedTab: selectedTab, unreadPushCount: store.unreadPushCount.count - ) - .resizablePane( - width: store.sideBar.width, - minimumWidth: isiOSAppOnMac ? 72 * AdaptiveSize.boardScale : 84, - idealWidth: sideBarIdealWidth, - maximumWidth: isiOSAppOnMac ? 500 * AdaptiveSize.boardScale : 320 - ) { width in - store.send(.sideBar(.resized(width))) - } - // 칸 자르기 밖이라 잘리지 않도록 바탕은 칸 바깥에서 아래쪽 안전 영역까지 채움 - .background(Color.secondaryBackground, ignoresSafeAreaEdges: .bottom) + ) { + isSideBarOn = false + } + .resizablePane( + width: store.sideBar.width, + minimumWidth: isiOSAppOnMac ? 72 * AdaptiveSize.boardScale : 84, + idealWidth: sideBarIdealWidth, + maximumWidth: isiOSAppOnMac ? 500 * AdaptiveSize.boardScale : 320 + ) { width in + store.send(.sideBar(.resized(width))) + } + // 칸 자르기 밖이라 잘리지 않도록 바탕은 칸 바깥에서 아래쪽 안전 영역까지 채움 + .background(Color.secondaryBackground, ignoresSafeAreaEdges: .bottom) } } right: { content in // 탭 화면이 올린 내용, 올린 내용이 없으면 안내 표시 @@ -178,14 +179,6 @@ struct CompositionView: View { } // Mac 창에서 상태 표시줄 자리로 비워 두는 상단 여백 제거 .statusBarHidden(isiOSAppOnMac) - // iPad는 사이드바를 펴면 목록 칸과 상세 칸이 함께 들어가지 않는 창에서 사이드바를 접고 시작 - // 세로 화면처럼 좁은 창에서 상세 칸이 잘리지 않게 함 - .onGeometryChange(for: Bool.self) { proxy in - splitMinimumWidth + sideBarIdealWidth <= proxy.size.width - } action: { fitsSideBar in - guard !isiOSAppOnMac else { return } - store.send(.sideBar(.binding(.set(\.isCollapsed, !fitsSideBar)))) - } .onGeometryChange(for: CGFloat.self) { proxy in proxy.windowControlsInset } action: { inset in diff --git a/Application/Presentation/Entry/Sources/Composition/SideBarFeature.swift b/Application/Presentation/Entry/Sources/Composition/SideBarFeature.swift index 62822146..d97b8f74 100644 --- a/Application/Presentation/Entry/Sources/Composition/SideBarFeature.swift +++ b/Application/Presentation/Entry/Sources/Composition/SideBarFeature.swift @@ -18,7 +18,6 @@ struct SideBarFeature { @ObservableState struct State: Equatable { - var isCollapsed = false // 사용자가 끌어서 정한 폭, 정하지 않았으면 기본 폭 var width: CGFloat? var expandedGroups: Set = [] diff --git a/Application/Presentation/Entry/Sources/Composition/TreeSideBar.swift b/Application/Presentation/Entry/Sources/Composition/TreeSideBar.swift index e489874d..405cc031 100644 --- a/Application/Presentation/Entry/Sources/Composition/TreeSideBar.swift +++ b/Application/Presentation/Entry/Sources/Composition/TreeSideBar.swift @@ -15,13 +15,15 @@ struct TreeSideBar: View { let store: StoreOf let selectedTab: AppTab let unreadPushCount: Int + // 사이드바를 접는 동작 + let onCollapse: () -> Void var body: some View { let location = store.locations[selectedTab] ?? selectedTab.sideBarLocation let expandedGroups = store.expandedGroups let isCompact = (paneWidth ?? .infinity) < SideBarRow.compactWidth let collapseButton = Button { - store.send(.binding(.set(\.isCollapsed, true))) + onCollapse() } label: { Image(systemName: "sidebar.left") } From bfe212b5ea2972da94a4f494020f1a2344f6cd48 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:24:40 +0900 Subject: [PATCH 21/25] =?UTF-8?q?refactor:=20=EC=84=B8=EB=B6=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=82=AC=EC=9D=B4=EB=93=9C=EB=B0=94?= =?UTF-8?q?=EB=A5=BC=20=EC=BC=9C=EA=B3=A0=20=EB=81=84=EB=8A=94=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=A5=BC=20SplitShell=EC=9D=B4=20=EB=B3=B4=EA=B4=80?= =?UTF-8?q?=ED=95=98=EA=B3=A0=20DetailSideBarFeature=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Common/Component/SplitShell.swift | 14 ++++++----- .../Composition/CompositionFeature.swift | 7 +----- .../Sources/Composition/CompositionView.swift | 19 +++++--------- .../Composition/DetailSideBarFeature.swift | 25 ------------------- 4 files changed, 15 insertions(+), 50 deletions(-) delete mode 100644 Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift diff --git a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift index 1a528a04..e47ada70 100644 --- a/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift +++ b/Application/Presentation/Entry/Sources/Common/Component/SplitShell.swift @@ -13,20 +13,22 @@ import PresentationShared struct SplitShell: View { // 왼쪽 자리를 켜 둔 상태, 켜고 끄는 바인딩으로 가운데와 왼쪽 클로저에 넘김 @State private var isLeftOn = true + // 오른쪽 자리를 켜 둔 상태, 켜고 끄는 바인딩으로 가운데와 오른쪽 클로저에 넘김 + @State private var isRightOn = false // 가운데 화면이 올린 세부 정보 사이드바 내용, 오른쪽 자리에 그릴지는 쓰는 쪽에서 결정 @State private var rightContent: DetailSideBarContent? // 이 폭보다 좁아지면 왼쪽 자리를 끄고 넓어지면 켬, 없으면 창 폭으로 바꾸지 않음 private let leftFitWidth: CGFloat? - private let center: (Binding) -> Center + private let center: (_ isLeftOn: Binding, _ isRightOn: Binding) -> Center private let left: (Binding) -> Left - private let right: (DetailSideBarContent?) -> Right + private let right: (DetailSideBarContent?, Binding) -> Right private let overlay: Overlay init( leftFitWidth: CGFloat? = nil, - @ViewBuilder center: @escaping (Binding) -> Center, + @ViewBuilder center: @escaping (_ isLeftOn: Binding, _ isRightOn: Binding) -> Center, @ViewBuilder left: @escaping (Binding) -> Left, - @ViewBuilder right: @escaping (DetailSideBarContent?) -> Right, + @ViewBuilder right: @escaping (DetailSideBarContent?, Binding) -> Right, @ViewBuilder overlay: () -> Overlay ) { self.leftFitWidth = leftFitWidth @@ -39,11 +41,11 @@ struct SplitShell: View { var body: some View { HStack(spacing: 0) { left($isLeftOn) - center($isLeftOn) + center($isLeftOn, $isRightOn) .onPreferenceChange(DetailSideBarContentPreferenceKey.self) { content in rightContent = content } - right(rightContent) + right(rightContent, $isRightOn) } .overlay { overlay } .onGeometryChange(for: Bool?.self) { proxy in diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift b/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift index d3003f0d..392cd2ec 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionFeature.swift @@ -31,7 +31,6 @@ struct CompositionFeature { // 앱 화면과 분리해 창 전체에 표시하는 설정 화면, 좁아진 창에서는 프로필 화면에 이어서 표시 var isSettingsPresented = false var sideBar = SideBarFeature.State() - var detailSideBar = DetailSideBarFeature.State() var unreadPushCount = UnreadPushCountFeature.State() // 창 폭이 바뀌어도 보던 항목과 진행 중인 로그아웃, 회원 탈퇴를 이어 가게 화면보다 위에서 보관 var settings = SettingsFeature.State() @@ -54,7 +53,6 @@ struct CompositionFeature { case selectTab(AppTab) case view(ViewAction) case sideBar(SideBarFeature.Action) - case detailSideBar(DetailSideBarFeature.Action) case unreadPushCount(UnreadPushCountFeature.Action) case settings(SettingsFeature.Action) case store(StoreAction) @@ -80,9 +78,6 @@ struct CompositionFeature { Scope(state: \.sideBar, action: \.sideBar) { SideBarFeature() } - Scope(state: \.detailSideBar, action: \.detailSideBar) { - DetailSideBarFeature() - } Scope(state: \.unreadPushCount, action: \.unreadPushCount) { UnreadPushCountFeature() } @@ -111,7 +106,7 @@ struct CompositionFeature { return selectTabEffect(tab, state: &state) case .sideBar(.tapSettings): return .send(.settings(.open)) - case .sideBar, .detailSideBar, .unreadPushCount: + case .sideBar, .unreadPushCount: break case .settings(.open): state.isSettingsPresented = true diff --git a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift index 067adc0c..497bd303 100644 --- a/Application/Presentation/Entry/Sources/Composition/CompositionView.swift +++ b/Application/Presentation/Entry/Sources/Composition/CompositionView.swift @@ -43,7 +43,7 @@ struct CompositionView: View { // iPad는 사이드바를 펴면 목록 칸과 상세 칸이 함께 들어가지 않는 창에서 사이드바를 접고 시작 // 세로 화면처럼 좁은 창에서 상세 칸이 잘리지 않게 함 - SplitShell(leftFitWidth: isiOSAppOnMac ? nil : splitMinimumWidth + sideBarIdealWidth) { $isSideBarOn in + SplitShell(leftFitWidth: isiOSAppOnMac ? nil : splitMinimumWidth + sideBarIdealWidth) { $isSideBarOn, $isDetailSideBarOn in ZStack { // iPad는 시스템 탭 바를 쓰지 않아 Mac과 같이 구성 // 넓은 창과 좁은 창을 오가도 탭 화면을 다시 만들지 않음 @@ -95,15 +95,8 @@ struct CompositionView: View { // 접은 사이드바는 화면 칸 제목 줄의 버튼으로 다시 폄 .environment(\.expandSideBar, isSideBarOn ? nil : { isSideBarOn = true }) // 닫힌 세부 정보 사이드바는 화면 칸 제목 줄의 버튼으로 엶 - .environment( - \.showDetailSideBar, - showsSideBar && !store.detailSideBar.isPresented - ? { store.send(.detailSideBar(.binding(.set(\.isPresented, true)))) } : nil - ) - .environment( - \.setDetailSideBarPresented, - showsSideBar ? { store.send(.detailSideBar(.binding(.set(\.isPresented, $0)))) } : nil - ) + .environment(\.showDetailSideBar, showsSideBar && !isDetailSideBarOn ? { isDetailSideBarOn = true } : nil) + .environment(\.setDetailSideBarPresented, showsSideBar ? { isDetailSideBarOn = $0 } : nil) } left: { $isSideBarOn in if showsSideBar && isSideBarOn { // 최소는 화살표와 아이콘만 보이는 폭, Mac 최대는 Orca 사이드바와 같은 폭 @@ -125,11 +118,11 @@ struct CompositionView: View { // 칸 자르기 밖이라 잘리지 않도록 바탕은 칸 바깥에서 아래쪽 안전 영역까지 채움 .background(Color.secondaryBackground, ignoresSafeAreaEdges: .bottom) } - } right: { content in + } right: { content, $isDetailSideBarOn in // 탭 화면이 올린 내용, 올린 내용이 없으면 안내 표시 - if showsSideBar && store.detailSideBar.isPresented { + if showsSideBar && isDetailSideBarOn { DetailSideBar { - store.send(.detailSideBar(.binding(.set(\.isPresented, false)))) + isDetailSideBarOn = false } content: { if let content { content diff --git a/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift b/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift deleted file mode 100644 index efd0c4f5..00000000 --- a/Application/Presentation/Entry/Sources/Composition/DetailSideBarFeature.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// DetailSideBarFeature.swift -// Entry -// -// Created by opfic on 11/25/26. -// - -import Foundation -import PresentationShared - -@Reducer -struct DetailSideBarFeature { - @ObservableState - struct State: Equatable { - var isPresented = false - } - - enum Action: BindableAction, Equatable { - case binding(BindingAction) - } - - var body: some ReducerOf { - BindingReducer() - } -} From 077e64cf41cc024090f7b83fd8119a47350028e6 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:54:21 +0900 Subject: [PATCH 22/25] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=98=A4=EB=A5=B8=EC=AA=BD=20=EC=B9=B8=EA=B3=BC=20=EC=84=B8?= =?UTF-8?q?=EB=B6=80=20=EC=A0=95=EB=B3=B4=20=EC=82=AC=EC=9D=B4=EB=93=9C?= =?UTF-8?q?=EB=B0=94=EA=B0=80=20=EA=B0=99=EC=9D=80=20Todo=EC=9D=98=20?= =?UTF-8?q?=ED=8E=B8=EC=A7=91=20=EA=B0=80=EB=8A=A5=20=EC=97=AC=EB=B6=80?= =?UTF-8?q?=EA=B0=80=20=EB=B0=94=EB=80=8C=EB=A9=B4=20=EB=8B=A4=EC=8B=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileTab/Sources/Profile/ProfileView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift index e8de54d9..e86897b8 100644 --- a/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift +++ b/Application/Presentation/ProfileTab/Sources/Profile/ProfileView.swift @@ -81,8 +81,8 @@ public struct ProfileView: View { isPaneDetail: onClose != nil, onClose: onClose ) - // 칸 안에서 다른 Todo로 바꾸면 그 Todo를 조회 - .id(detailStore.todoId) + // 칸 안에서 다른 Todo로 바꾸거나 같은 Todo를 다른 목록에서 다시 고르면 그 Todo를 조회 + .id([AnyHashable(detailStore.todoId), detailStore.showEditButton]) } panel: { detailStore in TodoDetailPanel( store: detailStore, @@ -101,7 +101,8 @@ public struct ProfileView: View { isEditable: detail.showEditButton, windowEvent: windowEvent ) - .id(detail.todoId) + // 같은 Todo도 편집할 수 있는지가 바뀌면 다시 만듦 + .id([AnyHashable(detail.todoId), detail.showEditButton]) } } // 좁은 창은 설정 목록과 고른 항목 화면을 프로필 위에 쌓고, 사이드바가 있는 창은 창 전체 설정 화면에 그려 쌓지 않음 From 0ef53d3fd9efd7984446cf7687eab9851cee9380 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:54:21 +0900 Subject: [PATCH 23/25] =?UTF-8?q?test:=20ProfileFeature=EC=9D=98=20?= =?UTF-8?q?=EA=B3=A0=EB=A5=B8=20Todo=20=EC=83=81=EC=84=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A5=BC=20ProfileFeatureTests=20=EC=95=88?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tests/Profile/ProfileFeatureTests.swift | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift b/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift index 9084aa4a..754b0741 100644 --- a/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift +++ b/Application/Presentation/ProfileTab/Tests/Profile/ProfileFeatureTests.swift @@ -223,6 +223,28 @@ struct ProfileFeatureTests { #expect(adapter.selectedActivityKinds == [.created]) #expect(spy.activityTypes.isEmpty) } + + @Test("ProfileFeature는 고른 Todo를 연 자리에서 바꾸고, 상세를 닫으면 오른쪽 칸 표시도 끈다") + func ProfileFeature는_고른_Todo를_연_자리에서_바꾸고_상세를_닫으면_오른쪽_칸_표시도_끈다() async { + let store = TestStore(initialState: ProfileFeature.State()) { + ProfileFeature() + } + + await store.send(.selectTodo("activity", isEditable: false)) { + $0.detail = TodoDetailFeature.State(todoId: "activity", showEditButton: false) + } + await store.send(.binding(.set(\.showsDetailInPane, true))) { + $0.showsDetailInPane = true + } + // 같은 Todo도 최근 Todo에서 고르면 편집할 수 있는 상세로 바꿈 + await store.send(.selectTodo("activity", isEditable: true)) { + $0.detail = TodoDetailFeature.State(todoId: "activity", showEditButton: true) + } + await store.send(.detail(.dismiss)) { + $0.detail = nil + $0.showsDetailInPane = false + } + } } private final class FetchTodosUseCaseSpy: FetchTodosUseCase { @@ -317,28 +339,6 @@ private final class UpdateHeatmapActivityTypesUseCaseSpy: UpdateHeatmapActivityT func execute(_ activityTypes: [String]) { self.activityTypes.append(activityTypes) } - - @Test("ProfileFeature는 고른 Todo를 연 자리에서 바꾸고, 상세를 닫으면 오른쪽 칸 표시도 끈다") - func ProfileFeature는_고른_Todo를_연_자리에서_바꾸고_상세를_닫으면_오른쪽_칸_표시도_끈다() async { - let store = TestStore(initialState: ProfileFeature.State()) { - ProfileFeature() - } - - await store.send(.selectTodo("activity", isEditable: false)) { - $0.detail = TodoDetailFeature.State(todoId: "activity", showEditButton: false) - } - await store.send(.binding(.set(\.showsDetailInPane, true))) { - $0.showsDetailInPane = true - } - // 같은 Todo도 최근 Todo에서 고르면 편집할 수 있는 상세로 바꿈 - await store.send(.selectTodo("activity", isEditable: true)) { - $0.detail = TodoDetailFeature.State(todoId: "activity", showEditButton: true) - } - await store.send(.detail(.dismiss)) { - $0.detail = nil - $0.showsDetailInPane = false - } - } } @MainActor From e782fcbb0610605667eff380e2c53ae9ea7b7ec9 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:54:21 +0900 Subject: [PATCH 24/25] =?UTF-8?q?fix:=20=EC=9C=84=EC=A0=AF=EA=B3=BC=20?= =?UTF-8?q?=ED=91=B8=EC=8B=9C=20=EC=95=8C=EB=A6=BC=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=97=B0=20Todo=20=EC=8B=9C=ED=8A=B8=EA=B0=80=20=EB=8B=A4?= =?UTF-8?q?=EB=A5=B8=20Todo=EB=A1=9C=20=EB=B0=94=EB=80=8C=EB=A9=B4=20?= =?UTF-8?q?=EA=B7=B8=20Todo=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Presentation/Entry/Sources/Root/RootView.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Application/Presentation/Entry/Sources/Root/RootView.swift b/Application/Presentation/Entry/Sources/Root/RootView.swift index b0a3dcda..63ad57a0 100644 --- a/Application/Presentation/Entry/Sources/Root/RootView.swift +++ b/Application/Presentation/Entry/Sources/Root/RootView.swift @@ -51,6 +51,8 @@ public struct RootView: View { NavigationStack { TodoDetailView(store: sheetStore) } + // 시트가 떠 있는 동안 다른 Todo를 열면 화면을 다시 만들어 그 Todo를 조회 + .id(sheetStore.todoId) .environment(\.deviceType, .bar) .background(Color.background) } From 9b516b1c1a8f302ae2d798439020d5318b48ee94 Mon Sep 17 00:00:00 2001 From: opficdev Date: Sat, 28 Nov 2026 14:54:22 +0900 Subject: [PATCH 25/25] =?UTF-8?q?fix:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EA=B4=80=EB=A6=AC=EC=97=90=EC=84=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=EB=B0=94=EB=A1=9C=20=EA=B0=9C=EB=B0=9C=20?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=EB=A5=BC=20=EC=97=B4=EC=96=B4=EB=8F=84=20?= =?UTF-8?q?=EC=84=B8=EB=B6=80=20=EC=A0=95=EB=B3=B4=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EB=93=9C=EB=B0=94=EA=B0=80=20=EB=8B=AB=ED=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HomeTab/Sources/Home/HomeView.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index 4f3d37fd..f2875f73 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -41,7 +41,16 @@ public struct HomeView: View { GoalCreateSideBarContent(store: goalStore) } } + // 좁은 창은 개발 목표를 홈 내비게이션에 쌓고, 넓어지면 같은 상태를 홈 자리에 표시하고 기록 작성은 오른쪽 칸에 표시 + .compositionCenter( + item: $store.scope(state: \.goalDetail, action: \.goalDetail), + narrow: .push + ) { goalStore in + GoalDetailView(store: goalStore, windowEvent: windowEvent) + .id(goalStore.goalId) + } // 사이드바가 있으면 카테고리 관리를 시트 대신 홈 자리에 표시 + // 사이드바에서 개발 목표를 열어 개발 목표 화면으로 바뀌어도 닫힘을 받아 세부 정보 사이드바를 닫도록 개발 목표 바깥에 둠 .compositionCenter( item: $store.scope(state: \.categoryManage, action: \.categoryManage), narrow: .sheet, @@ -52,14 +61,6 @@ public struct HomeView: View { store.send(.categoryManage(.dismiss)) } } - // 좁은 창은 개발 목표를 홈 내비게이션에 쌓고, 넓어지면 같은 상태를 홈 자리에 표시하고 기록 작성은 오른쪽 칸에 표시 - .compositionCenter( - item: $store.scope(state: \.goalDetail, action: \.goalDetail), - narrow: .push - ) { goalStore in - GoalDetailView(store: goalStore, windowEvent: windowEvent) - .id(goalStore.goalId) - } } destination: { pathStore in Group { switch pathStore.case {