diff --git a/src/components/document-viewer.tsx b/src/components/document-viewer.tsx index 96b9d3e..5c0fd60 100644 --- a/src/components/document-viewer.tsx +++ b/src/components/document-viewer.tsx @@ -4,6 +4,7 @@ import { useState, useEffect, useRef } from "react"; import { Button } from "./ui/button"; import { useRouter } from "next/navigation"; import { getUserData } from "@/app/actions"; +import type { AdviceAPIType } from "@/types"; export async function getPaperlessDocument( documentId: number, @@ -40,16 +41,43 @@ export default function DocumentViewer(props: { id: number }) { const [pdfUrl, setPdfUrl] = useState(null); const [loading, setLoading] = useState(true); const fetchDataCalledRef = useRef(false); + const [advice, setAdvice] = useState(null); + + useEffect(() => { + const fetchAdvice = async () => { + try { + const response = await fetch("https://api.adviceslip.com/advice"); + if (!response.ok) { + throw new Error("Network response was not ok"); + } + const data = (await response.json()) as AdviceAPIType; + setAdvice(data.slip.advice); + } catch (error) { + console.error("Failed to fetch advice:", error); + } + }; + + void fetchAdvice(); + }, []); const SkeletonLoader = () => (
-
+
{/* PDF Skeleton */} -
+
+ {/* Pulsing Background */} +
+ {/* Text Overlay */} +
+
+ {advice ? advice : "Loading advice..."} +
+
+
{/* Button Skeleton */} -
+
diff --git a/src/types/index.ts b/src/types/index.ts index 6966b0f..ed86760 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -67,3 +67,10 @@ export type PaperlessDocumentsType = { }; }[]; }; + +export type AdviceAPIType = { + slip: { + slip_id: number; + advice: string; + }; +};