35 lines
No EOL
1,010 B
JavaScript
35 lines
No EOL
1,010 B
JavaScript
|
|
const api_url = "http://127.0.0.1:8000"
|
|
|
|
var all_owned_games
|
|
|
|
async function makeAPIRequest(request) {
|
|
try {
|
|
const response = await fetch(request);
|
|
const result = await response.json();
|
|
return result
|
|
} catch (error) {
|
|
console.error("Error:", error);
|
|
}
|
|
}
|
|
|
|
function add_boardgame_row(html_table, boardgame_json) {
|
|
var row = html_table.insertRow()
|
|
var name_cell = row.insertCell();
|
|
var description_cell = row.insertCell()
|
|
|
|
name_cell.innerHTML = boardgame_json.name
|
|
description_cell.innerHTML = boardgame_json.description
|
|
}
|
|
|
|
async function loadOwnedGames() {
|
|
const loadGamesRequest = new Request(api_url + "/owned")
|
|
all_owned_games = await makeAPIRequest(loadGamesRequest)
|
|
|
|
console.log("Loaded owned games:", all_owned_games)
|
|
var boardgame_table = document.getElementById("boardgame_table")
|
|
|
|
for (index = 0; index < all_owned_games.length; index++) {
|
|
add_boardgame_row(boardgame_table, all_owned_games[index])
|
|
}
|
|
} |