Visual edit in Lovable

This commit is contained in:
gpt-engineer-app[bot]
2025-09-28 20:24:01 +00:00
parent 23172444a0
commit 65e5b8e52f

View File

@@ -10,25 +10,27 @@ import { useToast } from '@/hooks/use-toast';
import { useAuth } from '@/hooks/useAuth'; import { useAuth } from '@/hooks/useAuth';
import { supabase } from '@/integrations/supabase/client'; import { supabase } from '@/integrations/supabase/client';
import { Eye, UserX, Shield, Search } from 'lucide-react'; import { Eye, UserX, Shield, Search } from 'lucide-react';
interface PrivacySettings { interface PrivacySettings {
activity_visibility: 'public' | 'private'; activity_visibility: 'public' | 'private';
search_visibility: boolean; search_visibility: boolean;
show_location: boolean; show_location: boolean;
show_age: boolean; show_age: boolean;
} }
interface ProfilePrivacy { interface ProfilePrivacy {
privacy_level: 'public' | 'private'; privacy_level: 'public' | 'private';
show_pronouns: boolean; show_pronouns: boolean;
} }
export function PrivacyTab() { export function PrivacyTab() {
const { user, profile, refreshProfile } = useAuth(); const {
const { toast } = useToast(); user,
profile,
refreshProfile
} = useAuth();
const {
toast
} = useToast();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [preferences, setPreferences] = useState<PrivacySettings | null>(null); const [preferences, setPreferences] = useState<PrivacySettings | null>(null);
const form = useForm<ProfilePrivacy & PrivacySettings>({ const form = useForm<ProfilePrivacy & PrivacySettings>({
defaultValues: { defaultValues: {
privacy_level: (profile?.privacy_level === 'friends' ? 'public' : profile?.privacy_level) || 'public', privacy_level: (profile?.privacy_level === 'friends' ? 'public' : profile?.privacy_level) || 'public',
@@ -39,31 +41,25 @@ export function PrivacyTab() {
show_age: false show_age: false
} }
}); });
useEffect(() => { useEffect(() => {
fetchPreferences(); fetchPreferences();
}, [user]); }, [user]);
const fetchPreferences = async () => { const fetchPreferences = async () => {
if (!user) return; if (!user) return;
try { try {
const { data, error } = await supabase const {
.from('user_preferences') data,
.select('privacy_settings') error
.eq('user_id', user.id) } = await supabase.from('user_preferences').select('privacy_settings').eq('user_id', user.id).maybeSingle();
.maybeSingle();
if (error && error.code !== 'PGRST116') { if (error && error.code !== 'PGRST116') {
console.error('Error fetching preferences:', error); console.error('Error fetching preferences:', error);
return; return;
} }
if (data?.privacy_settings) { if (data?.privacy_settings) {
const privacySettings = data.privacy_settings as any; const privacySettings = data.privacy_settings as any;
setPreferences(privacySettings); setPreferences(privacySettings);
form.reset({ form.reset({
privacy_level: profile?.privacy_level === 'friends' ? 'public' : (profile?.privacy_level || 'public'), privacy_level: profile?.privacy_level === 'friends' ? 'public' : profile?.privacy_level || 'public',
show_pronouns: profile?.show_pronouns || false, show_pronouns: profile?.show_pronouns || false,
...privacySettings ...privacySettings
}); });
@@ -75,27 +71,22 @@ export function PrivacyTab() {
console.error('Error fetching preferences:', error); console.error('Error fetching preferences:', error);
} }
}; };
const initializePreferences = async () => { const initializePreferences = async () => {
if (!user) return; if (!user) return;
const defaultSettings: PrivacySettings = { const defaultSettings: PrivacySettings = {
activity_visibility: 'public', activity_visibility: 'public',
search_visibility: true, search_visibility: true,
show_location: false, show_location: false,
show_age: false show_age: false
}; };
try { try {
const { error } = await supabase const {
.from('user_preferences') error
.insert([{ } = await supabase.from('user_preferences').insert([{
user_id: user.id, user_id: user.id,
privacy_settings: defaultSettings as any privacy_settings: defaultSettings as any
}]); }]);
if (error) throw error; if (error) throw error;
setPreferences(defaultSettings); setPreferences(defaultSettings);
form.reset({ form.reset({
privacy_level: (profile?.privacy_level === 'friends' ? 'public' : profile?.privacy_level) || 'public', privacy_level: (profile?.privacy_level === 'friends' ? 'public' : profile?.privacy_level) || 'public',
@@ -106,22 +97,18 @@ export function PrivacyTab() {
console.error('Error initializing preferences:', error); console.error('Error initializing preferences:', error);
} }
}; };
const onSubmit = async (data: any) => { const onSubmit = async (data: any) => {
if (!user) return; if (!user) return;
setLoading(true); setLoading(true);
try { try {
// Update profile privacy settings // Update profile privacy settings
const { error: profileError } = await supabase const {
.from('profiles') error: profileError
.update({ } = await supabase.from('profiles').update({
privacy_level: data.privacy_level, privacy_level: data.privacy_level,
show_pronouns: data.show_pronouns, show_pronouns: data.show_pronouns,
updated_at: new Date().toISOString() updated_at: new Date().toISOString()
}) }).eq('user_id', user.id);
.eq('user_id', user.id);
if (profileError) throw profileError; if (profileError) throw profileError;
// Update user preferences // Update user preferences
@@ -131,20 +118,16 @@ export function PrivacyTab() {
show_location: data.show_location, show_location: data.show_location,
show_age: data.show_age show_age: data.show_age
}; };
const {
const { error: prefsError } = await supabase error: prefsError
.from('user_preferences') } = await supabase.from('user_preferences').upsert([{
.upsert([{ user_id: user.id,
user_id: user.id, privacy_settings: privacySettings as any,
privacy_settings: privacySettings as any, updated_at: new Date().toISOString()
updated_at: new Date().toISOString() }]);
}]);
if (prefsError) throw prefsError; if (prefsError) throw prefsError;
await refreshProfile(); await refreshProfile();
setPreferences(privacySettings); setPreferences(privacySettings);
toast({ toast({
title: 'Privacy settings updated', title: 'Privacy settings updated',
description: 'Your privacy preferences have been successfully saved.' description: 'Your privacy preferences have been successfully saved.'
@@ -159,9 +142,7 @@ export function PrivacyTab() {
setLoading(false); setLoading(false);
} }
}; };
return <div className="space-y-8">
return (
<div className="space-y-8">
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
{/* Profile Visibility */} {/* Profile Visibility */}
<div className="space-y-4"> <div className="space-y-4">
@@ -179,12 +160,7 @@ export function PrivacyTab() {
<CardContent className="space-y-6"> <CardContent className="space-y-6">
<div className="space-y-3"> <div className="space-y-3">
<Label htmlFor="privacy_level">Profile Privacy</Label> <Label htmlFor="privacy_level">Profile Privacy</Label>
<Select <Select value={form.watch('privacy_level')} onValueChange={(value: 'public' | 'private') => form.setValue('privacy_level', value)}>
value={form.watch('privacy_level')}
onValueChange={(value: 'public' | 'private') =>
form.setValue('privacy_level', value)
}
>
<SelectTrigger> <SelectTrigger>
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
@@ -206,10 +182,7 @@ export function PrivacyTab() {
Display your preferred pronouns on your profile Display your preferred pronouns on your profile
</p> </p>
</div> </div>
<Switch <Switch checked={form.watch('show_pronouns')} onCheckedChange={checked => form.setValue('show_pronouns', checked)} />
checked={form.watch('show_pronouns')}
onCheckedChange={(checked) => form.setValue('show_pronouns', checked)}
/>
</div> </div>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
@@ -219,24 +192,10 @@ export function PrivacyTab() {
Display your location on your profile Display your location on your profile
</p> </p>
</div> </div>
<Switch <Switch checked={form.watch('show_location')} onCheckedChange={checked => form.setValue('show_location', checked)} />
checked={form.watch('show_location')}
onCheckedChange={(checked) => form.setValue('show_location', checked)}
/>
</div> </div>
<div className="flex items-center justify-between">
<div className="space-y-1">
<Label>Show Age</Label>
<p className="text-sm text-muted-foreground">
Display your age calculated from date of birth
</p>
</div>
<Switch
checked={form.watch('show_age')}
onCheckedChange={(checked) => form.setValue('show_age', checked)}
/>
</div>
</CardContent> </CardContent>
</Card> </Card>
</div> </div>
@@ -259,12 +218,7 @@ export function PrivacyTab() {
<CardContent className="space-y-6"> <CardContent className="space-y-6">
<div className="space-y-3"> <div className="space-y-3">
<Label htmlFor="activity_visibility">Activity Visibility</Label> <Label htmlFor="activity_visibility">Activity Visibility</Label>
<Select <Select value={form.watch('activity_visibility')} onValueChange={(value: 'public' | 'private') => form.setValue('activity_visibility', value)}>
value={form.watch('activity_visibility')}
onValueChange={(value: 'public' | 'private') =>
form.setValue('activity_visibility', value)
}
>
<SelectTrigger> <SelectTrigger>
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
@@ -308,10 +262,7 @@ export function PrivacyTab() {
Allow your profile to appear in search results Allow your profile to appear in search results
</p> </p>
</div> </div>
<Switch <Switch checked={form.watch('search_visibility')} onCheckedChange={checked => form.setValue('search_visibility', checked)} />
checked={form.watch('search_visibility')}
onCheckedChange={(checked) => form.setValue('search_visibility', checked)}
/>
</div> </div>
</CardContent> </CardContent>
</Card> </Card>
@@ -351,6 +302,5 @@ export function PrivacyTab() {
</Button> </Button>
</div> </div>
</form> </form>
</div> </div>;
);
} }