content.tsx 2.3 KB

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