diff --git a/www/app/browse/page.tsx b/www/app/browse/page.tsx new file mode 100644 index 00000000..9c6db369 --- /dev/null +++ b/www/app/browse/page.tsx @@ -0,0 +1,89 @@ +"use client"; +import React, { useState, useEffect } from "react"; +import getApi from "../lib/getApi"; +import { + PageGetTranscript, + GetTranscript, + GetTranscriptFromJSON, +} from "../api"; +import { Title } from "../lib/textComponents"; +import Pagination from "./pagination"; +import Link from "next/link"; + +export default function TranscriptBrowser() { + const api = getApi(); + const [results, setResults] = useState(null); + const [page, setPage] = useState(1); + + 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]); + + return ( +
+ {/* +
+ +
+ */} + +
+ Past transcripts + +
+ +
+
+ {results?.items.map((item: GetTranscript) => ( +
+
+
+ + {item.title || item.name} + + + {item.locked ? ( +
+ Locked +
+ ) : ( + <> + )} + + {item.sourceLanguage ? ( +
+ {item.sourceLanguage} +
+ ) : ( + <> + )} +
+
+ {new Date(item.createdAt).toLocaleDateString("en-US")} +
+
{item.shortSummary}
+
+
+ ))} +
+
+
+ ); +} diff --git a/www/app/browse/pagination.tsx b/www/app/browse/pagination.tsx new file mode 100644 index 00000000..27ff5f47 --- /dev/null +++ b/www/app/browse/pagination.tsx @@ -0,0 +1,75 @@ +type PaginationProps = { + page: number; + setPage: (page: number) => void; + total: number; + size: number; +}; + +export default function Pagination(props: PaginationProps) { + const { page, setPage, total, size } = props; + const totalPages = Math.ceil(total / size); + + const pageNumbers = Array.from( + { length: totalPages }, + (_, i) => i + 1, + ).filter((pageNumber) => { + if (totalPages <= 3) { + // If there are 3 or fewer total pages, show all pages. + return true; + } else if (page <= 2) { + // For the first two pages, show the first 3 pages. + return pageNumber <= 3; + } else if (page >= totalPages - 1) { + // For the last two pages, show the last 3 pages. + return pageNumber >= totalPages - 2; + } else { + // For all other cases, show 3 pages centered around the current page. + return pageNumber >= page - 1 && pageNumber <= page + 1; + } + }); + + const canGoPrevious = page > 1; + const canGoNext = page < totalPages; + + const handlePageChange = (newPage: number) => { + if (newPage >= 1 && newPage <= totalPages) { + setPage(newPage); + } + }; + + return ( +
+ + + {pageNumbers.map((pageNumber) => ( + + ))} + + +
+ ); +} diff --git a/www/app/layout.tsx b/www/app/layout.tsx index ff35ff03..da4dfd4d 100644 --- a/www/app/layout.tsx +++ b/www/app/layout.tsx @@ -9,6 +9,7 @@ import Image from "next/image"; import Link from "next/link"; import About from "./(aboutAndPrivacy)/about"; import Privacy from "./(aboutAndPrivacy)/privacy"; +import { featPrivacy } from "./lib/utils"; const poppins = Poppins({ subsets: ["latin"], weight: ["200", "400", "600"] }); @@ -93,9 +94,29 @@ export default function RootLayout({ children }) {
{/* Text link on the right */} - + + Create +  ·  - + + Browse + +  ·  + + {featPrivacy() ? ( + <> +  ·  + + + ) : ( + <> + )}
diff --git a/www/app/lib/utils.ts b/www/app/lib/utils.ts index db775f07..3a95cc22 100644 --- a/www/app/lib/utils.ts +++ b/www/app/lib/utils.ts @@ -1,3 +1,11 @@ export function isDevelopment() { return process.env.NEXT_PUBLIC_ENV === "development"; } + +export function featPrivacy() { + return process.env.NEXT_PUBLIC_FEAT_PRIVACY === "1"; +} + +export function featBrowse() { + return process.env.NEXT_PUBLIC_FEAT_BROWSE === "1"; +} diff --git a/www/app/transcripts/shareLink.tsx b/www/app/transcripts/shareLink.tsx index 04f348bc..99e5ac9a 100644 --- a/www/app/transcripts/shareLink.tsx +++ b/www/app/transcripts/shareLink.tsx @@ -1,4 +1,5 @@ import React, { useState, useRef, useEffect, use } from "react"; +import { featPrivacy } from "../lib/utils"; const ShareLink = () => { const [isCopied, setIsCopied] = useState(false); @@ -27,11 +28,18 @@ const ShareLink = () => { className="p-2 md:p-4 rounded" style={{ background: "rgba(96, 165, 250, 0.2)" }} > -

- You can share this link with others. Anyone with the link will have - access to the page, including the full audio recording, for the next 7 - days. -

+ {featPrivacy() ? ( +

+ You can share this link with others. Anyone with the link will have + access to the page, including the full audio recording, for the next 7 + days. +

+ ) : ( +

+ You can share this link with others. Anyone with the link will have + access to the page, including the full audio recording. +

+ )}