mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-22 11:03:21 -04:00
Reduce Welcome view
This commit is contained in:
parent
d94c862110
commit
79589e74bf
@ -222,12 +222,15 @@ private struct CompactView: View {
|
||||
|
||||
private struct Content<LaunchModel>: View where LaunchModel: LaunchProtocol {
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
@EnvironmentObject private var browser: BrowserViewModel
|
||||
@EnvironmentObject private var library: LibraryViewModel
|
||||
@EnvironmentObject private var navigation: NavigationViewModel
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \ZimFile.size, ascending: false)],
|
||||
predicate: ZimFile.openedPredicate
|
||||
) private var zimFiles: FetchedResults<ZimFile>
|
||||
|
||||
/// this is still hacky a bit, as the change from here re-validates the view
|
||||
/// which triggers the model to be revalidated
|
||||
@Default(.hasSeenCategories) private var hasSeenCategories
|
||||
@ -258,7 +261,7 @@ private struct Content<LaunchModel>: View where LaunchModel: LaunchProtocol {
|
||||
case .list:
|
||||
LocalLibraryList()
|
||||
case .welcome(let welcomeViewState):
|
||||
WelcomeCatalog(viewState: welcomeViewState, showLibrary: showLibrary)
|
||||
WelcomeCatalog(viewState: welcomeViewState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -269,10 +272,6 @@ private struct Content<LaunchModel>: View where LaunchModel: LaunchProtocol {
|
||||
.onAppear {
|
||||
browser.updateLastOpened()
|
||||
}
|
||||
.task {
|
||||
debugPrint("library: \(library)")
|
||||
debugPrint("")
|
||||
}
|
||||
.onDisappear {
|
||||
// since the browser is comming from @Environment,
|
||||
// by the time we get to .onDisappear,
|
||||
@ -298,6 +297,22 @@ private struct Content<LaunchModel>: View where LaunchModel: LaunchProtocol {
|
||||
browser.refreshVideoState()
|
||||
}
|
||||
}
|
||||
.onChange(of: library.state) { state in
|
||||
guard state == .complete else { return }
|
||||
showTheLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
private func showTheLibrary() {
|
||||
#if os(macOS)
|
||||
navigation.currentItem = .categories
|
||||
#else
|
||||
if horizontalSizeClass == .regular {
|
||||
navigation.currentItem = .categories
|
||||
} else {
|
||||
showLibrary()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -87,7 +87,10 @@ struct BrowserTab: View {
|
||||
|
||||
private struct Content<LaunchModel>: View where LaunchModel: LaunchProtocol {
|
||||
@Environment(\.isSearching) private var isSearching
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
@EnvironmentObject private var browser: BrowserViewModel
|
||||
@EnvironmentObject private var library: LibraryViewModel
|
||||
@EnvironmentObject private var navigation: NavigationViewModel
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \ZimFile.size, ascending: false)],
|
||||
predicate: ZimFile.openedPredicate
|
||||
@ -135,11 +138,19 @@ struct BrowserTab: View {
|
||||
case .catalog(.list):
|
||||
LocalLibraryList()
|
||||
case .catalog(.welcome(let welcomeViewState)):
|
||||
WelcomeCatalog(viewState: welcomeViewState, showLibrary: nil)
|
||||
WelcomeCatalog(viewState: welcomeViewState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: library.state) { state in
|
||||
guard state == .complete else { return }
|
||||
showTheLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
private func showTheLibrary() {
|
||||
navigation.currentItem = .categories
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import SwiftUI
|
||||
import Combine
|
||||
import Defaults
|
||||
|
||||
/// Displays a grid of available local ZIM files. Used on new tab.
|
||||
struct LocalLibraryList: View {
|
||||
@EnvironmentObject private var browser: BrowserViewModel
|
||||
@FetchRequest(
|
||||
|
@ -17,17 +17,14 @@ import SwiftUI
|
||||
import Combine
|
||||
import Defaults
|
||||
|
||||
/// Displays the Logo and 2 buttons open file | fetch catalog.
|
||||
/// Used on new tab, when no ZIM files are available
|
||||
struct WelcomeCatalog: View {
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
@EnvironmentObject private var navigation: NavigationViewModel
|
||||
@EnvironmentObject private var library: LibraryViewModel
|
||||
@Default(.hasSeenCategories) private var hasSeenCategories
|
||||
let viewState: WelcomeViewState
|
||||
|
||||
/// Used only for iPhone
|
||||
let showLibrary: (() -> Void)?
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
LogoView()
|
||||
@ -48,21 +45,6 @@ struct WelcomeCatalog: View {
|
||||
x: geometry.size.width * 0.5,
|
||||
y: logoCalc.buttonCenterY)
|
||||
.frame(maxWidth: logoCalc.buttonsWidth)
|
||||
.onChange(of: library.state) { state in
|
||||
if state == .error {
|
||||
hasSeenCategories = true
|
||||
}
|
||||
guard state == .complete else { return }
|
||||
#if os(macOS)
|
||||
navigation.currentItem = .categories
|
||||
#elseif os(iOS)
|
||||
if horizontalSizeClass == .regular {
|
||||
navigation.currentItem = .categories
|
||||
} else {
|
||||
showLibrary?()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if viewState == .error {
|
||||
Text("library_refresh_error.retrieve.description".localized)
|
||||
.foregroundColor(.red)
|
||||
@ -107,7 +89,7 @@ struct WelcomeCatalog: View {
|
||||
} label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
if library.state == .inProgress {
|
||||
if viewState == .loading {
|
||||
Text("welcome.button.status.fetching_catalog.text".localized)
|
||||
} else {
|
||||
Text("welcome.button.status.fetch_catalog.text".localized)
|
||||
@ -115,60 +97,15 @@ struct WelcomeCatalog: View {
|
||||
Spacer()
|
||||
}.padding(6)
|
||||
}
|
||||
.disabled(library.state == .inProgress)
|
||||
.disabled(viewState == .loading)
|
||||
.font(.subheadline)
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
}
|
||||
//
|
||||
//struct Welcome: View {
|
||||
// @Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
// @Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
// @EnvironmentObject private var browser: BrowserViewModel
|
||||
// @EnvironmentObject private var library: LibraryViewModel
|
||||
// @EnvironmentObject private var navigation: NavigationViewModel
|
||||
// @Default(.hasSeenCategories) private var hasSeenCategories
|
||||
//
|
||||
// /// Used only for iPhone
|
||||
// let showLibrary: (() -> Void)?
|
||||
//
|
||||
// var body: some View {
|
||||
// if zimFiles.isEmpty || !FeatureFlags.hasLibrary {
|
||||
// ZStack {
|
||||
// if !FeatureFlags.hasLibrary && browser.isLoading != false {
|
||||
// LoadingView()
|
||||
// } else {
|
||||
// LogoView()
|
||||
// welcomeContent
|
||||
// .onAppear {
|
||||
// if !hasSeenCategories, library.state == .complete {
|
||||
// // safety path for upgrading user with no ZIM files, but fetched categories
|
||||
// // to make sure we do display the buttons
|
||||
// hasSeenCategories = true
|
||||
// }
|
||||
// }
|
||||
// if library.state == .inProgress {
|
||||
// if hasSeenCategories {
|
||||
// LoadingProgressView()
|
||||
// } else {
|
||||
// LoadingMessageView(message: "welcome.button.status.fetching_catalog.text".localized)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }.ignoresSafeArea()
|
||||
// } else if FeatureFlags.hasLibrary {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
struct WelcomeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
WelcomeCatalog(viewState: .loading,
|
||||
showLibrary: nil).environmentObject(LibraryViewModel()).preferredColorScheme(.light).padding()
|
||||
WelcomeCatalog(viewState: .error,
|
||||
showLibrary: nil).environmentObject(LibraryViewModel()).preferredColorScheme(.dark).padding()
|
||||
WelcomeCatalog(viewState: .loading).environmentObject(LibraryViewModel()).preferredColorScheme(.light).padding()
|
||||
WelcomeCatalog(viewState: .error).environmentObject(LibraryViewModel()).preferredColorScheme(.dark).padding()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user