1
0
forked from wrenn/wrenn

Fix team name blink on navigation by lifting teams into a singleton store

Teams list was fetched on every Sidebar mount (each page navigation),
causing a flash from '…' to the real name on every tab switch. Move teams
into a module-level reactive store (teams.svelte.ts) that fetches once per
session and is shared between Sidebar and the team page.
This commit is contained in:
2026-03-24 14:44:09 +06:00
parent 71a7fdb76f
commit bf494f73fc
3 changed files with 40 additions and 17 deletions

View File

@ -17,9 +17,9 @@
searchUsers,
type TeamInfo,
type TeamMember,
type TeamWithRole,
type UserSearchResult
} from '$lib/api/team';
import { teams as teamsStore } from '$lib/teams.svelte';
let collapsed = $state(
typeof window !== 'undefined'
@ -30,12 +30,11 @@
// Page data
let team = $state<TeamInfo | null>(null);
let members = $state<TeamMember[]>([]);
let allTeams = $state<TeamWithRole[]>([]);
let loading = $state(true);
let error = $state<string | null>(null);
// True when this is the user's only team — deleting/leaving would leave them teamless
let isLastTeam = $derived(allTeams.length <= 1);
let isLastTeam = $derived(teamsStore.list.length <= 1);
// Current user's role — derived from members list
let myRole = $derived(members.find((m) => m.user_id === auth.userId)?.role ?? 'member');
@ -86,9 +85,9 @@
loading = false;
return;
}
const [teamResult, teamsResult] = await Promise.all([
const [teamResult] = await Promise.all([
getTeam(auth.teamId),
listTeams()
teamsStore.fetch()
]);
if (teamResult.ok) {
team = teamResult.data.team;
@ -96,9 +95,6 @@
} else {
error = teamResult.error;
}
if (teamsResult.ok) {
allTeams = teamsResult.data;
}
loading = false;
}