Files
yattee/Shared/Trending/TrendingCountry.swift
Arkadiusz Fal 5758417293 Fix SwiftLint and SwiftFormat violations
- Run SwiftFormat to fix indentation, spacing, and formatting issues
- Replace CGFloat with Double and NSRect with CGRect per style guide
- Remove redundant .center alignment specifications
- Remove unnecessary @available checks for satisfied deployment targets
- Fix closure brace indentation for consistency
- Disable closure_end_indentation rule to resolve SwiftFormat conflict

All linting checks now pass with zero errors and warnings.
2025-11-15 19:42:37 +01:00

85 lines
2.5 KiB
Swift

import SwiftUI
struct TrendingCountry: View {
static let prompt = "Country Name or Code".localized()
@Binding var selectedCountry: Country
@StateObject private var store = Store(Country.allCases)
@State private var query = ""
@State private var selection: Country?
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode
var body: some View {
VStack {
#if !os(tvOS)
HStack {
// swiftlint:disable:next deployment_target
if #available(iOS 15.0, macOS 12.0, *) {
TextField("Country", text: $query, prompt: Text(Self.prompt))
} else {
TextField("Country", text: $query)
}
Button("Done") { selectCountryAndDismiss() }
.keyboardShortcut(.defaultAction)
.keyboardShortcut(.cancelAction)
}
.padding([.horizontal, .top])
#endif
countriesList
}
#if os(tvOS)
.searchable(text: $query, placement: .automatic, prompt: Text(Self.prompt))
.background(Color.background(scheme: colorScheme))
#endif
}
var countriesList: some View {
let list = ScrollViewReader { _ in
List(store.collection, selection: $selection) { country in
#if os(macOS)
Text(country.name)
.tag(country)
.id(country)
#else
Button(country.name) { selectCountryAndDismiss(country) }
#endif
}
.onChange(of: query) { newQuery in
let results = Country.search(newQuery)
store.replace(results)
selection = results.first
}
}
return Group {
#if os(macOS)
list.listStyle(.inset(alternatesRowBackgrounds: true))
#else
list
#endif
}
#if os(macOS)
.padding(.bottom, 5)
#endif
}
func selectCountryAndDismiss(_ country: Country? = nil) {
if let selected = country ?? selection {
selectedCountry = selected
}
presentationMode.wrappedValue.dismiss()
}
}
struct TrendingCountry_Previews: PreviewProvider {
static var previews: some View {
TrendingCountry(selectedCountry: .constant(.pl))
}
}