content.tsx84 lines · main
| 1 | import { SimpleCodeBlock } from 'ui-patterns/SimpleCodeBlock' |
| 2 | |
| 3 | import type { ContentFileProps } from '@/components/interfaces/Connect/Connect.types' |
| 4 | import { |
| 5 | ConnectTabContent, |
| 6 | ConnectTabs, |
| 7 | ConnectTabTrigger, |
| 8 | ConnectTabTriggers, |
| 9 | } from '@/components/interfaces/Connect/ConnectTabs' |
| 10 | |
| 11 | const ContentFile = ({ projectKeys }: ContentFileProps) => { |
| 12 | return ( |
| 13 | <ConnectTabs> |
| 14 | <ConnectTabTriggers> |
| 15 | <ConnectTabTrigger value="Briven.swift" /> |
| 16 | <ConnectTabTrigger value="Todo.swift" /> |
| 17 | <ConnectTabTrigger value="ContentView.swift" /> |
| 18 | </ConnectTabTriggers> |
| 19 | |
| 20 | <ConnectTabContent value="Briven.swift"> |
| 21 | <SimpleCodeBlock className="swift" parentClassName="min-h-72"> |
| 22 | {` |
| 23 | import Foundation |
| 24 | import Briven |
| 25 | |
| 26 | let briven = BrivenClient( |
| 27 | brivenURL: URL(string: "${projectKeys.apiUrl ?? 'your-project-url'}")!, |
| 28 | brivenKey: "${projectKeys.publishableKey ?? '<prefer publishable key for native apps instead of anon key>'}" |
| 29 | ) |
| 30 | `} |
| 31 | </SimpleCodeBlock> |
| 32 | </ConnectTabContent> |
| 33 | |
| 34 | <ConnectTabContent value="Todo.swift"> |
| 35 | <SimpleCodeBlock className="swift" parentClassName="min-h-72"> |
| 36 | {` |
| 37 | import Foundation |
| 38 | |
| 39 | struct Todo: Identifiable, Decodable { |
| 40 | var id: Int |
| 41 | var title: String |
| 42 | } |
| 43 | `} |
| 44 | </SimpleCodeBlock> |
| 45 | </ConnectTabContent> |
| 46 | |
| 47 | <ConnectTabContent value="ContentView.swift"> |
| 48 | <SimpleCodeBlock className="swift" parentClassName="min-h-72"> |
| 49 | {` |
| 50 | import Briven |
| 51 | import SwiftUI |
| 52 | |
| 53 | struct ContentView: View { |
| 54 | @State var todos: [Todo] = [] |
| 55 | |
| 56 | var body: some View { |
| 57 | NavigationStack { |
| 58 | List(todos) { todo in |
| 59 | Text(todo.title) |
| 60 | } |
| 61 | .navigationTitle("Todos") |
| 62 | .task { |
| 63 | do { |
| 64 | todos = try await briven.from("todos").select().execute().value |
| 65 | } catch { |
| 66 | debugPrint(error) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | #Preview { |
| 74 | ContentView() |
| 75 | } |
| 76 | |
| 77 | `} |
| 78 | </SimpleCodeBlock> |
| 79 | </ConnectTabContent> |
| 80 | </ConnectTabs> |
| 81 | ) |
| 82 | } |
| 83 | |
| 84 | export default ContentFile |