Merge branch 'dev' of github.com:JoaquinPar/2800-202510-BBY14 into fix/account_details_update
This commit is contained in:
5 files changed
+114
-75
No files matched your search
@@ -5,38 +5,47 @@ function getLocation() {
|
||||
}
|
||||
|
||||
function update(data) {
|
||||
document.getElementById("loading").style = "display: none";
|
||||
document.getElementById("currencyExchange").style = "display: flex";
|
||||
|
||||
document.getElementById("yourFlag").src = `/static/svgs/flags/${data.data.country}.svg`
|
||||
document.getElementById("yourFlag").alt = data.data.country;
|
||||
document.getElementById("flagTag").innerHTML = `(${data.data.country})`;
|
||||
|
||||
document.getElementById("exchangeFlag").src = `/static/svgs/flags/USD.svg`;
|
||||
document.getElementById("exchangeFlag").alt = "USD";
|
||||
document.getElementById("exFlagTag").innerHTML = "(USD)";
|
||||
if (data.data.message != "error") {
|
||||
document.getElementById("loading").style = "display: none";
|
||||
document.getElementById("currencyExchange").style = "display: flex";
|
||||
|
||||
document.getElementById("dropdown-country-button").value = data.data.toCurrencyRates["USD"];
|
||||
|
||||
updateExchange(document.getElementById("dropdown-country-button").value);
|
||||
|
||||
const dropdown = document.getElementById("dropdown");
|
||||
let countries = Object.keys(data.data.toCurrencyRates);
|
||||
|
||||
countries.forEach(item => {
|
||||
if (dropdown.querySelector(`button[value="${data.data.toCurrencyRates[item]}"]`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const listItem = document.createElement("li");
|
||||
listItem.innerHTML = `<button onclick="switchButton(this)" type="button" value="${data.data.toCurrencyRates[item]}" class="country Button inline-flex w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem">
|
||||
<span class="inline-flex items-center">
|
||||
<img src="/static/svgs/flags/${item}.svg" class="h-4 w-4 me-2" alt="${item}"> (${item})
|
||||
</span>
|
||||
</button>`;
|
||||
|
||||
dropdown.appendChild(listItem);
|
||||
});
|
||||
document.getElementById("yourFlag").src = `/static/svgs/flags/${data.data.country}.svg`
|
||||
document.getElementById("yourFlag").alt = data.data.country;
|
||||
document.getElementById("flagTag").innerHTML = `(${data.data.country})`;
|
||||
|
||||
document.getElementById("exchangeFlag").src = `/static/svgs/flags/USD.svg`;
|
||||
document.getElementById("exchangeFlag").alt = "USD";
|
||||
document.getElementById("exFlagTag").innerHTML = "(USD)";
|
||||
|
||||
document.getElementById("dropdown-country-button").value = data.data.toCurrencyRates["USD"];
|
||||
|
||||
updateExchange(document.getElementById("dropdown-country-button").value);
|
||||
|
||||
const dropdown = document.getElementById("dropdown");
|
||||
let countries = Object.keys(data.data.toCurrencyRates);
|
||||
|
||||
countries.forEach(item => {
|
||||
if (dropdown.querySelector(`button[value="${data.data.toCurrencyRates[item]}"]`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const listItem = document.createElement("li");
|
||||
listItem.innerHTML = `<button onclick="switchButton(this)" type="button" value="${data.data.toCurrencyRates[item]}" class="country Button inline-flex w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem">
|
||||
<span class="inline-flex items-center">
|
||||
<img src="/static/svgs/flags/${item}.svg" class="h-4 w-4 me-2" alt="${item}"> (${item})
|
||||
</span>
|
||||
</button>`;
|
||||
|
||||
dropdown.appendChild(listItem);
|
||||
});
|
||||
} else {
|
||||
document.getElementById("loading").style = "display: none";
|
||||
document.getElementById("exFrom").style = "display: none";
|
||||
document.getElementById("dropdown-country-button").style = "display: none";
|
||||
document.getElementById("currencyExchange").style = "display: flex";
|
||||
document.getElementById("exchange").innerHTML = "Country not supported";
|
||||
document.getElementById("exchange").className = "block rounded-lg text-center p-2.5 w-50 z-20 text-sm border bg-gray-700 border-gray-600 placeholder-gray-400 text-white focus:border-blue-500";
|
||||
}
|
||||
}
|
||||
|
||||
function switchButton(clickedButton) {
|
||||
@@ -60,10 +69,16 @@ async function getLatestExchange(position) {
|
||||
let lon = position.coords.longitude;
|
||||
const res = await fetch(`/exRates/${lat}/${lon}`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
update(data);
|
||||
}
|
||||
|
||||
function error(err) {
|
||||
console.error("Geolocation error: ", err);
|
||||
const data = {
|
||||
data: {
|
||||
message: "error"
|
||||
}
|
||||
}
|
||||
|
||||
update(data);
|
||||
}
|
||||
Reference in new issue
Block a user