AnayShukla commited on
Commit
ec71c8a
·
1 Parent(s): 418395e
Files changed (1) hide show
  1. frontend/src/components/Solver.jsx +15 -4
frontend/src/components/Solver.jsx CHANGED
@@ -343,11 +343,19 @@ export default function Solver() {
343
  return () => { clearInterval(id); document.body.style.overflow = prev; };
344
  }, [isSolving]);
345
 
 
 
346
  useEffect(() => {
347
- if (isLoggedIn && userProfile.defaultTeamId && String(userProfile.defaultTeamId) === String(teamId) && availableGWs.length === 0 && !isLoading) {
348
- fetchTeam(null, teamData.length > 0);
 
 
 
349
  }
350
- }, [isLoggedIn, userProfile.defaultTeamId, teamId, availableGWs.length, teamData.length]);
 
 
 
351
 
352
  const fetchTeam = async (e, preserveState = false) => {
353
  // If manually clicked by user, always wipe the slate clean
@@ -356,7 +364,10 @@ export default function Solver() {
356
  if (!teamId) return;
357
  setIsLoading(true); setError(null);
358
  try {
359
- const res = await fetch(`https://anayshukla-fpl-solver.hf.space/api/manager/${teamId}`);
 
 
 
360
  if (!res.ok) throw new Error("Could not fetch team.");
361
  const data = await res.json();
362
 
 
343
  return () => { clearInterval(id); document.body.style.overflow = prev; };
344
  }, [isSolving]);
345
 
346
+ const hasAutoLoadedAfterLogin = useRef(false);
347
+
348
  useEffect(() => {
349
+ if (isLoggedIn && userProfile.defaultTeamId && String(userProfile.defaultTeamId) === String(teamId) && !isLoading) {
350
+ if (!hasAutoLoadedAfterLogin.current) {
351
+ hasAutoLoadedAfterLogin.current = true;
352
+ fetchTeam(null, teamData.length > 0);
353
+ }
354
  }
355
+ if (!isLoggedIn) {
356
+ hasAutoLoadedAfterLogin.current = false; // reset on logout
357
+ }
358
+ }, [isLoggedIn, userProfile.defaultTeamId, teamId]);
359
 
360
  const fetchTeam = async (e, preserveState = false) => {
361
  // If manually clicked by user, always wipe the slate clean
 
364
  if (!teamId) return;
365
  setIsLoading(true); setError(null);
366
  try {
367
+ const token = localStorage.getItem('fpl_token');
368
+ const res = await fetch(`https://anayshukla-fpl-solver.hf.space/api/manager/${teamId}`, {
369
+ headers: token ? { 'Authorization': `Bearer ${token}` } : {}
370
+ });
371
  if (!res.ok) throw new Error("Could not fetch team.");
372
  const data = await res.json();
373