feat(dashboard): add isReader flag + reader branch to page load

Read-only users (no WRITE_ALL or ANNOTATE_ALL) now receive lean reader
data (stats, top-4 persons, 5 recent docs, 3 recent stories, and drafts
when BLOG_WRITE) instead of the contributor transcription queues.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-07 19:04:04 +02:00
committed by marcel
parent 6a46a1e3eb
commit a58e796ffa
2 changed files with 247 additions and 11 deletions

View File

@@ -9,8 +9,13 @@ type DashboardResumeDTO = components['schemas']['DashboardResumeDTO'];
type DashboardPulseDTO = components['schemas']['DashboardPulseDTO'];
type ActivityFeedItemDTO = components['schemas']['ActivityFeedItemDTO'];
type IncompleteDocumentDTO = components['schemas']['IncompleteDocumentDTO'];
type PersonSummaryDTO = components['schemas']['PersonSummaryDTO'];
type Document = components['schemas']['Document'];
type Geschichte = components['schemas']['Geschichte'];
export async function load({ fetch }) {
export async function load({ fetch, parent }) {
const { canWrite, canAnnotate, canBlogWrite } = await parent();
const isReader = !canWrite && !canAnnotate;
const api = createApiClient(fetch);
try {
@@ -20,6 +25,73 @@ export async function load({ fetch }) {
throw redirect(302, '/login');
}
if (isReader) {
const readerFetches: Promise<unknown>[] = [
api.GET('/api/stats'),
api.GET('/api/persons', { params: { query: { size: 4, sort: 'documentCount' } } }),
api.GET('/api/documents', {
params: { query: { sort: 'UPDATED_AT', dir: 'DESC', size: 5 } }
}),
api.GET('/api/geschichten', { params: { query: { status: 'PUBLISHED', limit: 3 } } })
];
if (canBlogWrite) {
readerFetches.push(
api.GET('/api/geschichten', { params: { query: { status: 'DRAFT', limit: 10 } } })
);
}
const [statsRes, topPersonsRes, recentDocsRes, recentStoriesRes, draftsRes] =
await Promise.allSettled(readerFetches);
let readerStats: StatsDTO | null = null;
let topPersons: PersonSummaryDTO[] = [];
let recentDocs: Document[] = [];
let recentStories: Geschichte[] = [];
let drafts: Geschichte[] = [];
if (
statsRes?.status === 'fulfilled' &&
(statsRes.value as { response: Response }).response.ok
) {
readerStats = ((statsRes.value as { data: unknown }).data as StatsDTO) ?? null;
}
if (
topPersonsRes?.status === 'fulfilled' &&
(topPersonsRes.value as { response: Response }).response.ok
) {
topPersons = ((topPersonsRes.value as { data: unknown }).data as PersonSummaryDTO[]) ?? [];
}
if (
recentDocsRes?.status === 'fulfilled' &&
(recentDocsRes.value as { response: Response }).response.ok
) {
recentDocs = ((recentDocsRes.value as { data: unknown }).data as Document[]) ?? [];
}
if (
recentStoriesRes?.status === 'fulfilled' &&
(recentStoriesRes.value as { response: Response }).response.ok
) {
recentStories = ((recentStoriesRes.value as { data: unknown }).data as Geschichte[]) ?? [];
}
if (
draftsRes?.status === 'fulfilled' &&
(draftsRes.value as { response: Response }).response.ok
) {
drafts = ((draftsRes.value as { data: unknown }).data as Geschichte[]) ?? [];
}
return {
isReader: true as const,
canBlogWrite,
readerStats,
topPersons,
recentDocs,
recentStories,
drafts,
error: null as string | null
};
}
const [
statsResult,
resumeResult,
@@ -87,6 +159,7 @@ export async function load({ fetch }) {
}
return {
isReader: false as const,
stats,
resumeDoc,
pulse,
@@ -103,6 +176,7 @@ export async function load({ fetch }) {
if ((e as { status?: number }).status) throw e;
console.error('Error loading data:', e);
return {
isReader,
stats: null,
resumeDoc: null,
pulse: null,
@@ -113,6 +187,11 @@ export async function load({ fetch }) {
weeklyStats: null,
incompleteDocs: [] as IncompleteDocumentDTO[],
incompleteTotal: 0,
readerStats: null,
topPersons: [] as PersonSummaryDTO[],
recentDocs: [] as Document[],
recentStories: [] as Geschichte[],
drafts: [] as Geschichte[],
error: 'Daten konnten nicht geladen werden.' as string | null
};
}