← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


Crossmate/Views/Browse/ExternalBrowseView.swift (1327B)

1import SwiftUI
2
3struct ExternalBrowseView: View {
4    let onSelected: (String) -> Void
5    let libraryDates: Set<Date>
6
7    @Environment(NYTAuthService.self) private var nytAuth
8    @State private var provider: ExternalPuzzleProvider = .newYorkTimes
9
10    var body: some View {
11        VStack(spacing: 0) {
12            if nytAuth.canAttemptNYTFetch {
13                Picker("Provider", selection: $provider) {
14                    ForEach(ExternalPuzzleProvider.allCases) { provider in
15                        Text(provider.title).tag(provider)
16                    }
17                }
18                .pickerStyle(.menu)
19                .buttonStyle(.bordered)
20                .fixedSize()
21                .frame(maxWidth: .infinity)
22                .padding(.horizontal)
23                .padding(.top)
24                .padding(.bottom, 8)
25            }
26
27            switch provider {
28            case .newYorkTimes:
29                NYTBrowseView(
30                    onSelected: onSelected,
31                    libraryDates: libraryDates
32                )
33            }
34        }
35    }
36}
37
38private enum ExternalPuzzleProvider: String, CaseIterable, Identifiable {
39    case newYorkTimes
40
41    var id: String { rawValue }
42
43    var title: String {
44        switch self {
45        case .newYorkTimes: "New York Times"
46        }
47    }
48}