From e2536a41d0aa065bc62c883f9ff4398711b418f9 Mon Sep 17 00:00:00 2001 From: limellie Date: Fri, 10 Apr 2026 22:03:31 -0700 Subject: [PATCH 01/18] Merging main with updated front-end into backend_ellie --- client/src/Account.tsx | 120 ++++++++++++++++++++++++++++++++++++++ client/src/Auth.tsx | 95 ++++++++++++++++++++++++++++++ client/src/goalBackend.js | 14 +++++ 3 files changed, 229 insertions(+) create mode 100644 client/src/Account.tsx create mode 100644 client/src/Auth.tsx create mode 100644 client/src/goalBackend.js diff --git a/client/src/Account.tsx b/client/src/Account.tsx new file mode 100644 index 00000000..398b2f06 --- /dev/null +++ b/client/src/Account.tsx @@ -0,0 +1,120 @@ +import { useState, useEffect } from 'react' +import { supabase } from '../lib/supabase' +import { StyleSheet, View, Alert } from 'react-native' +import { Button, Input } from '@rneui/themed' +import { Session } from '@supabase/supabase-js' + +export default function Account({ session }: { session: Session }) { + const [loading, setLoading] = useState(true) + const [username, setUsername] = useState('') + const [website, setWebsite] = useState('') + const [avatarUrl, setAvatarUrl] = useState('') + + useEffect(() => { + if (session) getProfile() + }, [session]) + + async function getProfile() { + try { + setLoading(true) + if (!session?.user) throw new Error('No user on the session!') + + const { data, error, status } = await supabase + .from('profiles') + .select(`username, website, avatar_url`) + .eq('id', session?.user.id) + .single() + if (error && status !== 406) { + throw error + } + + if (data) { + setUsername(data.username) + setWebsite(data.website) + setAvatarUrl(data.avatar_url) + } + } catch (error) { + if (error instanceof Error) { + Alert.alert(error.message) + } + } finally { + setLoading(false) + } + } + + async function updateProfile({ + username, + website, + avatar_url, + }: { + username: string + website: string + avatar_url: string + }) { + try { + setLoading(true) + if (!session?.user) throw new Error('No user on the session!') + + const updates = { + id: session?.user.id, + username, + website, + avatar_url, + updated_at: new Date(), + } + + const { error } = await supabase.from('profiles').upsert(updates) + + if (error) { + throw error + } + } catch (error) { + if (error instanceof Error) { + Alert.alert(error.message) + } + } finally { + setLoading(false) + } + } + + return ( + + + + + + setUsername(text)} /> + + + setWebsite(text)} /> + + + +