From 76f95aad667196acaee3007f7404a19311914eee Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Wed, 18 Oct 2023 18:58:27 +0200 Subject: [PATCH] www: add transcripts list --- www/app/browse/page.tsx | 110 +++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/www/app/browse/page.tsx b/www/app/browse/page.tsx index 9c6db369..10c7d936 100644 --- a/www/app/browse/page.tsx +++ b/www/app/browse/page.tsx @@ -9,21 +9,35 @@ import { import { Title } from "../lib/textComponents"; import Pagination from "./pagination"; import Link from "next/link"; +import { useFiefIsAuthenticated } from "@fief/fief/nextjs/react"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faGear } from "@fortawesome/free-solid-svg-icons"; export default function TranscriptBrowser() { const api = getApi(); const [results, setResults] = useState(null); const [page, setPage] = useState(1); + const [isLoading, setIsLoading] = useState(false); + const isAuthenticated = useFiefIsAuthenticated(); useEffect(() => { - api.v1TranscriptsList({ page }).then((response) => { - // issue with API layer, conversion for items is not happening - response.items = response.items.map((item) => - GetTranscriptFromJSON(item), - ); - setResults(response); - }); - }, [page]); + if (!isAuthenticated) return; + setIsLoading(true); + api + .v1TranscriptsList({ page }) + .then((response) => { + // issue with API layer, conversion for items is not happening + response.items = response.items.map((item) => + GetTranscriptFromJSON(item), + ); + setResults(response); + setIsLoading(false); + }) + .catch(() => { + setResults(null); + setIsLoading(false); + }); + }, [page, isAuthenticated]); return (
@@ -45,43 +59,57 @@ export default function TranscriptBrowser() {
- {results?.items.map((item: GetTranscript) => ( -
-
-
- - {item.title || item.name} - + {isLoading ? ( + + ) : ( + <> + {results === null ? ( +
No transcripts found.
+ ) : ( + <> + )} + {results?.items.map((item: GetTranscript) => ( +
+
+
+ + {item.title || item.name} + - {item.locked ? ( -
- Locked -
- ) : ( - <> - )} + {item.locked ? ( +
+ Locked +
+ ) : ( + <> + )} - {item.sourceLanguage ? ( -
- {item.sourceLanguage} + {item.sourceLanguage ? ( +
+ {item.sourceLanguage} +
+ ) : ( + <> + )}
- ) : ( - <> - )} +
+ {new Date(item.createdAt).toLocaleDateString("en-US")} +
+
{item.shortSummary}
+
-
- {new Date(item.createdAt).toLocaleDateString("en-US")} -
-
{item.shortSummary}
-
-
- ))} + ))} + + )}