fix: improve team selection logic and prevent duplicate fetches
- Enhanced GlobalTaskDetailDialog to handle loading states more effectively, preventing unnecessary re-fetching of team data. - Updated selectTeam function in teamSlice to guard against duplicate in-flight fetches for the same team, improving performance and user experience. - Refactored dependencies in useEffect to ensure proper data loading behavior.
This commit is contained in:
parent
b346fd319d
commit
0f302521e4
2 changed files with 24 additions and 2 deletions
|
|
@ -44,9 +44,25 @@ export const GlobalTaskDetailDialog = (): React.JSX.Element | null => {
|
|||
// Load full team data in the background to enable "as before" details (logs/changes/members).
|
||||
useEffect(() => {
|
||||
if (!globalTaskDetail) return;
|
||||
if (selectedTeamName === teamName && selectedTeamData) return;
|
||||
if (!teamName) return;
|
||||
|
||||
// Avoid re-triggering selectTeam in a loop while the fetch is in flight.
|
||||
// selectedTeamName is set immediately by selectTeam(), but selectedTeamData
|
||||
// remains null until IPC resolves.
|
||||
if (selectedTeamName === teamName) {
|
||||
if (selectedTeamData || selectedTeamLoading) return;
|
||||
// Retry once if we are on the right team but have no data and not loading (e.g. prior error).
|
||||
}
|
||||
|
||||
void selectTeam(teamName, { skipProjectAutoSelect: true });
|
||||
}, [globalTaskDetail, selectTeam, selectedTeamData, selectedTeamName, teamName]);
|
||||
}, [
|
||||
globalTaskDetail,
|
||||
selectTeam,
|
||||
selectedTeamData,
|
||||
selectedTeamLoading,
|
||||
selectedTeamName,
|
||||
teamName,
|
||||
]);
|
||||
|
||||
const isFullTeamLoaded = selectedTeamName === teamName && !!selectedTeamData;
|
||||
|
||||
|
|
|
|||
|
|
@ -354,6 +354,12 @@ export const createTeamSlice: StateCreator<AppState, [], [], TeamSlice> = (set,
|
|||
},
|
||||
|
||||
selectTeam: async (teamName: string, opts) => {
|
||||
// Guard: prevent duplicate in-flight fetches for the same team.
|
||||
// GlobalTaskDetailDialog + tab navigation can call selectTeam() in quick succession.
|
||||
if (get().selectedTeamLoading && get().selectedTeamName === teamName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear stale data immediately to prevent flash of previous team's content
|
||||
const prev = get().selectedTeamName;
|
||||
set({
|
||||
|
|
|
|||
Loading…
Reference in a new issue