mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 13:31:14 -05:00
Reverted to commit 06ed528d76
This commit is contained in:
16
src/App.tsx
16
src/App.tsx
@@ -44,20 +44,12 @@ import BlogIndex from "./pages/BlogIndex";
|
|||||||
import BlogPost from "./pages/BlogPost";
|
import BlogPost from "./pages/BlogPost";
|
||||||
import AdminBlog from "./pages/AdminBlog";
|
import AdminBlog from "./pages/AdminBlog";
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient();
|
||||||
defaultOptions: {
|
|
||||||
queries: {
|
|
||||||
refetchOnWindowFocus: false, // Don't refetch when switching back to tab
|
|
||||||
refetchOnMount: true, // Still refetch on component mount
|
|
||||||
refetchOnReconnect: true, // Refetch when internet reconnects
|
|
||||||
staleTime: 60000, // Consider data fresh for 60 seconds
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
function AppContent() {
|
function AppContent() {
|
||||||
return (
|
return (
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
|
<LocationAutoDetectProvider />
|
||||||
<BrowserRouter
|
<BrowserRouter
|
||||||
future={{
|
future={{
|
||||||
v7_startTransition: true,
|
v7_startTransition: true,
|
||||||
@@ -118,9 +110,7 @@ function AppContent() {
|
|||||||
const App = () => (
|
const App = () => (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<LocationAutoDetectProvider>
|
<AppContent />
|
||||||
<AppContent />
|
|
||||||
</LocationAutoDetectProvider>
|
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -130,7 +130,6 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
const isMountingRef = useRef(true);
|
const isMountingRef = useRef(true);
|
||||||
const initialFetchCompleteRef = useRef(false);
|
const initialFetchCompleteRef = useRef(false);
|
||||||
const FETCH_COOLDOWN_MS = 1000;
|
const FETCH_COOLDOWN_MS = 1000;
|
||||||
const isPageVisible = useRef(true);
|
|
||||||
|
|
||||||
// Pagination state
|
// Pagination state
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
@@ -213,34 +212,8 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
}
|
}
|
||||||
}, [loadingState, items.length, hasRenderedOnce]);
|
}, [loadingState, items.length, hasRenderedOnce]);
|
||||||
|
|
||||||
// Track page visibility to prevent tab-switch refreshes
|
|
||||||
useEffect(() => {
|
|
||||||
const handleVisibilityChange = () => {
|
|
||||||
const wasHidden = !isPageVisible.current;
|
|
||||||
isPageVisible.current = !document.hidden;
|
|
||||||
|
|
||||||
if (wasHidden && isPageVisible.current) {
|
|
||||||
console.log('📄 Page became visible - NOT auto-refreshing queue');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
||||||
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const fetchItems = useCallback(async (entityFilter: EntityFilter = 'all', statusFilter: StatusFilter = 'pending', silent = false, tab: QueueTab = 'mainQueue') => {
|
const fetchItems = useCallback(async (entityFilter: EntityFilter = 'all', statusFilter: StatusFilter = 'pending', silent = false, tab: QueueTab = 'mainQueue') => {
|
||||||
console.log('🔍 fetchItems called:', {
|
|
||||||
hasUser: !!userRef.current,
|
|
||||||
entityFilter,
|
|
||||||
statusFilter,
|
|
||||||
silent,
|
|
||||||
tab,
|
|
||||||
loadingState,
|
|
||||||
timestamp: new Date().toISOString()
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!userRef.current) {
|
if (!userRef.current) {
|
||||||
console.warn('⚠️ fetchItems: No user available yet, cannot fetch');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,12 +223,6 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip fetch if triggered during tab visibility change (unless manual refresh)
|
|
||||||
if (!silent && !isPageVisible.current) {
|
|
||||||
console.log('👁️ Skipping fetch while page is hidden');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cooldown check - prevent rapid-fire calls
|
// Cooldown check - prevent rapid-fire calls
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const timeSinceLastFetch = now - lastFetchTimeRef.current;
|
const timeSinceLastFetch = now - lastFetchTimeRef.current;
|
||||||
@@ -773,28 +740,15 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
|
|
||||||
// Initial fetch on mount and filter changes
|
// Initial fetch on mount and filter changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('🎯 Initial fetch effect:', {
|
if (!user) return;
|
||||||
hasUser: !!user,
|
|
||||||
loadingState,
|
|
||||||
hasInitialFetchRef: hasInitialFetchRef.current,
|
|
||||||
initialFetchComplete: initialFetchCompleteRef.current,
|
|
||||||
isMounting: isMountingRef.current
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
console.log('⏳ Waiting for user to be available...');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Phase 1: Initial fetch (run once)
|
// Phase 1: Initial fetch (run once)
|
||||||
if (!hasInitialFetchRef.current) {
|
if (!hasInitialFetchRef.current) {
|
||||||
console.log('✅ Triggering initial fetch');
|
|
||||||
hasInitialFetchRef.current = true;
|
hasInitialFetchRef.current = true;
|
||||||
isMountingRef.current = true;
|
isMountingRef.current = true;
|
||||||
|
|
||||||
fetchItems(debouncedEntityFilter, debouncedStatusFilter, false)
|
fetchItems(debouncedEntityFilter, debouncedStatusFilter, false)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('✅ Initial fetch complete');
|
|
||||||
initialFetchCompleteRef.current = true;
|
initialFetchCompleteRef.current = true;
|
||||||
// Wait for DOM to paint before allowing subsequent fetches
|
// Wait for DOM to paint before allowing subsequent fetches
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
@@ -806,7 +760,6 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
|
|
||||||
// Phase 2: Filter changes (only after initial fetch completes)
|
// Phase 2: Filter changes (only after initial fetch completes)
|
||||||
if (!isMountingRef.current && initialFetchCompleteRef.current) {
|
if (!isMountingRef.current && initialFetchCompleteRef.current) {
|
||||||
console.log('🔄 Filter changed, fetching with debounce');
|
|
||||||
debouncedFetchItems(debouncedEntityFilter, debouncedStatusFilter, true, activeTab);
|
debouncedFetchItems(debouncedEntityFilter, debouncedStatusFilter, true, activeTab);
|
||||||
}
|
}
|
||||||
}, [debouncedEntityFilter, debouncedStatusFilter, user, activeTab, fetchItems, debouncedFetchItems]);
|
}, [debouncedEntityFilter, debouncedStatusFilter, user, activeTab, fetchItems, debouncedFetchItems]);
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import { ReactNode } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useLocationAutoDetect } from '@/hooks/useLocationAutoDetect';
|
import { useLocationAutoDetect } from '@/hooks/useLocationAutoDetect';
|
||||||
|
|
||||||
interface LocationAutoDetectProviderProps {
|
export function LocationAutoDetectProvider() {
|
||||||
children?: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function LocationAutoDetectProvider({ children }: LocationAutoDetectProviderProps) {
|
|
||||||
useLocationAutoDetect();
|
useLocationAutoDetect();
|
||||||
return <>{children}</>;
|
return null; // This component doesn't render anything, just runs the hook
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,6 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
|||||||
} else {
|
} else {
|
||||||
setSession(session);
|
setSession(session);
|
||||||
setUser(session?.user ?? null);
|
setUser(session?.user ?? null);
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track pending email changes
|
// Track pending email changes
|
||||||
|
|||||||
Reference in New Issue
Block a user