-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
.../studio/components/interfaces/Home/Connect/content/exporeactnative/supabasejs/content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { ContentFileProps } from 'components/interfaces/Home/Connect/Connect.types' | ||
|
||
import { | ||
ConnectTabs, | ||
ConnectTabTrigger, | ||
ConnectTabTriggers, | ||
ConnectTabContent, | ||
} from 'components/interfaces/Home/Connect/ConnectTabs' | ||
import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock' | ||
|
||
const ContentFile = ({ projectKeys }: ContentFileProps) => { | ||
return ( | ||
<ConnectTabs> | ||
<ConnectTabTriggers> | ||
<ConnectTabTrigger value=".env.local" /> | ||
<ConnectTabTrigger value="utils/supabase.ts " /> | ||
<ConnectTabTrigger value="App.tsx" /> | ||
</ConnectTabTriggers> | ||
|
||
<ConnectTabContent value=".env.local"> | ||
<SimpleCodeBlock className="bash" parentClassName="min-h-72"> | ||
{` | ||
SUPABASE_URL=${projectKeys.apiUrl ?? 'your-project-url'} | ||
SUPABASE_ANON_KEY=${projectKeys.anonKey ?? 'your-anon-key'} | ||
`} | ||
</SimpleCodeBlock> | ||
</ConnectTabContent> | ||
|
||
<ConnectTabContent value="utils/supabase.ts"> | ||
<SimpleCodeBlock className="ts" parentClassName="min-h-72"> | ||
{` | ||
import 'react-native-url-polyfill/auto' | ||
import AsyncStorage from '@react-native-async-storage/async-storage' | ||
import { createClient } from '@supabase/supabase-js' | ||
import { SUPABASE_URL, SUPABASE_ANON_KEY } from "@env"; | ||
export const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, { | ||
auth: { | ||
storage: AsyncStorage, | ||
autoRefreshToken: true, | ||
persistSession: true, | ||
detectSessionInUrl: false, | ||
}, | ||
}) | ||
`} | ||
</SimpleCodeBlock> | ||
</ConnectTabContent> | ||
|
||
<ConnectTabContent value="App.tsx"> | ||
<SimpleCodeBlock className="tsx" parentClassName="min-h-72"> | ||
{` | ||
import React, { useState, useEffect } from 'react'; | ||
import { View, Text, FlatList } from 'react-native'; | ||
import { supabase } from '../utils/supabase'; | ||
export default function App() { | ||
const [todos, setTodos] = useState([]); | ||
useEffect(() => { | ||
const getTodos = async () => { | ||
try { | ||
const { data: todos, error } = await supabase.from('todos').select(); | ||
if (error) { | ||
console.error('Error fetching todos:', error.message); | ||
return; | ||
} | ||
if (todos && todos.length > 0) { | ||
setTodos(todos); | ||
} | ||
} catch (error) { | ||
console.error('Error fetching todos:', error.message); | ||
} | ||
}; | ||
getTodos(); | ||
}, []); | ||
return ( | ||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
<Text>Todo List</Text> | ||
<FlatList | ||
data={todos} | ||
keyExtractor={(item) => item.id.toString()} | ||
renderItem={({ item }) => <Text key={item.id}>{item.title}</Text>} | ||
/> | ||
</View> | ||
); | ||
}; | ||
`} | ||
</SimpleCodeBlock> | ||
</ConnectTabContent> | ||
</ConnectTabs> | ||
) | ||
} | ||
|
||
export default ContentFile |