yattee/Shared/Navigation/ContentView.swift

98 lines
3.3 KiB
Swift
Raw Normal View History

2021-09-25 08:18:22 +00:00
import Defaults
2021-06-09 20:51:23 +00:00
import SwiftUI
struct ContentView: View {
@StateObject private var api = InvidiousAPI()
@StateObject private var instances = InstancesModel()
2021-09-25 08:18:22 +00:00
@StateObject private var navigation = NavigationModel()
@StateObject private var player = PlayerModel()
@StateObject private var playlists = PlaylistsModel()
2021-09-25 12:17:58 +00:00
@StateObject private var recents = RecentsModel()
@StateObject private var search = SearchModel()
@StateObject private var subscriptions = SubscriptionsModel()
2021-09-25 08:18:22 +00:00
2021-07-11 20:52:49 +00:00
#if os(iOS)
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
#endif
2021-06-11 21:11:59 +00:00
2021-06-09 20:51:23 +00:00
var body: some View {
2021-07-11 20:52:49 +00:00
Section {
#if os(iOS)
if horizontalSizeClass == .compact {
AppTabNavigation()
} else {
AppSidebarNavigation()
2021-06-11 21:11:59 +00:00
}
2021-07-11 20:52:49 +00:00
#elseif os(macOS)
AppSidebarNavigation()
#elseif os(tvOS)
TVNavigationView()
#endif
2021-07-29 22:34:13 +00:00
}
.onAppear(perform: configureAPI)
.environmentObject(api)
.environmentObject(instances)
2021-09-25 08:18:22 +00:00
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(playlists)
2021-09-25 08:18:22 +00:00
.environmentObject(recents)
.environmentObject(search)
.environmentObject(subscriptions)
#if os(iOS)
.fullScreenCover(isPresented: $player.presentingPlayer) {
VideoPlayerView()
.environmentObject(api)
2021-10-13 22:10:29 +00:00
.environmentObject(instances)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
2021-08-01 23:01:24 +00:00
}
#elseif os(macOS)
.sheet(isPresented: $player.presentingPlayer) {
VideoPlayerView()
.frame(minWidth: 900, minHeight: 800)
.environmentObject(api)
2021-10-13 22:10:29 +00:00
.environmentObject(instances)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
}
#endif
#if !os(tvOS)
.sheet(isPresented: $navigation.presentingAddToPlaylist) {
AddToPlaylistView(video: navigation.videoToAddToPlaylist)
.environmentObject(api)
.environmentObject(playlists)
}
2021-09-25 08:18:22 +00:00
.sheet(isPresented: $navigation.presentingPlaylistForm) {
PlaylistFormView(playlist: $navigation.editedPlaylist)
.environmentObject(api)
.environmentObject(playlists)
2021-09-25 08:18:22 +00:00
}
.sheet(isPresented: $navigation.presentingSettings) {
SettingsView()
.environmentObject(api)
.environmentObject(instances)
2021-08-29 21:36:18 +00:00
}
2021-08-01 23:01:24 +00:00
#endif
2021-07-07 22:39:18 +00:00
}
func configureAPI() {
if let account = instances.defaultAccount, api.account.isEmpty {
api.setAccount(account)
}
player.api = api
playlists.api = api
search.api = api
subscriptions.api = api
}
2021-06-09 20:51:23 +00:00
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
2021-09-29 11:45:00 +00:00
.injectFixtureEnvironmentObjects()
2021-06-09 20:51:23 +00:00
}
}