1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Views/WelcomeScreen.swift

98 lines
3.3 KiB
Swift
Raw Normal View History

import Defaults
import Siesta
2021-10-18 04:36:00 +05:30
import SwiftUI
struct WelcomeScreen: View {
2021-11-28 20:07:55 +05:30
@Environment(\.presentationMode) private var presentationMode
2021-10-18 04:36:00 +05:30
@State private var store = [ManifestedInstance]()
2021-10-18 04:36:00 +05:30
var body: some View {
VStack(alignment: .leading) {
2021-10-18 04:36:00 +05:30
Spacer()
2022-07-04 01:48:11 +05:30
Text("Welcome")
.frame(maxWidth: .infinity)
2021-10-18 04:36:00 +05:30
.font(.largeTitle)
.padding(.bottom, 10)
2022-07-04 01:48:11 +05:30
Text("Select location closest to you:")
.font(.subheadline)
2021-10-18 04:36:00 +05:30
ScrollView {
2022-07-04 01:48:11 +05:30
let countries = store.map(\.country).sorted().unique()
ForEach(countries, id: \.self) { country in
2021-10-18 04:36:00 +05:30
Button {
Defaults[.countryOfPublicInstances] = country
InstancesManifest.shared.setPublicAccount(country)
2021-11-28 20:07:55 +05:30
presentationMode.wrappedValue.dismiss()
2021-10-18 04:36:00 +05:30
} label: {
HStack(spacing: 10) {
if let flag = flag(country) {
Text(flag)
}
Text(country)
#if !os(tvOS)
.foregroundColor(.white)
#endif
.frame(maxWidth: .infinity, alignment: .leading)
2021-10-18 04:36:00 +05:30
}
#if os(tvOS)
.padding(8)
#else
.padding(4)
.background(RoundedRectangle(cornerRadius: 4).foregroundColor(Color.accentColor))
.padding(.bottom, 2)
#endif
}
.buttonStyle(.plain)
#if os(tvOS)
.padding(.horizontal, 10)
2021-10-18 04:36:00 +05:30
#endif
}
.padding(.horizontal, 30)
2021-10-18 04:36:00 +05:30
}
#if !os(tvOS)
OpenSettingsButton()
2022-07-04 01:48:11 +05:30
.foregroundColor(.white)
.padding(10)
.background(RoundedRectangle(cornerRadius: 4).foregroundColor(Color.accentColor))
.frame(maxWidth: .infinity)
#endif
2022-09-04 20:58:30 +05:30
Text("This information will be processed only on your device and used to connect you to the server in the specified country.".localized() + "\n" +
"It can be changed later in settings. You can use your own locations too.".localized())
2022-07-04 01:48:11 +05:30
.font(.caption)
.foregroundColor(.secondary)
}
.onAppear {
resource?.load().onSuccess { response in
if let instances: [ManifestedInstance] = response.typedContent() {
store = instances
}
}
2021-10-18 04:36:00 +05:30
}
.padding()
2021-10-18 04:36:00 +05:30
#if os(macOS)
.frame(minWidth: 400, minHeight: 400)
#elseif os(tvOS)
.frame(maxWidth: 1000)
2021-10-18 04:36:00 +05:30
#endif
}
2021-11-28 20:07:55 +05:30
func flag(_ country: String) -> String? {
store.first { $0.country == country }?.flag
}
var resource: Resource? {
InstancesManifest.shared.instancesList
2021-10-18 04:36:00 +05:30
}
}
struct WelcomeScreen_Previews: PreviewProvider {
static var previews: some View {
WelcomeScreen()
.injectFixtureEnvironmentObjects()
}
}