content.tsx71 lines · main
1import { MultipleCodeBlock } from 'ui-patterns/MultipleCodeBlock'
2
3import type { StepContentProps } from '@/components/interfaces/ConnectSheet/Connect.types'
4
5const ContentFile = ({ projectKeys }: StepContentProps) => {
6 const files = [
7 {
8 name: 'MainActivity.kt',
9 language: 'kotlin',
10 code: `
11val briven = createBrivenClient(
12 brivenUrl = "${projectKeys.apiUrl ?? 'your-project-url'}",
13 brivenKey = "${projectKeys.publishableKey ?? '<prefer publishable key instead of anon key for mobile apps>'}"
14 ) {
15 install(Postgrest)
16}
17
18class MainActivity : ComponentActivity() {
19 override fun onCreate(savedInstanceState: Bundle?) {
20 super.onCreate(savedInstanceState)
21 setContent {
22 MaterialTheme {
23 // A surface container using the 'background' color from the theme
24 Surface(
25 modifier = Modifier.fillMaxSize(),
26 color = MaterialTheme.colorScheme.background
27 ) {
28 TodoList()
29 }
30 }
31 }
32 }
33}
34
35@Composable
36fun TodoList() {
37 var items by remember { mutableStateOf<List<TodoItem>>(listOf()) }
38 LaunchedEffect(Unit) {
39 withContext(Dispatchers.IO) {
40 items = briven.from("todos")
41 .select().decodeList<TodoItem>()
42 }
43 }
44 LazyColumn {
45 items(
46 items,
47 key = { item -> item.id },
48 ) { item ->
49 Text(
50 item.name,
51 modifier = Modifier.padding(8.dp),
52 )
53 }
54 }
55}
56`,
57 },
58 {
59 name: 'TodoItem.kt',
60 language: 'kotlin',
61 code: `
62@Serializable
63data class TodoItem(val id: Int, val name: String)
64 `,
65 },
66 ]
67
68 return <MultipleCodeBlock files={files} />
69}
70
71export default ContentFile