Site seems to be working completely now!

This commit is contained in:
2025-06-13 14:43:18 -05:00
parent 89955367aa
commit f456e05a05
3 changed files with 63 additions and 14 deletions

View File

@ -102,7 +102,6 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
useEffect(() => { useEffect(() => {
const supabase = createClient(); const supabase = createClient();
// Initial fetch with loading // Initial fetch with loading
fetchUserData(true).catch((error) => { fetchUserData(true).catch((error) => {
console.error('💥 Initial fetch error:', error); console.error('💥 Initial fetch error:', error);
@ -111,8 +110,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
const { const {
data: { subscription }, data: { subscription },
} = supabase.auth.onAuthStateChange(async (event, _session) => { } = supabase.auth.onAuthStateChange(async (event, _session) => {
console.log('Auth state change:', event); // Debug log
console.log('Auth state change:', event); // Debug log
if (event === 'SIGNED_IN') { if (event === 'SIGNED_IN') {
// Background refresh without loading state // Background refresh without loading state
await fetchUserData(false); await fetchUserData(false);
@ -126,12 +125,53 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
await fetchUserData(false); await fetchUserData(false);
} }
}); });
return () => { return () => {
subscription.unsubscribe(); subscription.unsubscribe();
}; };
}, [fetchUserData]); }, [fetchUserData]);
useEffect(() => {
const supabase = createClient();
// Handle visibility changes (tab switching)
const handleVisibilityChange = () => {
if (!document.hidden && isInitialized) {
// Refresh auth state when tab becomes visible
fetchUserData(false).catch(console.error);
}
};
document.addEventListener('visibilitychange', handleVisibilityChange);
// Initial fetch with loading
fetchUserData(true).catch((error) => {
console.error('💥 Initial fetch error:', error);
});
const {
data: { subscription },
} = supabase.auth.onAuthStateChange(async (event, session) => {
console.log('Auth state change:', event, session?.expires_at);
if (event === 'SIGNED_IN') {
await fetchUserData(false);
} else if (event === 'SIGNED_OUT') {
setUser(null);
setProfile(null);
setAvatarUrl(null);
setIsLoading(false);
} else if (event === 'TOKEN_REFRESHED') {
console.log('Token refreshed, updating user data');
await fetchUserData(false);
}
});
return () => {
document.removeEventListener('visibilitychange', handleVisibilityChange);
subscription.unsubscribe();
};
}, [fetchUserData, isInitialized]);
const updateProfile = useCallback( const updateProfile = useCallback(
async (data: { async (data: {
full_name?: string; full_name?: string;

View File

@ -7,12 +7,14 @@ import { Loader2 } from 'lucide-react';
type Props = ComponentProps<typeof Button> & { type Props = ComponentProps<typeof Button> & {
disabled?: boolean; disabled?: boolean;
disabledNotLoading?: boolean;
pendingText?: string; pendingText?: string;
}; };
export const SubmitButton = ({ export const SubmitButton = ({
children, children,
disabled = false, disabled = false,
disabledNotLoading = false,
pendingText = 'Submitting...', pendingText = 'Submitting...',
...props ...props
}: Props) => { }: Props) => {
@ -26,7 +28,7 @@ export const SubmitButton = ({
disabled={disabled} disabled={disabled}
{...props} {...props}
> >
{pending || disabled ? ( {pending || (disabled && !disabledNotLoading) ? (
<> <>
<Loader2 className='mr-2 h-4 w-4 animate-spin' /> <Loader2 className='mr-2 h-4 w-4 animate-spin' />
{pendingText} {pendingText}

View File

@ -8,8 +8,9 @@ import {
updateStatuses, updateStatuses,
updateUserStatus, updateUserStatus,
type UserWithStatus, type UserWithStatus,
} from '@/lib/hooks/status'; } from '@/lib/hooks';
import { Drawer, DrawerTrigger, Loading } from '@/components/ui'; import { Drawer, DrawerTrigger, Loading } from '@/components/ui';
import { SubmitButton } from '@/components/default';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { HistoryDrawer } from '@/components/status'; import { HistoryDrawer } from '@/components/status';
import type { Profile } from '@/utils/supabase'; import type { Profile } from '@/utils/supabase';
@ -115,6 +116,13 @@ export const TechTable = ({
useEffect(() => { useEffect(() => {
if (!isAuthenticated) return; if (!isAuthenticated) return;
//if (channelRef.current) {
//const supabase = createClient();
//supabase.removeChannel(channelRef.current).catch((error) => {
//console.error(`Error unsubscribing from status updates: ${error}`);
//});
//channelRef.current = null;
//}
const supabase = createClient(); const supabase = createClient();
const channel = supabase const channel = supabase
@ -284,20 +292,19 @@ export const TechTable = ({
} }
}} }}
/> />
<button <SubmitButton
type='submit' size='xl'
className={ className={
'min-w-[100px] lg:min-w-[160px] py-2 px-4 rounded-xl \ 'px-8 rounded-xl font-semibold lg:text-2xl \
text-center font-semibold lg:text-2xl bg-primary \ disabled:opacity-50 disabled:cursor-not-allowed \
text-primary-foreground hover:bg-primary/90 \ cursor-pointer'
transition-colors disabled:opacity-50 \
disabled:cursor-not-allowed'
} }
onClick={() => void updateStatus()} onClick={() => updateStatus()}
disabled={!statusInput.trim()} disabled={!statusInput.trim()}
disabledNotLoading={true}
> >
Update Update
</button> </SubmitButton>
</div> </div>
)} )}
</div> </div>