|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +struct SuggestionSection: View { |
| 4 | + @AppStorage(\.realtimeSuggestionToggle) var realtimeSuggestionToggle |
| 5 | + @AppStorage(\.suggestionFeatureEnabledProjectList) var suggestionFeatureEnabledProjectList |
| 6 | + @AppStorage(\.acceptSuggestionWithTab) var acceptSuggestionWithTab |
| 7 | + @State var isSuggestionFeatureDisabledLanguageListViewOpen = false |
| 8 | + @State private var shouldPresentTurnoffSheet = false |
| 9 | + |
| 10 | + var realtimeSuggestionBinding : Binding<Bool> { |
| 11 | + Binding( |
| 12 | + get: { realtimeSuggestionToggle }, |
| 13 | + set: { |
| 14 | + if !$0 { |
| 15 | + shouldPresentTurnoffSheet = true |
| 16 | + } else { |
| 17 | + realtimeSuggestionToggle = $0 |
| 18 | + } |
| 19 | + } |
| 20 | + ) |
| 21 | + } |
| 22 | + |
| 23 | + var body: some View { |
| 24 | + SettingsSection(title: "Suggestion Settings") { |
| 25 | + SettingsToggle( |
| 26 | + title: "Request suggestions while typing", |
| 27 | + isOn: realtimeSuggestionBinding |
| 28 | + ) |
| 29 | + Divider() |
| 30 | + SettingsToggle( |
| 31 | + title: "Accept suggestions with Tab", |
| 32 | + isOn: $acceptSuggestionWithTab |
| 33 | + ) |
| 34 | + } footer: { |
| 35 | + HStack { |
| 36 | + Spacer() |
| 37 | + Button("Disabled language list") { |
| 38 | + isSuggestionFeatureDisabledLanguageListViewOpen = true |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + .sheet(isPresented: $isSuggestionFeatureDisabledLanguageListViewOpen) { |
| 43 | + DisabledLanguageList(isOpen: $isSuggestionFeatureDisabledLanguageListViewOpen) |
| 44 | + } |
| 45 | + .alert( |
| 46 | + "Disable suggestions while typing", |
| 47 | + isPresented: $shouldPresentTurnoffSheet |
| 48 | + ) { |
| 49 | + Button("Disable") { realtimeSuggestionToggle = false } |
| 50 | + Button("Cancel", role: .cancel, action: {}) |
| 51 | + } message: { |
| 52 | + Text(""" |
| 53 | + If you disable requesting suggestions while typing, you will \ |
| 54 | + not see any suggestions until requested manually. |
| 55 | + """) |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +#Preview { |
| 61 | + SuggestionSection() |
| 62 | +} |
0 commit comments