From 2b60665a3b70e9daffe7b20ccd02cbd696c83580 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 13 Jun 2021 00:17:08 -0400 Subject: [PATCH] this works. forget react-table --- .../Profile_TtsInferenceResultListFc.tsx | 92 ++++++++++++++++--- 1 file changed, 78 insertions(+), 14 deletions(-) diff --git a/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx b/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx index ce295eeb4c..6d4ae99d1e 100644 --- a/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx +++ b/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx @@ -1,16 +1,18 @@ -import React, { useState, useEffect } from 'react'; -import { ApiConfig } from '../../common/ApiConfig'; +import React, { useState, useEffect, useCallback } from 'react'; +import { ApiConfig, ListTtsInferenceResultsForUserArgs } from '../../common/ApiConfig'; import { Link } from "react-router-dom"; interface TtsInferenceResultListResponsePayload { success: boolean, results: Array, + cursor_next: string | null | undefined, + cursor_previous: string | null | undefined, } interface TtsInferenceResult { tts_result_token: string, tts_model_token: string, - inference_text: string, + raw_inference_text: string, maybe_creator_user_token?: string, maybe_creator_username?: string, @@ -28,11 +30,29 @@ interface Props { } function ProfileTtsInferenceResultsListFc(props: Props) { - const [w2lResults, setW2lResults] = useState>([]); + const [ttsResults, setTtsResults] = useState>([]); + + const [currentCursor, setCurrentCursor] = useState(null); + const [nextCursor, setNextCursor] = useState(null); + const [previousCursor, setPreviousCursor] = useState(null); + + const getPage = useCallback((cursor : string|null, reverse: boolean) => { + console.log('get page', cursor); + + let args : ListTtsInferenceResultsForUserArgs = { + username: props.username , + limit: 5, + }; + + if (cursor !== null) { + args.cursor = cursor; + if (reverse) { + args.cursor_is_reversed = true; + } + } - useEffect(() => { const api = new ApiConfig(); - const endpointUrl = api.listTtsInferenceResultsForUser({username: props.username }); + const endpointUrl = api.listTtsInferenceResultsForUser(args); fetch(endpointUrl, { method: 'GET', @@ -43,21 +63,55 @@ function ProfileTtsInferenceResultsListFc(props: Props) { }) .then(res => res.json()) .then(res => { - const templatesResponse : TtsInferenceResultListResponsePayload = res; - if (!templatesResponse.success) { + const modelsResponse : TtsInferenceResultListResponsePayload = res; + if (!modelsResponse.success) { return; } - setW2lResults(templatesResponse.results) + setTtsResults(modelsResponse.results) + setNextCursor(modelsResponse.cursor_next || null) + setPreviousCursor(modelsResponse.cursor_previous || null) }) .catch(e => { //this.props.onSpeakErrorCallback(); }); - }, [props.username]); // NB: Empty array dependency sets to run ONLY on mount + }, [props.username]); + + useEffect(() => { + getPage(null, false); +// let args : ListTtsInferenceResultsForUserArgs = { +// username: props.username , +// limit: 5, +// }; +// +// const api = new ApiConfig(); +// const endpointUrl = api.listTtsInferenceResultsForUser(args); +// +// fetch(endpointUrl, { +// method: 'GET', +// headers: { +// 'Accept': 'application/json', +// }, +// credentials: 'include', +// }) +// .then(res => res.json()) +// .then(res => { +// const modelsResponse : TtsInferenceResultListResponsePayload = res; +// if (!modelsResponse.success) { +// return; +// } +// +// setTtsResults(modelsResponse.results) +// setNextCursor(modelsResponse.cursor_next || null) +// }) +// .catch(e => { +// //this.props.onSpeakErrorCallback(); +// }); + }, [getPage, props.username]); // NB: Empty array dependency sets to run ONLY on mount let rows : Array = []; - w2lResults.forEach(result => { + ttsResults.forEach(result => { let duration_seconds = result.duration_millis / 1000; let inferenceLink = `/tts/result/${result.tts_result_token}`; @@ -65,7 +119,13 @@ function ProfileTtsInferenceResultsListFc(props: Props) { rows.push( - ▶️ Result + + ▶️ Result +   + + + {result.raw_inference_text} + Model {duration_seconds} s {result.created_at} @@ -78,8 +138,9 @@ function ProfileTtsInferenceResultsListFc(props: Props) { - - + + + @@ -88,6 +149,9 @@ function ProfileTtsInferenceResultsListFc(props: Props) { {rows}
Result LinkTemplateDownload & Play LinkRaw TextModel Duration Creation Date (UTC)
+ +   + ) }