content.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: '.env.local',
  7. language: 'bash',
  8. code: `
  9. EXPO_PUBLIC_BRIVEN_URL=${projectKeys.apiUrl ?? 'your-project-url'}
  10. EXPO_PUBLIC_BRIVEN_KEY=${projectKeys.publishableKey ?? '<prefer publishable key instead of anon key for mobile and desktop apps>'}
  11. `,
  12. },
  13. {
  14. name: 'utils/briven.ts',
  15. language: 'ts',
  16. code: `
  17. import AsyncStorage from '@react-native-async-storage/async-storage'
  18. import { createClient } from '@supabase/supabase-js'
  19. export const briven = createClient(
  20. process.env.EXPO_PUBLIC_BRIVEN_URL!,
  21. process.env.EXPO_PUBLIC_BRIVEN_KEY!,
  22. {
  23. auth: {
  24. storage: AsyncStorage,
  25. autoRefreshToken: true,
  26. persistSession: true,
  27. detectSessionInUrl: false,
  28. },
  29. })
  30. `,
  31. },
  32. {
  33. name: 'App.tsx',
  34. language: 'tsx',
  35. code: `
  36. import React, { useState, useEffect } from 'react';
  37. import { View, Text, FlatList } from 'react-native';
  38. import { briven } from '../utils/briven';
  39. export default function App() {
  40. const [todos, setTodos] = useState([]);
  41. useEffect(() => {
  42. const getTodos = async () => {
  43. try {
  44. const { data: todos, error } = await briven.from('todos').select();
  45. if (error) {
  46. console.error('Error fetching todos:', error.message);
  47. return;
  48. }
  49. if (todos && todos.length > 0) {
  50. setTodos(todos);
  51. }
  52. } catch (error) {
  53. console.error('Error fetching todos:', error.message);
  54. }
  55. };
  56. getTodos();
  57. }, []);
  58. return (
  59. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  60. <Text>Todo List</Text>
  61. <FlatList
  62. data={todos}
  63. keyExtractor={(item) => item.id.toString()}
  64. renderItem={({ item }) => <Text key={item.id}>{item.name}</Text>}
  65. />
  66. </View>
  67. );
  68. };
  69. `,
  70. },
  71. ]
  72. return <MultipleCodeBlock files={files} />
  73. }
  74. export default ContentFile