Commit d023f720 authored by Carlos's avatar Carlos

feching API

parent 3025e6fd
VITE_DATA_MODE=mock
VITE_API_ENDPOINT=
\ No newline at end of file
VITE_DATA_MODE=api
VITE_API_ENDPOINT=https://loyalty-points-bank-data-service-prod.apps.cfcommerce.prod.azeus.gaptech.com/summary/pre-screen
VITE_DATA_MODE=api
VITE_API_ENDPOINT=
VITE_DATA_MODE=api
VITE_API_ENDPOINT=
\ No newline at end of file
...@@ -4,28 +4,20 @@ ...@@ -4,28 +4,20 @@
@layer components { @layer components {
/* This won't be included in your compiled CSS unless you actually use it */ /* This won't be included in your compiled CSS unless you actually use it */
h3{ h3 {
@apply font-bold text-lg; @apply font-bold text-lg;
} }
/* #findings-section {
.dashboard-body{ @apply mt-4 max-h-96 overflow-scroll;
@apply flex flex-wrap items-stretch; div {
>div{ @apply mb-8 border rounded-lg h-16;
@apply mr-2 mb-2 flex-grow; @apply flex flex-col justify-center;
} }
} div:last-child {
.legend-row { @apply mb-0
@apply flex justify-center pl-14 mb-1.5;
> div {
@apply flex mr-2 w-24 text-gray;
> div {
@apply w-4 h-4 mr-2 rounded-sm;
}
} }
} }
*/
} }
#root { #root {
...@@ -55,19 +47,19 @@ ...@@ -55,19 +47,19 @@
} }
.speaking { .speaking {
background: linear-gradient(-45deg, #ee7752, #4caf50, #23a6d5, #23d5ab); background: linear-gradient(-45deg, #ee7752, #4caf50, #23a6d5, #23d5ab);
background-size: 400% 400%; background-size: 400% 400%;
animation: gradient 2s ease infinite; animation: gradient 2s ease infinite;
} }
@keyframes gradient { @keyframes gradient {
0% { 0% {
background-position: 0% 50%; background-position: 0% 50%;
} }
50% { 50% {
background-position: 100% 50%; background-position: 100% 50%;
} }
100% { 100% {
background-position: 0% 50%; background-position: 0% 50%;
} }
} }
...@@ -2,6 +2,8 @@ import "./App.css"; ...@@ -2,6 +2,8 @@ import "./App.css";
// https://socket.dev/npm/package/react-hook-speech-to-text // https://socket.dev/npm/package/react-hook-speech-to-text
import useSpeechToText from "react-hook-speech-to-text"; import useSpeechToText from "react-hook-speech-to-text";
import micIcon from "./assets/1608550_microphone_icon.png"; import micIcon from "./assets/1608550_microphone_icon.png";
import useFetch from "./hooks/useFetch";
import { useEffect } from "react";
function App() { function App() {
const { const {
...@@ -9,6 +11,7 @@ function App() { ...@@ -9,6 +11,7 @@ function App() {
interimResult, interimResult,
isRecording, isRecording,
results, results,
setResults,
startSpeechToText, startSpeechToText,
stopSpeechToText, stopSpeechToText,
} = useSpeechToText({ } = useSpeechToText({
...@@ -16,12 +19,30 @@ function App() { ...@@ -16,12 +19,30 @@ function App() {
useLegacyResults: false, useLegacyResults: false,
}); });
const {
get,
loading,
error: responseError,
response,
} = useFetch(`${import.meta.env.VITE_API_ENDPOINT}/todos`);
useEffect(() => {
if (results.length > 0) {
(async () => {
await get();
})();
}
}, [results]);
// display: flex; // display: flex;
// flex-direction: column; // flex-direction: column;
// align-items: center; // align-items: center;
console.log(interimResult);
if (error) return <p>Web Speech API is not available in this browser 🤷‍</p>; if (error) return <p>Web Speech API is not available in this browser 🤷‍</p>;
console.log("response: ", response);
console.log("responseError: ", responseError);
const text = results.length > 0 && results[results.length - 1].transcript;
return ( return (
<> <>
...@@ -32,7 +53,9 @@ function App() { ...@@ -32,7 +53,9 @@ function App() {
</div> </div>
<div className={`mt-5 flex flex-col items-center`}> <div className={`mt-5 flex flex-col items-center`}>
<div <div
onMouseDown={startSpeechToText} onMouseDown={() => {
startSpeechToText();
}}
onMouseUp={stopSpeechToText} onMouseUp={stopSpeechToText}
className={`w-16 border border-solid rounded-full cursor-pointer p-2.5 ${ className={`w-16 border border-solid rounded-full cursor-pointer p-2.5 ${
isRecording && "speaking" isRecording && "speaking"
...@@ -42,11 +65,24 @@ function App() { ...@@ -42,11 +65,24 @@ function App() {
</div> </div>
{isRecording && <span className="text-sm">Listening...</span>} {isRecording && <span className="text-sm">Listening...</span>}
<ul className="mt-5 italic"> <ul className="mt-5 italic">
{results.map((result) => ( {text && `Showing results for: ${text}`}
<li key={result.timestamp}>{`Looking for: "${result.transcript}"`}</li> {/* {results.map(result => {
))} return (
<li key={result.timestamp}>{`Looking for: "${result.transcript}"`}</li>
)
})} */}
{/* {interimResult && <li>{interimResult}</li>} */} {/* {interimResult && <li>{interimResult}</li>} */}
</ul> </ul>
{loading && `Hold on a bit please!`}
{!loading && !responseError && response && response.length > 0 && (
<div id="findings-section">
{response.map((content) => {
return <div>{content.title}</div>;
})}
</div>
)}
</div> </div>
</> </>
); );
......
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useState } from "react";
interface IUseFecth {
get: (params?: string) => Promise<void>;
error: any;
response: any;
loading: boolean;
}
const getFullUrl = (apiHost: string, params?: string) => {
return params ? `${apiHost}?${params}` : apiHost;
};
const useFecth = function (apiUrl: string): IUseFecth {
const [error, setError] = useState<any>(null);
const [response, setResponse] = useState<any | null>(null);
const [loading, setLoading] = useState(false);
const get = async (params?: string) => {
setLoading(true);
fetch(new Request(getFullUrl(apiUrl, params)))
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then((response) => {
setResponse(response);
setError(null);
setLoading(false);
}).catch((error)=>{
setError(error);
console.log(error)
});
};
return { get, error, loading, response };
};
export default useFecth;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment