mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 19:11:12 -05:00
Refactor: Consolidate save buttons
This commit is contained in:
@@ -88,52 +88,39 @@ export function LocationTab() {
|
|||||||
if (!user) return;
|
if (!user) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const {
|
// Save profile information
|
||||||
error
|
const { error: profileError } = await supabase.from('profiles').update({
|
||||||
} = await supabase.from('profiles').update({
|
|
||||||
preferred_pronouns: data.preferred_pronouns || null,
|
preferred_pronouns: data.preferred_pronouns || null,
|
||||||
timezone: data.timezone,
|
timezone: data.timezone,
|
||||||
preferred_language: data.preferred_language,
|
preferred_language: data.preferred_language,
|
||||||
location_id: data.location_id || null,
|
location_id: data.location_id || null,
|
||||||
updated_at: new Date().toISOString()
|
updated_at: new Date().toISOString()
|
||||||
}).eq('user_id', user.id);
|
}).eq('user_id', user.id);
|
||||||
if (error) throw error;
|
|
||||||
await refreshProfile();
|
if (profileError) throw profileError;
|
||||||
toast({
|
|
||||||
title: 'Information updated',
|
// Save accessibility preferences
|
||||||
description: 'Your location and personal information has been successfully updated.'
|
const { error: accessibilityError } = await supabase.from('user_preferences').upsert([{
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
toast({
|
|
||||||
title: 'Error',
|
|
||||||
description: error.message || 'Failed to update information',
|
|
||||||
variant: 'destructive'
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const saveAccessibilityPreferences = async () => {
|
|
||||||
if (!user) return;
|
|
||||||
try {
|
|
||||||
const {
|
|
||||||
error
|
|
||||||
} = await supabase.from('user_preferences').upsert([{
|
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
accessibility_options: accessibility as any,
|
accessibility_options: accessibility as any,
|
||||||
updated_at: new Date().toISOString()
|
updated_at: new Date().toISOString()
|
||||||
}]);
|
}]);
|
||||||
if (error) throw error;
|
|
||||||
|
if (accessibilityError) throw accessibilityError;
|
||||||
|
|
||||||
|
await refreshProfile();
|
||||||
toast({
|
toast({
|
||||||
title: 'Accessibility preferences saved',
|
title: 'Settings saved',
|
||||||
description: 'Your accessibility settings have been updated.'
|
description: 'Your location, personal information, and accessibility settings have been updated.'
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: error.message || 'Failed to save accessibility preferences',
|
description: error.message || 'Failed to save settings',
|
||||||
variant: 'destructive'
|
variant: 'destructive'
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const updateAccessibility = (key: keyof AccessibilityOptions, value: any) => {
|
const updateAccessibility = (key: keyof AccessibilityOptions, value: any) => {
|
||||||
@@ -227,70 +214,64 @@ export function LocationTab() {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
{/* Accessibility Options */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Accessibility className="w-5 h-5" />
|
||||||
|
<h3 className="text-lg font-medium">Accessibility Options</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardDescription>
|
||||||
|
Customize the interface to meet your accessibility needs.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Label>Font Size</Label>
|
||||||
|
<Select value={accessibility.font_size} onValueChange={(value: 'small' | 'medium' | 'large') => updateAccessibility('font_size', value)}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="small">Small</SelectItem>
|
||||||
|
<SelectItem value="medium">Medium (Default)</SelectItem>
|
||||||
|
<SelectItem value="large">Large</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label>High Contrast</Label>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Increase contrast for better visibility
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Switch checked={accessibility.high_contrast} onCheckedChange={checked => updateAccessibility('high_contrast', checked)} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label>Reduced Motion</Label>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Minimize animations and transitions
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Switch checked={accessibility.reduced_motion} onCheckedChange={checked => updateAccessibility('reduced_motion', checked)} />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button type="submit" disabled={loading}>
|
<Button type="submit" disabled={loading}>
|
||||||
{loading ? 'Saving...' : 'Save Information'}
|
{loading ? 'Saving...' : 'Save Settings'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{/* Accessibility Options */}
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Accessibility className="w-5 h-5" />
|
|
||||||
<h3 className="text-lg font-medium">Accessibility Options</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardDescription>
|
|
||||||
Customize the interface to meet your accessibility needs.
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-6">
|
|
||||||
<div className="space-y-3">
|
|
||||||
<Label>Font Size</Label>
|
|
||||||
<Select value={accessibility.font_size} onValueChange={(value: 'small' | 'medium' | 'large') => updateAccessibility('font_size', value)}>
|
|
||||||
<SelectTrigger>
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="small">Small</SelectItem>
|
|
||||||
<SelectItem value="medium">Medium (Default)</SelectItem>
|
|
||||||
<SelectItem value="large">Large</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<Label>High Contrast</Label>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Increase contrast for better visibility
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Switch checked={accessibility.high_contrast} onCheckedChange={checked => updateAccessibility('high_contrast', checked)} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<Label>Reduced Motion</Label>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Minimize animations and transitions
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Switch checked={accessibility.reduced_motion} onCheckedChange={checked => updateAccessibility('reduced_motion', checked)} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-end">
|
|
||||||
<Button onClick={saveAccessibilityPreferences}>
|
|
||||||
Save Accessibility Settings
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user