feat: books fetch on SSR in book reader
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 17s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 17s
This commit is contained in:
@@ -10,9 +10,15 @@ import logger from "@/lib/logger";
|
||||
|
||||
interface ClientBookPageProps {
|
||||
bookId: string;
|
||||
initialData?: {
|
||||
book: KomgaBook;
|
||||
pages: number[];
|
||||
nextBook: KomgaBook | null;
|
||||
};
|
||||
initialError?: string;
|
||||
}
|
||||
|
||||
export function ClientBookPage({ bookId }: ClientBookPageProps) {
|
||||
export function ClientBookPage({ bookId, initialData, initialError }: ClientBookPageProps) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [data, setData] = useState<{
|
||||
@@ -21,6 +27,22 @@ export function ClientBookPage({ bookId }: ClientBookPageProps) {
|
||||
nextBook: KomgaBook | null;
|
||||
} | null>(null);
|
||||
|
||||
// Use SSR data if available
|
||||
useEffect(() => {
|
||||
if (initialData) {
|
||||
setData(initialData);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (initialError) {
|
||||
setError(initialError);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
fetchBookData();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [bookId, initialData, initialError]);
|
||||
|
||||
const fetchBookData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
@@ -43,11 +65,6 @@ export function ClientBookPage({ bookId }: ClientBookPageProps) {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchBookData();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [bookId]);
|
||||
|
||||
const handleRetry = () => {
|
||||
fetchBookData();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user