[dyad] Fixed auth loading state and moderation queue refresh issues - wrote 3 file(s) + extra files edited outside of Dyad

This commit is contained in:
pacnpal
2025-10-12 11:17:24 -04:00
parent 3d14393df9
commit 472813d1ea
3 changed files with 6956 additions and 87 deletions

6945
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -936,40 +936,14 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
locked_until: submission.locked_until || undefined, locked_until: submission.locked_until || undefined,
}; };
// Check auto-refresh strategy // Add to pending items
const strategy = refreshStrategyRef.current; setPendingNewItems(prev => {
if (prev.some(p => p.id === fullItem.id)) return prev;
if (strategy === 'notify') { return [...prev, fullItem];
console.log('📢 NEW submission detected - showing notification only (strategy: notify)');
toast({
title: '🆕 New Submission',
description: `${fullItem.submission_type} - ${fullItem.entity_name}`,
action: (
<Button size="sm" onClick={() => {
setItems(prev => [fullItem, ...prev]);
setNewItemsCount(prev => Math.max(0, prev - 1));
}}>
Show
</Button>
),
}); });
setNewItemsCount(prev => prev + 1); setNewItemsCount(prev => prev + 1);
return; // Don't add to queue
}
if (strategy === 'replace') { // Toast notification
console.log('🔄 NEW submission detected - full replacement (strategy: replace)');
toast({
title: '🆕 New Submission',
description: 'Refreshing queue...',
});
fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current);
return;
}
// strategy === 'merge' (default behavior - seamlessly add to existing list)
console.log(' NEW submission detected - merging into queue (strategy: merge)');
setItems(prev => [fullItem, ...prev]);
toast({ toast({
title: '🆕 New Submission', title: '🆕 New Submission',
description: `${fullItem.submission_type} - ${fullItem.entity_name}`, description: `${fullItem.submission_type} - ${fullItem.entity_name}`,
@@ -1164,50 +1138,6 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
} }
console.log('🔄 Realtime UPDATE: Changes detected for', fullItem.id); console.log('🔄 Realtime UPDATE: Changes detected for', fullItem.id);
// Check auto-refresh strategy
const strategy = refreshStrategyRef.current;
if (strategy === 'notify') {
console.log('📢 UPDATE detected - showing notification only (strategy: notify)');
toastRef.current({
title: '🔄 Submission Updated',
description: `Submission has been updated`,
action: (
<Button size="sm" onClick={() => {
setItems(prevItems => prevItems.map(item => {
if (item.id !== fullItem.id) return item;
const updates: Partial<ModerationItem> = {};
if (item.status !== fullItem.status) updates.status = fullItem.status;
if (item.reviewed_at !== fullItem.reviewed_at) updates.reviewed_at = fullItem.reviewed_at;
if (item.reviewer_notes !== fullItem.reviewer_notes) updates.reviewer_notes = fullItem.reviewer_notes;
if (item.assigned_to !== fullItem.assigned_to) updates.assigned_to = fullItem.assigned_to;
if (item.locked_until !== fullItem.locked_until) updates.locked_until = fullItem.locked_until;
if (item.escalated !== fullItem.escalated) updates.escalated = fullItem.escalated;
if (contentChanged) updates.content = fullItem.content;
if (fullItem.submission_items) updates.submission_items = fullItem.submission_items;
return Object.keys(updates).length > 0 ? { ...item, ...updates } : item;
}));
}}>
Refresh
</Button>
),
});
return prev; // Don't update queue
}
if (strategy === 'replace') {
console.log('🔄 UPDATE detected - full replacement (strategy: replace)');
toastRef.current({
title: '🔄 Submission Updated',
description: 'Refreshing queue...',
});
fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current);
return prev;
}
// strategy === 'merge' (default - seamlessly update in place)
console.log('🔄 Realtime UPDATE: Merging changes (strategy: merge)');
// Update ONLY changed fields to preserve object stability // Update ONLY changed fields to preserve object stability
return prev.map(i => { return prev.map(i => {
if (i.id !== fullItem.id) return i; if (i.id !== fullItem.id) return i;
@@ -1252,18 +1182,16 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
console.log('📴 Tab hidden - pausing queue updates'); console.log('📴 Tab hidden - pausing queue updates');
pauseFetchingRef.current = true; pauseFetchingRef.current = true;
} else { } else {
console.log('📱 Tab visible - checking admin settings'); console.log('📱 Tab visible - resuming queue updates');
pauseFetchingRef.current = false;
// Check admin setting for auto-refresh behavior // Check admin setting for auto-refresh behavior
const shouldRefresh = refreshOnTabVisibleRef.current; const shouldRefresh = refreshOnTabVisibleRef.current;
if (shouldRefresh && initialFetchCompleteRef.current && !isMountingRef.current) { if (shouldRefresh && initialFetchCompleteRef.current && !isMountingRef.current) {
console.log('🔄 Tab became visible - triggering refresh (setting enabled)'); console.log('🔄 Tab became visible - triggering refresh (admin setting enabled)');
pauseFetchingRef.current = false; // Only unpause when refreshing
fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current); fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current);
} else { } else {
console.log('⛔ Tab became visible - refresh BLOCKED by admin settings (keeping fetch paused)');
// Keep pauseFetchingRef.current = true to prevent ANY mechanism from triggering fetches
console.log('✅ Tab became visible - resuming without refresh'); console.log('✅ Tab became visible - resuming without refresh');
// Realtime subscriptions will handle updates naturally // Realtime subscriptions will handle updates naturally
} }

View File

@@ -135,11 +135,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
if (!user && isMountedRef.current) { if (!user && isMountedRef.current) {
setSession(session); setSession(session);
setUser(session.user); setUser(session.user);
fetchProfile(session.user.id, 0, () => { sessionVerifiedRef.current = true;
if (updateLoadingState && isMountedRef.current) {
setLoading(false);
}
});
} else if (updateLoadingState && isMountedRef.current) { } else if (updateLoadingState && isMountedRef.current) {
setLoading(false); setLoading(false);
} }