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