Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Fetch data from the API
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Nov 24, 2023
1 parent f38c667 commit 5772972
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 1 addition & 4 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Chess\Heuristics\EvalFunction;
use Chess\Heuristics\SanHeuristics;
use Chess\Variant\Classical\Board as ClassicalBoard;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App;
use Slim\Http\Response as Response;
Expand All @@ -31,10 +30,8 @@

// TODO: Parameter validation

$board = new ClassicalBoard();

$evalFunction = new EvalFunction();
$heuristics = new SanHeuristics($params['movetext'], $board);
$heuristics = new SanHeuristics($params['movetext']);

$json = [
'evalNames' => $evalFunction->names(),
Expand Down
21 changes: 18 additions & 3 deletions public/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
const gameForm = document.getElementById('gameForm');

gameForm.querySelector('button').onclick = (event) => {
// TODO: Send the data to the /api/heuristics endpoint
console.log(gameForm.querySelector('textarea').value);
gameForm.querySelector('button').onclick = async (event) => {
event.preventDefault();
await fetch(`http://localhost:8080/api/heuristics`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
movetext: gameForm.querySelector('textarea').value
})
})
.then(res => res.json())
.then(res => {
// TODO
console.log(res);
})
.catch(error => {
alert('Whoops! Something went wrong, please try again.');
});
}

0 comments on commit 5772972

Please sign in to comment.