diff --git a/www/app/[domain]/browse/page.tsx b/www/app/[domain]/browse/page.tsx index 877d19b5..4a59c6dc 100644 --- a/www/app/[domain]/browse/page.tsx +++ b/www/app/[domain]/browse/page.tsx @@ -100,6 +100,7 @@ export default function TranscriptBrowser() { api .v1TranscriptDelete(transcriptToDeleteId) .then(() => { + refetch(); setDeletionLoading(false); refetch(); onCloseDeletion(); diff --git a/www/app/[domain]/transcripts/[transcriptId]/finalSummary.tsx b/www/app/[domain]/transcripts/[transcriptId]/finalSummary.tsx new file mode 100644 index 00000000..afde0aac --- /dev/null +++ b/www/app/[domain]/transcripts/[transcriptId]/finalSummary.tsx @@ -0,0 +1,150 @@ +import { useEffect, useRef, useState } from "react"; +import React from "react"; +import Markdown from "react-markdown"; +import "../../../styles/markdown.css"; +import { + GetTranscript, + GetTranscriptTopic, + UpdateTranscript, +} from "../../../api"; +import useApi from "../../../lib/useApi"; +import { + Flex, + Heading, + IconButton, + Button, + Textarea, + Spacer, +} from "@chakra-ui/react"; +import { FaPen } from "react-icons/fa"; +import { useError } from "../../../(errors)/errorContext"; +import ShareAndPrivacy from "../shareAndPrivacy"; + +type FinalSummaryProps = { + transcriptResponse: GetTranscript; + topicsResponse: GetTranscriptTopic[]; +}; + +export default function FinalSummary(props: FinalSummaryProps) { + const finalSummaryRef = useRef(null); + + const [isEditMode, setIsEditMode] = useState(false); + const [preEditSummary, setPreEditSummary] = useState(""); + const [editedSummary, setEditedSummary] = useState(""); + + const api = useApi(); + + const { setError } = useError(); + + useEffect(() => { + setEditedSummary(props.transcriptResponse?.long_summary || ""); + }, [props.transcriptResponse?.long_summary]); + + if (!props.topicsResponse || !props.transcriptResponse) { + return null; + } + + const updateSummary = async (newSummary: string, transcriptId: string) => { + try { + const requestBody: UpdateTranscript = { + long_summary: newSummary, + }; + const updatedTranscript = await api?.v1TranscriptUpdate( + transcriptId, + requestBody, + ); + console.log("Updated long summary:", updatedTranscript); + } catch (err) { + console.error("Failed to update long summary:", err); + setError(err, "Failed to update long summary."); + } + }; + + const onEditClick = () => { + setPreEditSummary(editedSummary); + setIsEditMode(true); + }; + + const onDiscardClick = () => { + setEditedSummary(preEditSummary); + setIsEditMode(false); + }; + + const onSaveClick = () => { + updateSummary(editedSummary, props.transcriptResponse.id); + setIsEditMode(false); + }; + + const handleTextAreaKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Escape") { + onDiscardClick(); + } + + if (e.key === "Enter" && e.shiftKey) { + onSaveClick(); + e.preventDefault(); // prevent the default action of adding a new line + } + }; + + return ( + + + Summary + + {isEditMode && ( + <> + + + + + )} + + {!isEditMode && ( + <> + } + aria-label="Edit Summary" + onClick={onEditClick} + /> + + + + )} + + + {isEditMode ? ( +