From ef40cc0f3b1b3013046820b84e8482f1c6a29533 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 7 Dec 2025 17:44:14 +0900 Subject: feat(client): add deck list page with empty state and list view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement HomePage to display user's decks fetched from the API. Includes loading state, error handling with retry, and empty state messaging. Also adds comprehensive tests for the deck list page. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/client/pages/HomePage.tsx | 117 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) (limited to 'src/client/pages/HomePage.tsx') diff --git a/src/client/pages/HomePage.tsx b/src/client/pages/HomePage.tsx index 1d65484..c9d0843 100644 --- a/src/client/pages/HomePage.tsx +++ b/src/client/pages/HomePage.tsx @@ -1,8 +1,121 @@ +import { useCallback, useEffect, useState } from "react"; +import { ApiClientError, apiClient } from "../api"; +import { useAuth } from "../stores"; + +interface Deck { + id: string; + name: string; + description: string | null; + newCardsPerDay: number; + createdAt: string; + updatedAt: string; +} + export function HomePage() { + const { logout } = useAuth(); + const [decks, setDecks] = useState([]); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + const fetchDecks = useCallback(async () => { + setIsLoading(true); + setError(null); + + try { + const res = await apiClient.rpc.api.decks.$get(undefined, { + headers: apiClient.getAuthHeader(), + }); + + if (!res.ok) { + const errorBody = await res.json().catch(() => ({})); + throw new ApiClientError( + (errorBody as { error?: string }).error || + `Request failed with status ${res.status}`, + res.status, + ); + } + + const data = await res.json(); + setDecks(data.decks); + } catch (err) { + if (err instanceof ApiClientError) { + setError(err.message); + } else { + setError("Failed to load decks. Please try again."); + } + } finally { + setIsLoading(false); + } + }, []); + + useEffect(() => { + fetchDecks(); + }, [fetchDecks]); + return (
-

Kioku

-

Spaced repetition learning app

+
+

Kioku

+ +
+ +
+

Your Decks

+ + {isLoading &&

Loading decks...

} + + {error && ( +
+ {error} + +
+ )} + + {!isLoading && !error && decks.length === 0 && ( +
+

You don't have any decks yet.

+

Create your first deck to start learning!

+
+ )} + + {!isLoading && !error && decks.length > 0 && ( +
    + {decks.map((deck) => ( +
  • +

    {deck.name}

    + {deck.description && ( +

    + {deck.description} +

    + )} +
  • + ))} +
+ )} +
); } -- cgit v1.2.3-70-g09d2