diff --git a/vocodes/src/common/ApiConfig.ts b/vocodes/src/common/ApiConfig.ts index d08dc4cf6e..2913a04d1f 100644 --- a/vocodes/src/common/ApiConfig.ts +++ b/vocodes/src/common/ApiConfig.ts @@ -1,4 +1,11 @@ -import { url } from "inspector"; + +export interface ListTtsInferenceResultsForUserArgs { + username: string, + cursor?: string, + cursor_is_reversed?: boolean, + sort_ascending?: boolean, + limit?: number +}; class ApiConfig { @@ -53,34 +60,28 @@ class ApiConfig { return `${this.getScheme()}://${this.getNewApiHost()}/user/${username}/tts_models`; } - listTtsInferenceResultsForUser( - username: string, - cursor?: string, - cursor_is_reversed?: boolean, - sort_ascending?: boolean, - limit?: number, - ) : string { - const base_url = `${this.getScheme()}://${this.getNewApiHost()}/user/${username}/tts_results`; + listTtsInferenceResultsForUser(params: ListTtsInferenceResultsForUserArgs) : string { + const base_url = `${this.getScheme()}://${this.getNewApiHost()}/user/${params.username}/tts_results`; let query = ""; let query_prepend = "?"; - if (cursor !== undefined) { - query += `${query_prepend}cursor=${cursor}`; + if (params.cursor !== undefined) { + query += `${query_prepend}cursor=${params.cursor}`; query_prepend = "&"; - if (cursor_is_reversed !== undefined) { - query += `${query_prepend}cursor_is_reversed=${cursor_is_reversed}`; + if (params.cursor_is_reversed !== undefined) { + query += `${query_prepend}cursor_is_reversed=${params.cursor_is_reversed}`; } } - if (sort_ascending !== undefined) { - query += `${query_prepend}sort_ascending=${sort_ascending}`; + if (params.sort_ascending !== undefined) { + query += `${query_prepend}sort_ascending=${params.sort_ascending}`; query_prepend = "&"; } - if (limit !== undefined) { - query += `${query_prepend}limit=${limit}`; + if (params.limit !== undefined) { + query += `${query_prepend}limit=${params.limit}`; } return base_url + query; diff --git a/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx b/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx index 7692ab3903..ce295eeb4c 100644 --- a/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx +++ b/vocodes/src/v2/profile/Profile_TtsInferenceResultListFc.tsx @@ -32,7 +32,7 @@ function ProfileTtsInferenceResultsListFc(props: Props) { useEffect(() => { const api = new ApiConfig(); - const endpointUrl = api.listTtsInferenceResultsForUser(props.username); + const endpointUrl = api.listTtsInferenceResultsForUser({username: props.username }); fetch(endpointUrl, { method: 'GET', diff --git a/vocodes/src/v2/profile/Profile_TtsInferenceResultListTableFc.tsx b/vocodes/src/v2/profile/Profile_TtsInferenceResultListTableFc.tsx index a9821cb30f..da125bac20 100644 --- a/vocodes/src/v2/profile/Profile_TtsInferenceResultListTableFc.tsx +++ b/vocodes/src/v2/profile/Profile_TtsInferenceResultListTableFc.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { ApiConfig } from '../../common/ApiConfig'; +import { ApiConfig, ListTtsInferenceResultsForUserArgs } from '../../common/ApiConfig'; import { useTable, usePagination, } from 'react-table'; interface TtsInferenceResultListResponsePayload { @@ -36,9 +36,10 @@ function Table({ fetchData, loading, pageCount: controlledPageCount, + nextCursor, } : any) { - console.log(columns, data, fetchData, loading, controlledPageCount); + //console.log(columns, data, fetchData, loading, controlledPageCount); const { getTableProps, @@ -60,20 +61,23 @@ function Table({ { columns, data, - //initialState: { pageIndex: 0 }, // Pass our hoisted table state - //manualPagination: true, // Tell the usePagination + initialState: { pageIndex: 0, pageSize: 5 }, // Pass our hoisted table state + manualPagination: true, // Tell the usePagination // hook that we'll handle our own data fetching // This means we'll also have to provide our own // pageCount. - //pageCount: controlledPageCount, - }, + pageCount: -1, + } as any, usePagination ) as any + //console.log('nextCursor', nextCursor) + // Listen for changes in pagination and use the state to fetch our new data React.useEffect(() => { - fetchData({ pageIndex, pageSize }) - }, [fetchData, pageIndex, pageSize]) + //console.log('calliong fetchData', nextCursor) + fetchData({ pageIndex, pageSize, nextCursor }) + }, [fetchData, pageIndex, pageSize, nextCursor]) @@ -190,14 +194,18 @@ function Table({ function ProfileTtsInferenceResultsListTableFc(props: Props) { - const [w2lResults, setW2lResults] = useState>([]); + const [ttsResults, setTtsResults] = useState>([]); + const [data, setData] = useState>([]) const [loading, setLoading] = useState(false); + const [nextCursor, setNextCursor] = useState(undefined); + const [previousCursor, setPreviousCursor] = useState(undefined); + const columns = React.useMemo( () => [ { - Header: 'Result Link', + Header: 'RESULT LINK', accessor: 'col1', // TODO: Can be function into data }, { @@ -216,7 +224,7 @@ function ProfileTtsInferenceResultsListTableFc(props: Props) { [] ); - const data = React.useMemo( + /*const data = React.useMemo( () => [ { col1: 'Hello', @@ -238,14 +246,31 @@ function ProfileTtsInferenceResultsListTableFc(props: Props) { }, ], [] - ); + );*/ // TODO: Fix types here. - const tableInstance = useTable({ columns : columns as any, data }) + //const tableInstance = useTable({ columns : columns as any, data }) - const fetchData = React.useCallback(( { pageSize, pageToken } ) => { + + const fetchData = React.useCallback(( { pageSize, pageToken, nextCursor} ) => { const api = new ApiConfig(); - const endpointUrl = api.listTtsInferenceResultsForUser(props.username); + + //console.log('callback args', pageSize, pageToken, nextCursor) + + let args : ListTtsInferenceResultsForUserArgs = { + username: props.username, + limit: 5, + }; + + //if (nextCursor !== undefined) { + // args.cursor = nextCursor; + //} + + //console.log('nextCursor', nextCursor); + + const endpointUrl = api.listTtsInferenceResultsForUser(args); + + //console.log('url', endpointUrl); setLoading(true) @@ -258,12 +283,33 @@ function ProfileTtsInferenceResultsListTableFc(props: Props) { }) .then(res => res.json()) .then(res => { - const templatesResponse : TtsInferenceResultListResponsePayload = res; - if (!templatesResponse.success) { + const modelResponse : TtsInferenceResultListResponsePayload = res; + if (!modelResponse.success) { return; } - setW2lResults(templatesResponse.results) + //console.log('response', modelResponse) + + setTtsResults(modelResponse.results); + + + setNextCursor(modelResponse.cursor_next || undefined); + //setPreviousCursor(modelResponse.cursor_previous|| undefined); + + //console.log('callback nextCursor', nextCursor); + + let data : any[] = []; + + modelResponse.results.forEach(result => { + data.push({ + col1: result.raw_inference_text, + col2: result.raw_inference_text, + col3: result.tts_model_token, + col4: result.created_at, + }); + }) + + setData(data); setLoading(false); }) .catch(e => { @@ -273,44 +319,30 @@ function ProfileTtsInferenceResultsListTableFc(props: Props) { }, []); - useEffect(() => { - const api = new ApiConfig(); - const endpointUrl = api.listTtsInferenceResultsForUser(props.username); - - fetch(endpointUrl, { - method: 'GET', - headers: { - 'Accept': 'application/json', - }, - credentials: 'include', - }) - .then(res => res.json()) - .then(res => { - const templatesResponse : TtsInferenceResultListResponsePayload = res; - if (!templatesResponse.success) { - return; - } - - setW2lResults(templatesResponse.results) - }) - .catch(e => { - //this.props.onSpeakErrorCallback(); - }); - }, [props.username]); // NB: Empty array dependency sets to run ONLY on mount - - - const { - getTableProps, - getTableBodyProps, - headerGroups, - rows, - prepareRow, - } = tableInstance; +// const { +// getTableProps, +// getTableBodyProps, +// headerGroups, +// rows, +// prepareRow, +// } = tableInstance; return (
- + test +
+ + {/*
{// Loop over the header rows @@ -328,21 +360,15 @@ function ProfileTtsInferenceResultsListTableFc(props: Props) { ))} - {/* Apply the table body props */} - {// Loop over the table rows rows.map(row => { // Prepare the row for display prepareRow(row) return ( - // Apply the row props - {// Loop over the rows cells row.cells.map(cell => { - // Apply the cell props return ( ) @@ -352,6 +378,7 @@ function ProfileTtsInferenceResultsListTableFc(props: Props) { })}
- {// Render the cell contents cell.render('Cell')}
+ */}
)