mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
Finished UI
This commit is contained in:
@@ -16,12 +16,12 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
const [isCopiedSummary, setIsCopiedSummary] = useState(false);
|
const [isCopiedSummary, setIsCopiedSummary] = useState(false);
|
||||||
const [isCopiedTranscript, setIsCopiedTranscript] = useState(false);
|
const [isCopiedTranscript, setIsCopiedTranscript] = useState(false);
|
||||||
const [isEditMode, setIsEditMode] = useState(false);
|
const [isEditMode, setIsEditMode] = useState(false);
|
||||||
|
const [preEditSummary, setPreEditSummary] = useState(props.summary);
|
||||||
const [editedSummary, setEditedSummary] = useState(props.summary);
|
const [editedSummary, setEditedSummary] = useState(props.summary);
|
||||||
const api = getApi(props.protectedPath);
|
const api = getApi(props.protectedPath);
|
||||||
|
|
||||||
const updateSummary = async (newSummary: string, transcriptId: string) => {
|
const updateSummary = async (newSummary: string, transcriptId: string) => {
|
||||||
try {
|
try {
|
||||||
setEditedSummary(newSummary);
|
|
||||||
const updatedTranscript = await api.v1TranscriptUpdate({
|
const updatedTranscript = await api.v1TranscriptUpdate({
|
||||||
transcriptId,
|
transcriptId,
|
||||||
updateTranscript: {
|
updateTranscript: {
|
||||||
@@ -34,7 +34,7 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCopySummaryClick = () => {
|
const onCopySummaryClick = () => {
|
||||||
let text_to_copy = finalSummaryRef.current?.innerText;
|
let text_to_copy = finalSummaryRef.current?.innerText;
|
||||||
|
|
||||||
text_to_copy &&
|
text_to_copy &&
|
||||||
@@ -45,7 +45,7 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCopyTranscriptClick = () => {
|
const onCopyTranscriptClick = () => {
|
||||||
let text_to_copy = props.fullTranscript;
|
let text_to_copy = props.fullTranscript;
|
||||||
|
|
||||||
text_to_copy &&
|
text_to_copy &&
|
||||||
@@ -56,58 +56,113 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditMode = () => {
|
const onEditClick = () => {
|
||||||
setIsEditMode(!isEditMode);
|
setPreEditSummary(editedSummary);
|
||||||
|
setIsEditMode(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDiscardClick = () => {
|
||||||
|
setEditedSummary(preEditSummary);
|
||||||
|
setIsEditMode(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSaveClick = () => {
|
||||||
|
updateSummary(editedSummary, props.transcriptId);
|
||||||
|
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 (
|
return (
|
||||||
<div className="overflow-y-auto h-auto max-h-full">
|
<div
|
||||||
|
className={
|
||||||
|
(isEditMode ? "overflow-y-none" : "overflow-y-auto") +
|
||||||
|
" h-auto max-h-full flex flex-col h-full"
|
||||||
|
}
|
||||||
|
>
|
||||||
<div className="flex flex-row flex-wrap-reverse justify-between items-center">
|
<div className="flex flex-row flex-wrap-reverse justify-between items-center">
|
||||||
<h2 className="text-lg sm:text-xl md:text-2xl font-bold">
|
<h2 className="text-lg sm:text-xl md:text-2xl font-bold">
|
||||||
Final Summary
|
Final Summary
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div className="ml-auto flex space-x-2 mb-2">
|
<div className="ml-auto flex space-x-2 mb-2">
|
||||||
|
{isEditMode && (
|
||||||
|
<>
|
||||||
<button
|
<button
|
||||||
onClick={handleEditMode}
|
onClick={onDiscardClick}
|
||||||
|
className={"text-gray-500 text-sm hover:underline"}
|
||||||
|
>
|
||||||
|
Discard Changes
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={onSaveClick}
|
||||||
className={
|
className={
|
||||||
"bg-blue-400 hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2"
|
"bg-blue-400 hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isEditMode ? "Save" : "Edit Summary"}
|
Save Changes
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isEditMode && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={onEditClick}
|
||||||
|
className={
|
||||||
|
"bg-blue-400 hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2 sm:text-base text-xs"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Edit Summary
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={handleCopyTranscriptClick}
|
onClick={onCopyTranscriptClick}
|
||||||
className={
|
className={
|
||||||
(isCopiedTranscript ? "bg-blue-500" : "bg-blue-400") +
|
(isCopiedTranscript ? "bg-blue-500" : "bg-blue-400") +
|
||||||
" hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2"
|
" hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2 sm:text-base text-xs"
|
||||||
}
|
}
|
||||||
style={{ minHeight: "30px" }}
|
style={{ minHeight: "30px" }}
|
||||||
>
|
>
|
||||||
{isCopiedTranscript ? "Copied!" : "Copy Full Transcript"}
|
{isCopiedTranscript ? "Copied!" : "Copy Transcript"}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={handleCopySummaryClick}
|
onClick={onCopySummaryClick}
|
||||||
className={
|
className={
|
||||||
(isCopiedSummary ? "bg-blue-500" : "bg-blue-400") +
|
(isCopiedSummary ? "bg-blue-500" : "bg-blue-400") +
|
||||||
" hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2"
|
" hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2 sm:text-base text-xs"
|
||||||
}
|
}
|
||||||
style={{ minHeight: "30px" }}
|
style={{ minHeight: "30px" }}
|
||||||
>
|
>
|
||||||
{isCopiedSummary ? "Copied!" : "Copy Summary"}
|
{isCopiedSummary ? "Copied!" : "Copy Summary"}
|
||||||
</button>
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isEditMode ? (
|
{isEditMode ? (
|
||||||
|
<div className="flex-grow overflow-y-none">
|
||||||
<textarea
|
<textarea
|
||||||
value={editedSummary}
|
value={editedSummary}
|
||||||
onChange={(e) => updateSummary(e.target.value, props.transcriptId)}
|
onChange={(e) => setEditedSummary(e.target.value)}
|
||||||
className="markdown"
|
className="markdown w-full h-full d-block p-2 border rounded shadow-sm"
|
||||||
|
onKeyDown={(e) => handleTextAreaKeyDown(e)}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<p ref={finalSummaryRef} className="markdown">
|
<p ref={finalSummaryRef} className="markdown">
|
||||||
<Markdown>{editedSummary}</Markdown>
|
<Markdown>{editedSummary}</Markdown>
|
||||||
</p>
|
</p>
|
||||||
)}{" "}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ type TranscriptTitle = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const TranscriptTitle = (props: TranscriptTitle) => {
|
const TranscriptTitle = (props: TranscriptTitle) => {
|
||||||
const [currentTitle, setCurrentTitle] = useState(props.title);
|
const [displayedTitle, setDisplayedTitle] = useState(props.title);
|
||||||
|
const [preEditTitle, setPreEditTitle] = useState(props.title);
|
||||||
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const api = getApi(props.protectedPath);
|
const api = getApi(props.protectedPath);
|
||||||
|
|
||||||
const updateTitle = async (newTitle: string, transcriptId: string) => {
|
const updateTitle = async (newTitle: string, transcriptId: string) => {
|
||||||
|
if (!api) return;
|
||||||
try {
|
try {
|
||||||
const updatedTranscript = await api.v1TranscriptUpdate({
|
const updatedTranscript = await api.v1TranscriptUpdate({
|
||||||
transcriptId,
|
transcriptId,
|
||||||
@@ -24,21 +27,57 @@ const TranscriptTitle = (props: TranscriptTitle) => {
|
|||||||
console.error("Failed to update transcript:", err);
|
console.error("Failed to update transcript:", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleClick = () => {
|
|
||||||
const newTitle = prompt("Please enter the new title:", currentTitle);
|
const handleTitleClick = () => {
|
||||||
|
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
// Use prompt
|
||||||
|
const newTitle = prompt("Please enter the new title:", displayedTitle);
|
||||||
if (newTitle !== null) {
|
if (newTitle !== null) {
|
||||||
setCurrentTitle(newTitle);
|
setDisplayedTitle(newTitle);
|
||||||
updateTitle(newTitle, props.transcriptId);
|
updateTitle(newTitle, props.transcriptId);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setPreEditTitle(displayedTitle);
|
||||||
|
setIsEditing(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (e) => {
|
||||||
|
setDisplayedTitle(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
updateTitle(displayedTitle, props.transcriptId);
|
||||||
|
setIsEditing(false);
|
||||||
|
} else if (e.key === "Escape") {
|
||||||
|
setDisplayedTitle(preEditTitle);
|
||||||
|
setIsEditing(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{isEditing ? (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={displayedTitle}
|
||||||
|
onChange={handleChange}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
autoFocus
|
||||||
|
className="text-2xl lg:text-4xl font-extrabold text-center mb-4 w-full border-none bg-transparent overflow-hidden h-[fit-content]"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
<h2
|
<h2
|
||||||
className="text-2xl lg:text-4xl font-extrabold text-center mb-4"
|
className="text-2xl lg:text-4xl font-extrabold text-center mb-4 cursor-pointer"
|
||||||
onClick={handleClick}
|
onClick={handleTitleClick}
|
||||||
>
|
>
|
||||||
{currentTitle}
|
{displayedTitle}
|
||||||
</h2>
|
</h2>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user