// State shared between views: who is signed in, the user list, and the open // queue that drives the badges. import * as api from './api.js'; export const state = { me: null, // { user, has_password } // How the server can be signed in to. The defaults are an older server's // answer: passwords, no single sign-on. auth: { password_login: true, oidc: { enabled: false, name: '' } }, open: [], // the default queue: open, not snoozed teams: [], // the teams the viewer belongs to, each with their role }; // The team whose schedule and settings the views act on. A viewer in one team — // which is everybody until somebody makes a second — never has to choose. export function currentTeam() { return state.teams[0] || null; } export function myID() { return state.me ? state.me.user.id : null; } // The user list changes rarely; it is fetched once and then at most every // five minutes, for the assign sheet and for display names. let usersCache = null; let usersAt = 0; export async function users() { if (!usersCache || Date.now() - usersAt > 5 * 60 * 1000) { usersCache = await api.users(); usersAt = Date.now(); } return usersCache; } export async function loadTeams() { state.teams = await api.teams(); return state.teams; } export function reset() { state.me = null; state.open = []; state.teams = []; usersCache = null; }