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:
31
frontend/src/lib/teams.svelte.ts
Normal file
31
frontend/src/lib/teams.svelte.ts
Normal 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();
|
||||
Reference in New Issue
Block a user