diff --git a/apps/web/src/lib/api/inbox.ts b/apps/web/src/lib/api/inbox.ts new file mode 100644 index 0000000..f075309 --- /dev/null +++ b/apps/web/src/lib/api/inbox.ts @@ -0,0 +1,23 @@ +import type { Deck } from '@cards/domain'; +import { listDecks } from './decks.ts'; +import { listCards } from './cards.ts'; + +const INBOX_NAME = 'Inbox'; + +export interface InboxStats { + deck: Deck | null; + cardCount: number; +} + +/** + * Lädt das Inbox-Deck (Name = "Inbox", auto-erzeugt vom API beim + * ersten Share-Receive) und zählt die Karten darin. Liefert ein + * neutrales Result, wenn der User noch keinen Share empfangen hat. + */ +export async function loadInboxStats(): Promise { + const decks = await listDecks(); + const inbox = decks.decks.find((d) => d.name === INBOX_NAME) ?? null; + if (!inbox) return { deck: null, cardCount: 0 }; + const cards = await listCards(inbox.id); + return { deck: inbox, cardCount: cards.total }; +} diff --git a/apps/web/src/lib/components/InboxBanner.svelte b/apps/web/src/lib/components/InboxBanner.svelte new file mode 100644 index 0000000..df5a0dc --- /dev/null +++ b/apps/web/src/lib/components/InboxBanner.svelte @@ -0,0 +1,30 @@ + + +{#if stats && stats.deck && stats.cardCount > 0} + + 📥 Inbox + · + + {stats.cardCount} eingegangene + {stats.cardCount === 1 ? 'Karte' : 'Karten'} aus anderen Apps + + — sortieren → + +{/if} diff --git a/apps/web/src/routes/decks/+page.svelte b/apps/web/src/routes/decks/+page.svelte index 35004a5..5837ce9 100644 --- a/apps/web/src/routes/decks/+page.svelte +++ b/apps/web/src/routes/decks/+page.svelte @@ -5,6 +5,7 @@ import { listDecks, deleteDeck } from '$lib/api/decks.ts'; import { devUser } from '$lib/auth/dev-stub.svelte.ts'; import { toasts } from '$lib/stores/toasts.svelte.ts'; + import InboxBanner from '$lib/components/InboxBanner.svelte'; let decks = $state([]); let loading = $state(true); @@ -54,6 +55,10 @@ > +
+ +
+ {#if loading}

Lade…

{:else if error} diff --git a/apps/web/src/routes/study/+page.svelte b/apps/web/src/routes/study/+page.svelte index eec479f..d062be2 100644 --- a/apps/web/src/routes/study/+page.svelte +++ b/apps/web/src/routes/study/+page.svelte @@ -5,6 +5,7 @@ import { listDecks } from '$lib/api/decks.ts'; import { listDueReviews } from '$lib/api/reviews.ts'; import { devUser } from '$lib/auth/dev-stub.svelte.ts'; + import InboxBanner from '$lib/components/InboxBanner.svelte'; type Item = { deck: Deck; due: number }; @@ -37,6 +38,10 @@

Lernen

+
+ +
+ {#if loading}

Lade…

{:else}