"use client"; import React, { useState, useEffect } from "react"; import { Flex, Spinner, Heading, Text, Link } from "@chakra-ui/react"; import useTranscriptList from "../transcripts/useTranscriptList"; import useSessionUser from "../../lib/useSessionUser"; import { Room } from "../../api"; import Pagination from "./_components/Pagination"; import useApi from "../../lib/useApi"; import { useError } from "../../(errors)/errorContext"; import { SourceKind } from "../../api"; import FilterSidebar from "./_components/FilterSidebar"; import SearchBar from "./_components/SearchBar"; import TranscriptTable from "./_components/TranscriptTable"; import TranscriptCards from "./_components/TranscriptCards"; import DeleteTranscriptDialog from "./_components/DeleteTranscriptDialog"; export default function TranscriptBrowser() { const [selectedSourceKind, setSelectedSourceKind] = useState(null); const [selectedRoomId, setSelectedRoomId] = useState(""); const [rooms, setRooms] = useState([]); const [page, setPage] = useState(1); const [searchTerm, setSearchTerm] = useState(""); const { loading, response, refetch } = useTranscriptList( page, selectedSourceKind, selectedRoomId, searchTerm, ); const userName = useSessionUser().name; const [deletionLoading, setDeletionLoading] = useState(false); const api = useApi(); const { setError } = useError(); const cancelRef = React.useRef(null); const [transcriptToDeleteId, setTranscriptToDeleteId] = React.useState(); const [deletedItemIds, setDeletedItemIds] = React.useState(); useEffect(() => { setDeletedItemIds([]); }, [page, response]); useEffect(() => { if (!api) return; api .v1RoomsList({ page: 1 }) .then((rooms) => setRooms(rooms.items)) .catch((err) => setError(err, "There was an error fetching the rooms")); }, [api]); const handleFilterTranscripts = ( sourceKind: SourceKind | null, roomId: string, ) => { setSelectedSourceKind(sourceKind); setSelectedRoomId(roomId); setPage(1); }; const handleSearch = (searchTerm: string) => { setPage(1); setSearchTerm(searchTerm); setSelectedSourceKind(null); setSelectedRoomId(""); }; if (loading && !response) return ( ); if (!loading && !response) return ( No transcripts found, but you can  record a meeting  to get started. ); const onCloseDeletion = () => setTranscriptToDeleteId(undefined); const handleDeleteTranscript = (transcriptId) => (e) => { e.stopPropagation(); if (api && !deletionLoading) { setDeletionLoading(true); api .v1TranscriptDelete({ transcriptId }) .then(() => { refetch(); setDeletionLoading(false); onCloseDeletion(); setDeletedItemIds((deletedItemIds) => [ deletedItemIds, ...transcriptId, ]); }) .catch((err) => { setDeletionLoading(false); setError(err, "There was an error deleting the transcript"); }); } }; const handleProcessTranscript = (transcriptId) => (e) => { if (api) { api .v1TranscriptProcess({ transcriptId }) .then((result) => { const status = (result as any).status; if (status === "already running") { setError( new Error("Processing is already running, please wait"), "Processing is already running, please wait", ); } }) .catch((err) => { setError(err, "There was an error processing the transcript"); }); } }; return ( {userName ? `${userName}'s Transcriptions` : "Your Transcriptions"}{" "} {loading || (deletionLoading && )} handleDeleteTranscript(transcriptToDeleteId)(null)} cancelRef={cancelRef} /> ); }