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