content.tsx 1.8 KB

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