Skip to content

Commit

Permalink
avance
Browse files Browse the repository at this point in the history
  • Loading branch information
waldoosg committed Oct 29, 2024
1 parent 7e29020 commit 2e3d30a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
addMoneyToWallet as addMoneyService
} from './services/apiService.jsx';

import {
madeRecommendations
} from './workers-functions.js';

function App() {
const { loginWithRedirect, logout, isAuthenticated, user, getAccessTokenSilently } = useAuth0();
const [fixtures, setFixtures] = useState([]);
Expand Down Expand Up @@ -231,13 +235,19 @@ function App() {
}
};

const makeRecommendations = async () => {
let userId = localStorage.getItem('userId');
const result = await madeRecommendations(userId);
console.log(result);
};

const handleShowResultsClick = () => {
// Code to show results
};

return (
<div className="App">
<header className="App-header">
{isAuthenticated ? (
<>
<img src={user.picture} alt={user.name} className="App-logo" />
<p>Welcome, {user.name}</p>
<header className="App-header"></header>
<button onClick={handleLogout}>
Log Out
</button>
Expand All @@ -253,6 +263,10 @@ function App() {
<p>Worker Status: {workerAvailable ? 'Available' : 'Unavailable'}</p>
</div>

<div>
<button onClick={() => makeRecommendations()}>View Recommendation</button>
</div>

<div className="filters">
<input
type="text"
Expand Down
50 changes: 50 additions & 0 deletions src/workers-functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import axios from 'axios';

async function postRecomendations(id) {
const body = {
id: id
};
const response = await axios.post(`https://nodecraft.me/recommendations/`, body);
return response.data;
}

async function getRecomendations(id) {
const response = await axios.get(`https://nodecraft.me/recommendations/${id}`);
return response.data;
}

async function Recommendations(data) {
const fixtures = data.result;
const requests = fixtures.map(async (fixture) => {
const response = await axios.get(`https://nodecraft.me/fixtures/${fixture}`);
// Do something with the response
return response.data; // Return the response data if needed
});

const responses = await Promise.all(requests);
return responses;
}

async function getHistory(id) {
const response = await axios.get(`https://nodecraft.me/recommendations/${id}/history`);
const filteredData = response.data.filter(item => item.response != {});
console.log(filteredData);
return filteredData;
}

async function madeRecommendations(id) {
const job = await postRecomendations(id);
const data = await getRecomendations(id);
const result = await Recommendations(data);
return result;
}


//console.log(await Recommendations(fixtures));



export {
getHistory,
madeRecommendations
};

0 comments on commit 2e3d30a

Please sign in to comment.