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

@ -0,0 +1,31 @@
import { listTeams, type TeamWithRole } from '$lib/api/team';
function createTeamsStore() {
let teams = $state<TeamWithRole[]>([]);
let loaded = $state(false);
return {
get list() {
return teams;
},
get loaded() {
return loaded;
},
async fetch() {
if (loaded) return;
const result = await listTeams();
if (result.ok) {
teams = result.data;
loaded = true;
}
},
// Call after mutating teams (create/switch triggers a full reload, but
// adding a team locally avoids a flicker in the popover list).
set(newTeams: TeamWithRole[]) {
teams = newTeams;
loaded = true;
}
};
}
export const teams = createTeamsStore();