You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async (event) => {
|
|
const res = await event.fetch('/api/me/groups', { headers: { 'cache-control': 'no-store' } });
|
|
if (!res.ok) {
|
|
// El gate del layout debería impedir llegar aquí sin sesión; devolvemos vacío como salvaguarda.
|
|
return { groups: [], previews: {} };
|
|
}
|
|
const data = await res.json();
|
|
const groups = Array.isArray(data?.items) ? data.items : [];
|
|
|
|
// Prefetch de "sin responsable" por grupo (ligero)
|
|
const previews: Record<string, any[]> = {};
|
|
const previewLimit = 3;
|
|
|
|
for (const g of groups) {
|
|
try {
|
|
const r = await event.fetch(
|
|
`/api/groups/${encodeURIComponent(g.id)}/tasks?unassignedFirst=true&onlyUnassigned=true&limit=${previewLimit}`,
|
|
{ headers: { 'cache-control': 'no-store' } }
|
|
);
|
|
if (r.ok) {
|
|
const j = await r.json();
|
|
previews[String(g.id)] = Array.isArray(j?.items) ? j.items : [];
|
|
}
|
|
} catch {
|
|
// ignorar errores de un grupo y continuar
|
|
}
|
|
}
|
|
|
|
return { groups, previews };
|
|
};
|