"use client"; import React, { useState, useEffect } from "react"; import { Flex, Spinner, Heading, Box, Text, Link, Stack, Table, Thead, Tbody, Tr, Th, Td, Button, Divider, Input, Icon, Tooltip, Menu, MenuButton, MenuList, MenuItem, IconButton, AlertDialog, AlertDialogOverlay, AlertDialogContent, AlertDialogHeader, AlertDialogBody, AlertDialogFooter, Spacer, } from "@chakra-ui/react"; import { FaCheck, FaTrash, FaStar, FaMicrophone, FaGear, FaEllipsisVertical, FaArrowRotateRight, } from "react-icons/fa6"; import useTranscriptList from "../transcripts/useTranscriptList"; import useSessionUser from "../../lib/useSessionUser"; import NextLink from "next/link"; import { Room, GetTranscript } from "../../api"; import Pagination from "./pagination"; import { formatTimeMs } from "../../lib/time"; import useApi from "../../lib/useApi"; import { useError } from "../../(errors)/errorContext"; import { SourceKind } from "../../api"; 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 [searchInputValue, setSearchInputValue] = 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(); const myRooms = rooms.filter((room) => !room.is_shared); const sharedRooms = rooms.filter((room) => room.is_shared); useEffect(() => { setDeletedItemIds([]); }, [page, response]); useEffect(() => { refetch(); }, [selectedRoomId, page, searchTerm]); 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); refetch(); }; const handleSearch = () => { setPage(1); setSearchTerm(searchInputValue); setSelectedSourceKind(null); setSelectedRoomId(""); refetch(); }; const handleKeyDown = (event) => { if (event.key === "Enter") { handleSearch(); } }; 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 && )} handleFilterTranscripts(null, "")} color={selectedSourceKind === null ? "blue.500" : "gray.600"} _hover={{ color: "blue.300" }} fontWeight={selectedSourceKind === null ? "bold" : "normal"} > All Transcripts {myRooms.length > 0 && ( <> My Rooms {myRooms.map((room) => ( handleFilterTranscripts("room", room.id)} color={ selectedSourceKind === "room" && selectedRoomId === room.id ? "blue.500" : "gray.600" } _hover={{ color: "blue.300" }} fontWeight={ selectedSourceKind === "room" && selectedRoomId === room.id ? "bold" : "normal" } ml={4} > {room.name} ))} )} {sharedRooms.length > 0 && ( <> Shared Rooms {sharedRooms.map((room) => ( handleFilterTranscripts("room", room.id)} color={ selectedSourceKind === "room" && selectedRoomId === room.id ? "blue.500" : "gray.600" } _hover={{ color: "blue.300" }} fontWeight={ selectedSourceKind === "room" && selectedRoomId === room.id ? "bold" : "normal" } ml={4} > {room.name} ))} )} handleFilterTranscripts("live", "")} color={selectedSourceKind === "live" ? "blue.500" : "gray.600"} _hover={{ color: "blue.300" }} fontWeight={selectedSourceKind === "live" ? "bold" : "normal"} > Live Transcripts handleFilterTranscripts("file", "")} color={selectedSourceKind === "file" ? "blue.500" : "gray.600"} _hover={{ color: "blue.300" }} fontWeight={selectedSourceKind === "file" ? "bold" : "normal"} > Uploaded Files setSearchInputValue(e.target.value)} onKeyDown={handleKeyDown} /> {response?.items?.map((item: GetTranscript) => ( ))}
Transcription Title Source Date Duration
{item.status === "ended" && ( )} {item.status === "error" && ( )} {item.status === "idle" && ( )} {item.status === "processing" && ( )} {item.status === "recording" && ( )} {item.title || "Unnamed Transcript"} {item.source_kind === "room" ? item.room_name : item.source_kind} {new Date(item.created_at).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", })} {formatTimeMs(item.duration)} } variant="outline" aria-label="Options" /> Delete Reprocess
{response?.items?.map((item: GetTranscript) => ( {item.status === "ended" && ( )} {item.status === "error" && ( )} {item.status === "idle" && ( )} {item.status === "processing" && ( )} {item.status === "recording" && ( )} {item.title || "Unnamed Transcript"} Source:{" "} {item.source_kind === "room" ? item.room_name : item.source_kind} Date: {new Date(item.created_at).toLocaleString()} Duration: {formatTimeMs(item.duration)} } variant="outline" aria-label="Options" /> Delete Reprocess ))}
Delete Transcript Are you sure? You can't undo this action afterwards.
); }