Skip to content

Commit

Permalink
fix multiple count increase on multiple clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
ammakr committed Dec 5, 2024
1 parent ec9afbc commit 15ca223
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/components/DownloadTabs.astro
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,28 @@ import { data } from "src/javascript/downloadsData";
const button = document.getElementById(
`download-` + element.download_type
);
button?.addEventListener("click", (e) => {
let isRequestInProgress = false;
button?.addEventListener("click", function (e) {
e.preventDefault();
increaseCount(element.download_type);
console.log("it ran");
setTimeout(() => {
// @ts-expect-error
window.location.href = button.getAttribute("href");
}, 1000);
if (isRequestInProgress) {
return;
}
isRequestInProgress = true;

try {
increaseCount(element.download_type);
console.log("it ran");
setTimeout(() => {
// @ts-expect-error
window.location.href = button.getAttribute("href");
}, 1000);
} catch (e) {
console.log(e);
} finally {
setTimeout(() => {
isRequestInProgress = false;
}, 3000);
}
});
}
);
Expand Down

0 comments on commit 15ca223

Please sign in to comment.