/** * Meetings: the recorder on top, then every meeting this person can see, * newest first. A row opens the meeting's own page. Rows still recording, in * progress elsewhere or transcribing say so and update on their own. */ import { useOpenGeniText } from "../messages/runtime"; import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode, type ComponentProps, } from "react"; import { AudioLinesIcon, LockIcon, SearchIcon, Trash2Icon } from "lucide-react"; import type { Recording } from "@opengeni/contracts"; import { formatDuration, meetingHereStatus, meetingPhase, meetingStatusLabel, meetingTitle, useRecordingModels, useRecordings, useRecordingsClient, type RecordingsClientOverride, } from "../recordings"; import { Button } from "../ui/button"; import { DropdownMenuItem } from "../ui/dropdown-menu"; import { EmptyState } from "../ui/empty-state"; import { ErrorMessage } from "../ui/error-message"; import { inAppClick } from "../ui/in-app-click"; import { Input } from "../ui/input"; import { ListRow, ListRowSkeleton, RowList, type RowListColumn } from "../ui/list-row"; import { LogoTile } from "../ui/logo-tile"; import { MetaChip } from "../ui/meta-chip"; import { Notice } from "../ui/notice"; import { PageHeader } from "../ui/page-header"; import { RelativeTime } from "../ui/relative-time"; import { StatusBadge } from "../ui/status-badge"; import { DeleteMeetingDialog } from "./delete-meeting-dialog"; import { RecorderPanel, useOnline } from "./recorder-panel"; import { useMeetingRecorder, usePendingMeetingStart } from "./recorder-context"; import { MeetingsOverlayScope } from "./overlay-scope"; function useDebounced(value: T, delay: number): T { const [debounced, setDebounced] = useState(value); useEffect(() => { const timer = window.setTimeout(() => setDebounced(value), delay); return () => window.clearTimeout(timer); }, [value, delay]); return debounced; } function useNarrow(): boolean { const query = "(max-width: 639px)"; const [narrow, setNarrow] = useState( () => typeof window !== "undefined" && window.matchMedia?.(query).matches === true, ); useEffect(() => { const media = window.matchMedia?.(query); if (!media) return; const update = () => setNarrow(media.matches); update(); media.addEventListener("change", update); return () => media.removeEventListener("change", update); }, []); return narrow; } function MeetingsListPageContent({ workspaceId, liveTranscriptDefault, liveTranscript = true, defaultLanguage, recordings: recordingsClient, meetingHref, onOpen, externalRef = null, notice = null, header = true, recordingOff = null, viewerName = null, }: { workspaceId: string; /** * Whether the recorder starts with the live transcript on. By default the * workspace's setting, from the server. */ liveTranscriptDefault?: boolean; /** Offer the live transcript preview at all; false hides it even when a live model is connected. */ liveTranscript?: boolean; /** * The language the recorder starts on; null detects it. By default the * workspace's meeting language, from the server. */ defaultLanguage?: string | null; /** A recordings client to use instead of the app's, for previews. */ recordings?: RecordingsClientOverride["recordings"]; meetingHref: (recordingId: string) => string; onOpen: (recordingId: string) => void; /** * Show only the meetings with this id of the host's, such as a project, and * give new recordings started here the same id. */ externalRef?: string | null; /** A short line shown before every start, such as a reminder to tell the people present. */ notice?: ReactNode; /** Show the page title; false when the list sits inside a page of the host's. */ header?: boolean; /** * Shown instead of the recorder when the host doesn't let this person record * here, such as a setting an administrator has to turn on first. Meetings * already recorded stay listed, and a recording already underway keeps its controls. */ recordingOff?: ReactNode; /** The person recording's name, for their microphone's live text beside computer or tab audio. */ viewerName?: string | null; }) { const msg = useOpenGeniText(); const columns: RowListColumn[] = [ { id: "length", label: msg("meetings.listPage.length"), width: 96 }, { id: "recorded", label: msg("meetings.listPage.recorded"), width: 148 }, ]; const [search, setSearch] = useState(""); const query = useDebounced(search.trim(), 250); const override = { workspaceId, ...(recordingsClient ? { recordings: recordingsClient } : {}) }; const list = useRecordings({ ...override, ...(query ? { query } : {}), ...(externalRef ? { externalRef } : {}), }); const { client } = useRecordingsClient(override); const { recorder, finished, workspaceId: recorderWorkspaceId, openMeeting, } = useMeetingRecorder(); const online = useOnline(); // A recording started in another workspace keeps going here; its meeting // opens in its own workspace. const openRecorded = useCallback( (recordingId: string) => { if ( recorderWorkspaceId && recorderWorkspaceId !== workspaceId && openMeeting(recordingId, recorderWorkspaceId) ) { return; } onOpen(recordingId); }, [recorderWorkspaceId, workspaceId, openMeeting, onOpen], ); const models = useRecordingModels(override); const liveModel = models.liveModels.find((entry) => entry.available) ?? null; // A desktop call notification's Record waits for the live model list, so // the recording gets the same live-preview default as a click on Start. const pendingStart = usePendingMeetingStart(); const autoStart = useMemo( () => ({ pending: pendingStart.request !== null && !models.loading, take: pendingStart.take }), [pendingStart.request, pendingStart.take, models.loading], ); const narrow = useNarrow(); const [pendingDelete, setPendingDelete] = useState(null); // A recording that finished uploading in this tab changes state on the server. const refresh = list.refresh; const finishedCount = finished.length; useEffect(() => { if (finishedCount > 0) void refresh(); }, [finishedCount, refresh]); // A recording that just started shows up in the list as soon as the server has it. const liveId = recorder?.upload?.created ? recorder.recordingId : null; const lastLiveId = useRef(null); useEffect(() => { if (liveId && liveId !== lastLiveId.current) { lastLiveId.current = liveId; void refresh(); } }, [liveId, refresh]); const loading = list.loading && list.recordings.length === 0; const empty = !list.loading && !list.error && list.recordings.length === 0; const showRecorder = recordingOff === null || (recorder !== null && recorder.state !== "idle"); return ( <> {header ? ( } title={msg("meetings.listPage.meetings")} description={msg("meetings.listPage.recordAMeetingAndGet")} /> ) : null}
{showRecorder ? ( ) : ( {recordingOff} )} {recorder && recorder.recovered.length > 0 ? ( {msg("meetings.listPage.earlierRecordingsWereStillSaved", { count: recorder.recovered.length, })} ) : null}
{list.recordings.length > 0 || query ? (
) : null} {loading ? ( ) : list.error && list.recordings.length === 0 ? ( void list.refresh()} className="pointer-coarse:h-11" > {msg("meetings.listPage.tryAgain")} } > {msg("meetings.listPage.checkYourConnectionThenTry")} ) : empty ? ( query ? ( ) : ( } title={msg("meetings.listPage.noMeetingsYet")} description={ showRecorder ? msg("meetings.listPage.startARecordingAboveWhen") : undefined } className="pt-8" /> ) ) : ( {list.recordings.map((recording) => { // Stopped here, its last audio is on its way: Transcribing, not In progress. const here = recording.state === "capturing" ? meetingHereStatus(recorder, recording.id, online) : null; const status = meetingStatusLabel( here === "transcribing" ? { kind: "transcribing", version: null } : meetingPhase(recording), msg, ); // Recording here until Stop: after it, the row reads Transcribing. const isLive = here === "recording" || here === "paused"; return ( } />} title={meetingTitle(recording, msg)} titleAddon={ recording.sourceWorkspace ? ( // The person's own Only me meeting, stored in another // workspace of the organization: say which. }> {msg("meetings.listPage.onlyMeRecordedIn", { workspace: recording.sourceWorkspace.name, })} ) : recording.visibility === "private" ? ( }> {msg("meetings.listPage.onlyMe")} ) : undefined } status={ isLive ? ( here === "paused" ? ( {msg("meetings.recorderPanel.paused")} ) : ( {msg("meetings.listPage.recording")} ) ) : status ? ( {status.label} ) : undefined } meta={ narrow ? [ , recording.durationMilliseconds > 0 ? formatDuration(recording.durationMilliseconds, msg) : null, ].filter(Boolean) : undefined } cells={{ length: recording.durationMilliseconds > 0 ? ( {formatDuration(recording.durationMilliseconds, msg)} ) : ( — ), recorded: , }} menu={ setPendingDelete(recording)} > } menuLabel={msg("meetings.listPage.moreActionsForTitle", { title: meetingTitle(recording, msg), })} href={meetingHref(recording.id)} linkProps={{ onClick: inAppClick(() => onOpen(recording.id)) }} /> ); })} )} {list.hasMore ? (
) : null}
setPendingDelete(null)} onDelete={async (recordingId) => { await client.deleteRecording(workspaceId, recordingId); }} onDeleted={() => void list.refresh()} /> ); } export function MeetingsListPage(props: ComponentProps) { return ( ); }