import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Image } from '@/components/ui/image'; import { MediaPicker, type MediaAsset } from '@/components/ui/media-picker'; import { ModeToggle } from '@/components/ui/mode-toggle'; import { ScrollView } from '@/components/ui/scroll-view'; import { Separator } from '@/components/ui/separator'; import { Text } from '@/components/ui/text'; import { useToast } from '@/components/ui/toast'; import { View } from '@/components/ui/view'; import { useUpload, type UploadedFile } from '@/hooks/useUpload'; import { supabase } from '@/lib/supabase'; import { useState } from 'react'; export default function SettingsScreen() { const { upload, uploading } = useUpload(); const [selected, setSelected] = useState([]); const [uploaded, setUploaded] = useState([]); const [invoking, setInvoking] = useState(false); const [functionResult, setFunctionResult] = useState(null); const toast = useToast(); const projectUrl = process.env.EXPO_PUBLIC_SUPABASE_URL ?? ''; const projectRef = projectUrl.replace(/^https?:\/\//, '').split('.')[0]; const handleUpload = async () => { const asset = selected[0]; if (!asset) return; const result = await upload(asset); if (!result) { toast.error( 'Upload failed', 'Check the bucket policies in supabase/migrations/0002_storage.sql' ); return; } setUploaded((prev) => [result, ...prev]); setSelected([]); toast.success('Uploaded', result.path); }; const invokeFunction = async () => { setInvoking(true); setFunctionResult(null); const { data, error } = await supabase.functions.invoke('hello-world'); setInvoking(false); if (error) { toast.error( 'Function failed', 'Deploy it first: npm run functions:deploy' ); return; } setFunctionResult(JSON.stringify(data, null, 2)); }; return ( Project {projectRef ? 'Connected' : 'Not configured'} {projectUrl || 'Set EXPO_PUBLIC_SUPABASE_URL in .env.local'} Storage Uploads land in the public `uploads` bucket, so `getPublicUrl()` returns a link anyone can open. Use a private bucket and `createSignedUrl()` for anything that is not meant to be shared. toast.error('Picker error', message)} /> {uploaded.map((file) => ( {file.path} ))} Edge function Deno, running close to your database. `supabase/functions/hello-world` counts the tasks table server-side and returns JSON. {functionResult && ( {functionResult} )} ); }