2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SignInRequiredView<Content: View>: View {
|
|
|
|
let title: String
|
|
|
|
let content: Content
|
|
|
|
|
2021-10-16 22:48:58 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
|
2021-09-29 14:29:17 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2021-10-16 22:48:58 +00:00
|
|
|
@Default(.instances) private var instances
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
init(title: String, @ViewBuilder content: @escaping () -> Content) {
|
|
|
|
self.title = title
|
|
|
|
self.content = content()
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
2021-10-16 22:48:58 +00:00
|
|
|
if accounts.signedIn {
|
2021-09-25 08:18:22 +00:00
|
|
|
content
|
|
|
|
} else {
|
|
|
|
prompt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if !os(tvOS)
|
|
|
|
.navigationTitle(title)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var prompt: some View {
|
|
|
|
VStack(spacing: 30) {
|
|
|
|
Text("Sign In Required")
|
|
|
|
.font(.title2.bold())
|
|
|
|
|
|
|
|
Group {
|
|
|
|
if instances.isEmpty {
|
|
|
|
Text("You need to create an instance and accounts\nto access **\(title)** section")
|
|
|
|
} else {
|
|
|
|
Text("You need to select an account\nto access **\(title)** section")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.font(.title3)
|
|
|
|
.padding(.vertical)
|
|
|
|
|
2021-09-29 11:45:00 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
if instances.isEmpty {
|
2021-10-17 23:06:00 +00:00
|
|
|
OpenSettingsButton()
|
2021-09-29 11:45:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-09-28 18:06:05 +00:00
|
|
|
|
|
|
|
#if os(tvOS)
|
2021-10-17 23:06:00 +00:00
|
|
|
OpenSettingsButton()
|
2021-09-28 18:06:05 +00:00
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SignInRequiredView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-05 20:20:09 +00:00
|
|
|
PlayerControlsView {
|
|
|
|
SignInRequiredView(title: "Subscriptions") {
|
|
|
|
Text("Only when signed in")
|
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
.environmentObject(PlayerModel())
|
2021-09-29 11:45:00 +00:00
|
|
|
.environmentObject(InvidiousAPI())
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|