diff --git a/src/components/settings/NotificationsTab.tsx b/src/components/settings/NotificationsTab.tsx
index 2bdc0bce..c95bfe18 100644
--- a/src/components/settings/NotificationsTab.tsx
+++ b/src/components/settings/NotificationsTab.tsx
@@ -9,7 +9,6 @@ import { useToast } from '@/hooks/use-toast';
import { useAuth } from '@/hooks/useAuth';
import { supabase } from '@/integrations/supabase/client';
import { Bell, Mail, Smartphone, Volume2 } from 'lucide-react';
-
interface EmailNotifications {
review_replies: boolean;
new_followers: boolean;
@@ -17,16 +16,18 @@ interface EmailNotifications {
weekly_digest: boolean;
monthly_digest: boolean;
}
-
interface PushNotifications {
browser_enabled: boolean;
new_content: boolean;
social_updates: boolean;
}
-
export function NotificationsTab() {
- const { user } = useAuth();
- const { toast } = useToast();
+ const {
+ user
+ } = useAuth();
+ const {
+ toast
+ } = useToast();
const [loading, setLoading] = useState(false);
const [emailNotifications, setEmailNotifications] = useState({
review_replies: true,
@@ -40,26 +41,20 @@ export function NotificationsTab() {
new_content: true,
social_updates: true
});
-
useEffect(() => {
fetchNotificationPreferences();
}, [user]);
-
const fetchNotificationPreferences = async () => {
if (!user) return;
-
try {
- const { data, error } = await supabase
- .from('user_preferences')
- .select('email_notifications, push_notifications')
- .eq('user_id', user.id)
- .maybeSingle();
-
+ const {
+ data,
+ error
+ } = await supabase.from('user_preferences').select('email_notifications, push_notifications').eq('user_id', user.id).maybeSingle();
if (error && error.code !== 'PGRST116') {
console.error('Error fetching notification preferences:', error);
return;
}
-
if (data) {
if (data.email_notifications) {
setEmailNotifications(data.email_notifications as unknown as EmailNotifications);
@@ -75,49 +70,46 @@ export function NotificationsTab() {
console.error('Error fetching notification preferences:', error);
}
};
-
const initializePreferences = async () => {
if (!user) return;
-
try {
- const { error } = await supabase
- .from('user_preferences')
- .insert([{
- user_id: user.id,
- email_notifications: emailNotifications as any,
- push_notifications: pushNotifications as any
- }]);
-
+ const {
+ error
+ } = await supabase.from('user_preferences').insert([{
+ user_id: user.id,
+ email_notifications: emailNotifications as any,
+ push_notifications: pushNotifications as any
+ }]);
if (error) throw error;
} catch (error) {
console.error('Error initializing preferences:', error);
}
};
-
const updateEmailNotification = (key: keyof EmailNotifications, value: boolean) => {
- setEmailNotifications(prev => ({ ...prev, [key]: value }));
+ setEmailNotifications(prev => ({
+ ...prev,
+ [key]: value
+ }));
};
-
const updatePushNotification = (key: keyof PushNotifications, value: boolean) => {
- setPushNotifications(prev => ({ ...prev, [key]: value }));
+ setPushNotifications(prev => ({
+ ...prev,
+ [key]: value
+ }));
};
-
const saveNotificationPreferences = async () => {
if (!user) return;
-
setLoading(true);
try {
- const { error } = await supabase
- .from('user_preferences')
- .upsert([{
- user_id: user.id,
- email_notifications: emailNotifications as any,
- push_notifications: pushNotifications as any,
- updated_at: new Date().toISOString()
- }]);
-
+ const {
+ error
+ } = await supabase.from('user_preferences').upsert([{
+ user_id: user.id,
+ email_notifications: emailNotifications as any,
+ push_notifications: pushNotifications as any,
+ updated_at: new Date().toISOString()
+ }]);
if (error) throw error;
-
toast({
title: 'Preferences saved',
description: 'Your notification preferences have been updated.'
@@ -132,7 +124,6 @@ export function NotificationsTab() {
setLoading(false);
}
};
-
const requestPushPermission = async () => {
if ('Notification' in window) {
const permission = await Notification.requestPermission();
@@ -151,9 +142,7 @@ export function NotificationsTab() {
}
}
};
-
- return (
-
+ return
{/* Email Notifications */}
@@ -175,10 +164,7 @@ export function NotificationsTab() {
Get notified when someone replies to your reviews
-
updateEmailNotification('review_replies', checked)}
- />
+ updateEmailNotification('review_replies', checked)} />
@@ -188,10 +174,7 @@ export function NotificationsTab() {
Get notified when someone follows you
-
updateEmailNotification('new_followers', checked)}
- />
+ updateEmailNotification('new_followers', checked)} />
@@ -201,10 +184,7 @@ export function NotificationsTab() {
Important updates and announcements from ThrillWiki
-
updateEmailNotification('system_announcements', checked)}
- />
+ updateEmailNotification('system_announcements', checked)} />
@@ -216,10 +196,7 @@ export function NotificationsTab() {
Weekly summary of new parks, rides, and community activity
- updateEmailNotification('weekly_digest', checked)}
- />
+ updateEmailNotification('weekly_digest', checked)} />
@@ -229,10 +206,7 @@ export function NotificationsTab() {
Monthly roundup of popular content and your activity stats
- updateEmailNotification('monthly_digest', checked)}
- />
+ updateEmailNotification('monthly_digest', checked)} />
@@ -262,30 +236,20 @@ export function NotificationsTab() {
- {!pushNotifications.browser_enabled && (
- }
+ {
+ if (!checked) {
+ updatePushNotification('browser_enabled', false);
+ } else {
+ requestPushPermission();
+ }
+ }} />
- {pushNotifications.browser_enabled && (
- <>
+ {pushNotifications.browser_enabled && <>
@@ -293,10 +257,7 @@ export function NotificationsTab() {
Notifications about new parks, rides, and reviews
-
updatePushNotification('new_content', checked)}
- />
+ updatePushNotification('new_content', checked)} />
@@ -306,43 +267,17 @@ export function NotificationsTab() {
Notifications about followers, replies, and mentions
- updatePushNotification('social_updates', checked)}
- />
+ updatePushNotification('social_updates', checked)} />
- >
- )}
+ >}
-
+
{/* Sound Settings */}
-
-
-
-
Sound Settings
-
-
-
-
-
- Configure sound preferences for notifications and interactions.
-
-
-
-
-
-
Sound settings coming soon
-
- Configure notification sounds and interaction feedback.
-
-
-
-
-
+
{/* Save Button */}
@@ -350,6 +285,5 @@ export function NotificationsTab() {
{loading ? 'Saving...' : 'Save Notification Preferences'}
-
- );
+ ;
}
\ No newline at end of file