Created
May 31, 2022 10:18
-
-
Save koke/2c943fe6f6b91cad36a15a1f77b7a4de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Storage | |
enum BetaFeature: CaseIterable { | |
case viewAddOns | |
case productSKUScanner | |
case couponManagement | |
} | |
extension BetaFeature { | |
var title: String { | |
switch self { | |
case .viewAddOns: | |
return NSLocalizedString( | |
"View Add-Ons", | |
comment: "Cell title on the beta features screen to enable the order add-ons feature") | |
case .productSKUScanner: | |
return NSLocalizedString( | |
"Product SKU Scanner", | |
comment: "Cell title on beta features screen to enable product SKU input scanner in inventory settings.") | |
case .couponManagement: | |
return NSLocalizedString( | |
"Coupon Management", | |
comment: "Cell title on beta features screen to enable coupon management") | |
} | |
} | |
var description: String { | |
switch self { | |
case .viewAddOns: | |
return NSLocalizedString( | |
"Test out viewing Order Add-Ons as we get ready to launch", | |
comment: "Cell description on the beta features screen to enable the order add-ons feature") | |
case .productSKUScanner: | |
return NSLocalizedString( | |
"Test out scanning a barcode for a product SKU in the product inventory settings", | |
comment: "Cell description on beta features screen to enable product SKU input scanner in inventory settings.") | |
case .couponManagement: | |
return NSLocalizedString( | |
"Test out managing coupons as we get ready to launch", | |
comment: "Cell description on beta features screen to enable coupon management") | |
} | |
} | |
var settingsKey: KeyPath<GeneralAppSettings, Bool> { | |
switch self { | |
case .viewAddOns: | |
return \.isViewAddOnsSwitchEnabled | |
case .productSKUScanner: | |
return \.isProductSKUInputScannerSwitchEnabled | |
case .couponManagement: | |
return \.isCouponManagementSwitchEnabled | |
} | |
} | |
} | |
extension BetaFeature { | |
var isEnabled: Bool { | |
// TODO: actually load settings from storage | |
let settings = GeneralAppSettings(installationDate: nil, feedbacks: [:], isViewAddOnsSwitchEnabled: true, isProductSKUInputScannerSwitchEnabled: true, isCouponManagementSwitchEnabled: true, knownCardReaders: []) | |
return settings[keyPath: settingsKey] | |
} | |
func isEnabledBinding() -> Binding<Bool> { | |
return Binding { | |
isEnabled | |
} set: { value in | |
// TODO | |
} | |
} | |
} | |
extension BetaFeature: Identifiable { | |
var id: String { | |
description | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import Yosemite | |
struct BetaFeaturesConfiguration: View { | |
var body: some View { | |
List { | |
ForEach(BetaFeature.allCases) { feature in | |
Section(footer: Text(feature.description)) { | |
Toggle(feature.title, isOn: feature.isEnabledBinding()) | |
} | |
} | |
} | |
.listStyle(.grouped) | |
} | |
} | |
struct BetaFeaturesConfiguration_Previews: PreviewProvider { | |
static var previews: some View { | |
BetaFeaturesConfiguration() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment