diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift index 88f169c7..ea5b99a8 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift @@ -114,8 +114,11 @@ private struct ContainerModifier: ViewModifier { func body(content: Content) -> some View { debugChanges() return content - .themeProgress(if: !profileManager.isReady) - .themeEmptyContent(if: profileManager.isReady && !profileManager.hasProfiles, message: Strings.Views.Profiles.Folders.noProfiles) + .themeProgress( + if: !profileManager.isReady, + isEmpty: !profileManager.hasProfiles, + emptyMessage: Strings.Views.Profiles.Folders.noProfiles + ) .searchable(text: $search) .onChange(of: search) { profileManager.search(byName: $0) diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Migration/MigrateView.swift b/Passepartout/Library/Sources/AppUIMain/Views/Migration/MigrateView.swift index e8767dce..874c6bf9 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Migration/MigrateView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Migration/MigrateView.swift @@ -65,8 +65,11 @@ struct MigrateView: View { .disabled(model.step != .fetched) } .themeForm() - .themeProgress(if: model.step == .fetching) - .themeEmptyContent(if: model.step == .fetched && model.profiles.isEmpty, message: "Nothing to migrate") + .themeProgress( + if: model.step == .fetching, + isEmpty: model.profiles.isEmpty, + emptyMessage: "Nothing to migrate" + ) .themeAnimation(on: model, category: .profiles) .navigationTitle(title) .toolbar(content: toolbarContent) diff --git a/Passepartout/Library/Sources/UILibrary/Extensions/View+Environment.swift b/Passepartout/Library/Sources/UILibrary/Extensions/View+Environment.swift index 8605dbb7..9bca78c0 100644 --- a/Passepartout/Library/Sources/UILibrary/Extensions/View+Environment.swift +++ b/Passepartout/Library/Sources/UILibrary/Extensions/View+Environment.swift @@ -35,6 +35,9 @@ extension View { } public func withMockEnvironment() -> some View { - withEnvironment(from: .mock, theme: Theme()) + task { + try? await AppContext.mock.profileManager.observeLocal() + } + .withEnvironment(from: .mock, theme: Theme()) } } diff --git a/Passepartout/Library/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift b/Passepartout/Library/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift index d894f694..ed0d5089 100644 --- a/Passepartout/Library/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift +++ b/Passepartout/Library/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift @@ -163,8 +163,8 @@ extension View { modifier(ThemeProgressViewModifier(isProgressing: isProgressing)) } - public func themeEmptyContent(if isEmpty: Bool, message: String) -> some View { - modifier(ThemeEmptyContentModifier(isEmpty: isEmpty, message: message)) + public func themeProgress(if isProgressing: Bool, isEmpty: Bool, emptyMessage: String) -> some View { + modifier(ThemeProgressViewModifier(isProgressing: isProgressing, isEmpty: isEmpty, emptyMessage: emptyMessage)) } #if !os(tvOS) @@ -370,31 +370,20 @@ struct ThemeAnimationModifier: ViewModifier where T: Equatable { struct ThemeProgressViewModifier: ViewModifier { let isProgressing: Bool + var isEmpty: Bool? + + var emptyMessage: String? + func body(content: Content) -> some View { ZStack { + content + .opaque(!isProgressing && isEmpty != true) + if isProgressing { ThemeProgressView() - } - content - .opaque(!isProgressing) - } - } -} - -struct ThemeEmptyContentModifier: ViewModifier { - let isEmpty: Bool - - let message: String - - func body(content: Content) -> some View { - ZStack { - content - .opaque(!isEmpty) - - if isEmpty { - Text(message) + } else if let isEmpty, let emptyMessage, isEmpty { + Text(emptyMessage) .themeEmptyMessage() - .opaque(isEmpty) } } }