From 47762e9b05e984cf39535515450d7e9c49021e79 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 13 Dec 2023 16:45:49 +0100 Subject: [PATCH] implement done button --- server/reflector/views/transcripts.py | 4 +- .../[transcriptId]/correct/page.tsx | 54 +++++++++++++++---- www/app/[domain]/transcripts/useTranscript.ts | 4 +- www/app/[domain]/transcripts/useWebSockets.ts | 1 - www/app/api/models/GetTranscript.ts | 9 ++++ www/app/api/models/UpdateTranscript.ts | 8 +++ 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/server/reflector/views/transcripts.py b/server/reflector/views/transcripts.py index 171e04d7..bfc822b1 100644 --- a/server/reflector/views/transcripts.py +++ b/server/reflector/views/transcripts.py @@ -233,7 +233,9 @@ async def transcript_update( user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)], ): user_id = user["sub"] if user else None - transcript = await transcripts_controller.get_by_id(transcript_id, user_id=user_id) + transcript = await transcripts_controller.get_by_id_for_http( + transcript_id, user_id=user_id + ) if not transcript: raise HTTPException(status_code=404, detail="Transcript not found") values = info.dict(exclude_unset=True) diff --git a/www/app/[domain]/transcripts/[transcriptId]/correct/page.tsx b/www/app/[domain]/transcripts/[transcriptId]/correct/page.tsx index 9dcb2c7e..4695a431 100644 --- a/www/app/[domain]/transcripts/[transcriptId]/correct/page.tsx +++ b/www/app/[domain]/transcripts/[transcriptId]/correct/page.tsx @@ -1,5 +1,5 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import TopicHeader from "./topicHeader"; import TopicWords from "./topicWords"; import TopicPlayer from "./topicPlayer"; @@ -8,6 +8,10 @@ import useTopicWithWords from "../../useTopicWithWords"; import ParticipantList from "./participantList"; import { GetTranscriptTopic } from "../../../../api"; import { SelectedText, selectedTextIsTimeSlice } from "./types"; +import getApi from "../../../../lib/getApi"; +import useTranscript from "../../useTranscript"; +import { useError } from "../../../../(errors)/errorContext"; +import { useRouter } from "next/navigation"; export type TranscriptCorrect = { params: { @@ -18,12 +22,32 @@ export type TranscriptCorrect = { export default function TranscriptCorrect({ params: { transcriptId }, }: TranscriptCorrect) { + const api = getApi(); + const transcript = useTranscript(transcriptId); const stateCurrentTopic = useState(); const [currentTopic, _sct] = stateCurrentTopic; const stateSelectedText = useState(); const [selectedText, _sst] = stateSelectedText; const topicWithWords = useTopicWithWords(currentTopic?.id, transcriptId); const participants = useParticipants(transcriptId); + const { setError } = useError(); + const router = useRouter(); + + const markAsDone = () => { + if (transcript.response && !transcript.response.reviewed) { + api + ?.v1TranscriptUpdate({ + transcriptId, + updateTranscript: { reviewed: true }, + }) + .then(() => { + router.push(`/transcripts/${transcriptId}`); + }) + .catch((e) => { + setError(e, "Error marking as done"); + }); + } + }; return (
@@ -55,14 +79,26 @@ export default function TranscriptCorrect({
)} {participants.response && ( - +
+ + {!transcript.response?.reviewed && ( +
+ +
+ )} +
)}
diff --git a/www/app/[domain]/transcripts/useTranscript.ts b/www/app/[domain]/transcripts/useTranscript.ts index 91700d7a..4a052961 100644 --- a/www/app/[domain]/transcripts/useTranscript.ts +++ b/www/app/[domain]/transcripts/useTranscript.ts @@ -8,11 +8,11 @@ import { shouldShowError } from "../../lib/errorUtils"; type ErrorTranscript = { error: Error; loading: false; - response: any; + response: null; }; type LoadingTranscript = { - response: any; + response: null; loading: true; error: false; }; diff --git a/www/app/[domain]/transcripts/useWebSockets.ts b/www/app/[domain]/transcripts/useWebSockets.ts index d5ab2b8a..26b69c05 100644 --- a/www/app/[domain]/transcripts/useWebSockets.ts +++ b/www/app/[domain]/transcripts/useWebSockets.ts @@ -67,7 +67,6 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => { title: "Topic 1: Introduction to Quantum Mechanics", transcript: "A brief overview of quantum mechanics and its principles.", - duration: 10, segments: [ { speaker: 1, diff --git a/www/app/api/models/GetTranscript.ts b/www/app/api/models/GetTranscript.ts index 44f36bda..e716692e 100644 --- a/www/app/api/models/GetTranscript.ts +++ b/www/app/api/models/GetTranscript.ts @@ -103,6 +103,12 @@ export interface GetTranscript { * @memberof GetTranscript */ participants: any | null; + /** + * + * @type {any} + * @memberof GetTranscript + */ + reviewed: any | null; } /** @@ -123,6 +129,7 @@ export function instanceOfGetTranscript(value: object): boolean { isInstance = isInstance && "sourceLanguage" in value; isInstance = isInstance && "targetLanguage" in value; isInstance = isInstance && "participants" in value; + isInstance = isInstance && "reviewed" in value; return isInstance; } @@ -153,6 +160,7 @@ export function GetTranscriptFromJSONTyped( sourceLanguage: json["source_language"], targetLanguage: json["target_language"], participants: json["participants"], + reviewed: json["reviewed"], }; } @@ -178,5 +186,6 @@ export function GetTranscriptToJSON(value?: GetTranscript | null): any { source_language: value.sourceLanguage, target_language: value.targetLanguage, participants: value.participants, + reviewed: value.reviewed, }; } diff --git a/www/app/api/models/UpdateTranscript.ts b/www/app/api/models/UpdateTranscript.ts index b4965eab..da5bee72 100644 --- a/www/app/api/models/UpdateTranscript.ts +++ b/www/app/api/models/UpdateTranscript.ts @@ -61,6 +61,12 @@ export interface UpdateTranscript { * @memberof UpdateTranscript */ participants?: any | null; + /** + * + * @type {any} + * @memberof UpdateTranscript + */ + reviewed?: any | null; } /** @@ -97,6 +103,7 @@ export function UpdateTranscriptFromJSONTyped( participants: !exists(json, "participants") ? undefined : json["participants"], + reviewed: !exists(json, "reviewed") ? undefined : json["reviewed"], }; } @@ -115,5 +122,6 @@ export function UpdateTranscriptToJSON(value?: UpdateTranscript | null): any { long_summary: value.longSummary, share_mode: value.shareMode, participants: value.participants, + reviewed: value.reviewed, }; }