implement done button

This commit is contained in:
Sara
2023-12-13 16:45:49 +01:00
parent 66d4470306
commit 47762e9b05
6 changed files with 67 additions and 13 deletions

View File

@@ -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<GetTranscriptTopic>();
const [currentTopic, _sct] = stateCurrentTopic;
const stateSelectedText = useState<SelectedText>();
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 (
<div className="h-full grid grid-cols-2 gap-4">
@@ -55,14 +79,26 @@ export default function TranscriptCorrect({
<div></div>
)}
{participants.response && (
<ParticipantList
{...{
transcriptId,
participants,
topicWithWords,
stateSelectedText,
}}
/>
<div className="h-full flex flex-col justify-between">
<ParticipantList
{...{
transcriptId,
participants,
topicWithWords,
stateSelectedText,
}}
/>
{!transcript.response?.reviewed && (
<div className="flex flex-row justify-end">
<button
className="p-2 px-4 rounded bg-green-400"
onClick={markAsDone}
>
Done
</button>
</div>
)}
</div>
)}
</div>
</div>

View File

@@ -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;
};

View File

@@ -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,

View File

@@ -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,
};
}

View File

@@ -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,
};
}