Edit title + summary UI

This commit is contained in:
Koper
2023-10-29 18:57:21 +00:00
committed by Mathieu Virbel
parent e8c867420f
commit 17f10051ad
3 changed files with 85 additions and 8 deletions

View File

@@ -1,11 +1,43 @@
import { useState } from "react";
import getApi from "../../lib/getApi";
type TranscriptTitle = {
protectedPath: boolean;
title: string;
transcriptId: string;
};
const TranscriptTitle = (props: TranscriptTitle) => {
const [currentTitle, setCurrentTitle] = useState(props.title);
const api = getApi(props.protectedPath);
const updateTitle = async (newTitle: string, transcriptId: string) => {
try {
const updatedTranscript = await api.v1TranscriptUpdate({
transcriptId,
updateTranscript: {
title: newTitle,
},
});
console.log("Updated transcript:", updatedTranscript);
} catch (err) {
console.error("Failed to update transcript:", err);
}
};
const handleClick = () => {
const newTitle = prompt("Please enter the new title:", currentTitle);
if (newTitle !== null) {
setCurrentTitle(newTitle);
updateTitle(newTitle, props.transcriptId);
}
};
return (
<h2 className="text-2xl lg:text-4xl font-extrabold text-center mb-4">
{props.title}
<h2
className="text-2xl lg:text-4xl font-extrabold text-center mb-4"
onClick={handleClick}
>
{currentTitle}
</h2>
);
};