content.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. `NEXT_PUBLIC_BRIVEN_URL=${projectKeys.apiUrl ?? 'your-project-url'}`,
  10. projectKeys?.publishableKey
  11. ? `NEXT_PUBLIC_BRIVEN_PUBLISHABLE_KEY=${projectKeys.publishableKey}`
  12. : `NEXT_PUBLIC_BRIVEN_ANON_KEY=${projectKeys.anonKey ?? 'your-anon-key'}`,
  13. '',
  14. ].join('\n'),
  15. },
  16. {
  17. name: 'utils/briven.ts',
  18. language: 'ts',
  19. code: `
  20. import { createClient } from "@supabase/supabase-js";
  21. const brivenUrl = process.env.NEXT_PUBLIC_BRIVEN_URL!;
  22. const brivenKey = process.env.${projectKeys?.publishableKey ? 'NEXT_PUBLIC_BRIVEN_PUBLISHABLE_KEY' : 'NEXT_PUBLIC_BRIVEN_ANON_KEY'}!;
  23. export const briven = createClient(brivenUrl, brivenKey);
  24. `,
  25. },
  26. {
  27. name: 'pages/index.tsx',
  28. language: 'tsx',
  29. code: `
  30. import { useState, useEffect } from 'react'
  31. import { briven } from '../utils/briven'
  32. export default function Page() {
  33. const [todos, setTodos] = useState([])
  34. useEffect(() => {
  35. async function getTodos() {
  36. const { data: todos } = await briven.from('todos').select()
  37. if (todos) {
  38. setTodos(todos)
  39. }
  40. }
  41. getTodos()
  42. }, [])
  43. return (
  44. <ul>
  45. {todos.map((todo) => (
  46. <li key={todo.id}>{todo.name}</li>
  47. ))}
  48. </ul>
  49. )
  50. }
  51. `,
  52. },
  53. ]
  54. return <MultipleCodeBlock files={files} />
  55. }
  56. export default ContentFile