forked from wrenn/wrenn
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.
32 lines
668 B
TypeScript
32 lines
668 B
TypeScript
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();
|