Sources/OrgstarMobile/TipSection.swift
49 lines · 1781 bytes
1 symbol in this file
1#if os(iOS)
2import OrgApp
3import StoreKit
4import SwiftUI
5
6/// Tips in About, for everyone, with or without orgstar+.
7struct TipSection: View {
8 @State private var store = TipStore()
9
10 var body: some View {
11 Section {
12 if store.isLoading && store.products.isEmpty {
13 ProgressView().frame(maxWidth: .infinity)
14 }
15 ForEach(store.products) { product in
16 Button { Task { await store.purchase(product) } } label: {
17 HStack {
18 Text(product.displayName)
19 Spacer()
20 if store.purchasingProductID == product.id {
21 ProgressView().controlSize(.small)
22 } else {
23 Text(product.displayPrice).monospacedDigit().foregroundStyle(.secondary)
24 }
25 }
26 }
27 .tint(.primary)
28 .disabled(store.purchasingProductID != nil)
29 }
30 if let message = store.message {
31 Text(message).foregroundStyle(.secondary)
32 if store.products.count < Tip.productIDs.count {
33 Button("Try Again") { Task { await store.loadProducts() } }.disabled(store.isLoading)
34 }
35 }
36 } header: {
37 Text("Support Development")
38 } footer: {
39 Text("Tips are one-time purchases that help pay for orgstar's development. They don't unlock anything.")
40 }
41 .task { await store.loadProducts() }
42 .alert("Thank You", isPresented: $store.thanked) {
43 Button("OK") {}
44 } message: {
45 Text("Your tip helps keep orgstar going.")
46 }
47 }
48}
49#endif