2025-11-18 21:16:35 -05:00
|
|
|
import { postData, verifyLogin } from "./client.js";
|
|
|
|
|
import { formatSalary } from "./utils.js";
|
|
|
|
|
|
|
|
|
|
const searchForm = document.getElementById("searchForm");
|
|
|
|
|
|
|
|
|
|
const token = window.localStorage.getItem("token");
|
|
|
|
|
|
|
|
|
|
const tableHeader = document.getElementById("header");
|
|
|
|
|
const tableBody = document.getElementById("results");
|
|
|
|
|
const table = document.getElementById("table");
|
|
|
|
|
const nomatch = document.getElementById("nomatch");
|
|
|
|
|
|
2025-11-26 21:10:22 -05:00
|
|
|
const watchButton = document.querySelector("#watch");
|
|
|
|
|
|
|
|
|
|
//const watchlist = await postData("/getWatchlist", {}, token);
|
|
|
|
|
|
2025-11-18 21:16:35 -05:00
|
|
|
populatePlayerData();
|
2025-11-26 21:10:22 -05:00
|
|
|
updateIsWatched();
|
|
|
|
|
|
|
|
|
|
watchButton.onclick = async e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
const [, , id] = window.location.pathname.split("/");
|
|
|
|
|
const resultObject = await postData("/toggleWatched", { id: id }, token);
|
2025-11-28 11:15:58 -05:00
|
|
|
//alert(resultObject.message);
|
2025-11-26 21:10:22 -05:00
|
|
|
updateIsWatched();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function updateIsWatched() {
|
|
|
|
|
const [, , id] = window.location.pathname.split("/");
|
|
|
|
|
const resultObject = await postData("/isWatched", {id: id}, token);
|
|
|
|
|
const isWatched = resultObject.isWatched;
|
|
|
|
|
watchButton.innerHTML = isWatched ? "Stop Watching Player" : "Watch Player";
|
|
|
|
|
}
|
2025-11-18 21:16:35 -05:00
|
|
|
|
|
|
|
|
async function populatePlayerData() {
|
|
|
|
|
const [, , id] = window.location.pathname.split("/");
|
|
|
|
|
const result = await postData("/getPlayer", { id: id }, window.localStorage.getItem("token"));
|
|
|
|
|
if (result.success === false) {
|
|
|
|
|
console.log("Invalid ID");
|
|
|
|
|
window.location.href = "/search";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const player = result.match;
|
|
|
|
|
for (const [attribute, value] of Object.entries(player)) {
|
|
|
|
|
console.log(`.attribute-${attribute}`);
|
|
|
|
|
document.querySelectorAll(`.attribute-${attribute}`).forEach(element => {
|
|
|
|
|
if (element.classList.contains("format-salary")) {
|
|
|
|
|
element.textContent = formatSalary(value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
element.textContent = value;
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.log(player);
|
|
|
|
|
}
|