Skip to content

Commit

Permalink
update displayToast
Browse files Browse the repository at this point in the history
  • Loading branch information
Neffi42 committed Oct 21, 2024
1 parent 78060f4 commit 274f14e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions django/src/ft_auth/templates/authentification.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h1 class="row">Johnny Depp</h1>

submitForm('register-form', () => {
route('/login');
displayToast("Account creation successful.");
displayToast("Account creation successful.", "bg-success");
}, (json) => {
document.getElementById('register-error').textContent = json.error;
emptyPasswords();
Expand Down Expand Up @@ -293,4 +293,4 @@ <h1 class="row">Johnny Depp</h1>
overflow-wrap: break-word;
}
</style>
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions django/src/ft_auth/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 class="form-title">Upload New Avatar</h2>

submitForm('password-form', () => {
route('/settings');
displayToast("Password changed successfully.");
displayToast("Password changed successfully.", "bg-success");
}, (json) => {
document.getElementById('password-error').textContent = json.error;
emptyPasswords();
Expand Down Expand Up @@ -144,7 +144,7 @@ <h2 class="form-title">Upload New Avatar</h2>
const avatarImg = document.querySelector('.profile-image-container img');
avatarImg.src = data.avatar_url;
hideModal();
displayToast("Avatar updated successfully.");
displayToast("Avatar updated successfully.", "bg-success");
} else {
alert('Error uploading avatar');
}
Expand Down
4 changes: 2 additions & 2 deletions django/src/games/templates/pong_tournament.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h2 class="text-start fs-4 fw-bold mb-3">{% trans "Match history" %}</h2>
case "join": handleJoin(data.players); break;
case "player_pairs": handlePlayerPairs(data.player_pairs); break;
case "next_round_id": route(`/pong/online/${data.id}/{{ name }}/${power}`); break;
case "bye": displayToast("You have received a bye for this round. Enjoy the break!"); break;
case "bye": displayToast("You have received a bye for this round. Enjoy the break!", "bg-info"); break;
case "history": handleHistory(data.history); break;
case "end": handleEnd(data.winner); break;
default: console.error("Invalid message from server ignored."); break;
Expand Down Expand Up @@ -182,7 +182,7 @@ <h2 class="text-start fs-4 fw-bold mb-3">{% trans "Match history" %}</h2>
const tableBody = document.querySelector("#players tbody");
const rowCount = tableBody.rows.length;
if (rowCount < 2) {
displayToast("You are alone in the tournament...");
displayToast("You are alone in the tournament...", "bg-warning");
return;
}
hideBtn(lockBtn);
Expand Down
4 changes: 2 additions & 2 deletions nginx/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div id="content"></div>

<div class="toast-container position-fixed bottom-0 end-0 p-3" style="z-index: 9001;">
<div id="toast" class="toast align-items-center text-white bg-success" role="alert" aria-live="assertive"
<div id="toast" class="toast align-items-center text-black" role="alert" aria-live="assertive"
aria-atomic="true">
<div class="d-flex">
<div class="toast-body" id="toast-content">
Expand All @@ -46,4 +46,4 @@
<script src="/js/sidebar.js"></script>
</body>

</html>
</html>
5 changes: 4 additions & 1 deletion nginx/src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ function logout() {
}).catch(error => console.error(error));
}

function displayToast(message) {
function displayToast(message, colorClass = "") {
const toastContentElement = document.getElementById('toast-content');
toastContentElement.textContent = message;
const toastElement = document.getElementById('toast');
toastElement.classList.remove('bg-success', 'bg-danger', 'bg-warning', 'bg-info', 'bg-primary', 'bg-secondary', 'bg-light', 'bg-dark');
if (colorClass !== "")
toastElement.classList.add(colorClass);
const toast = new bootstrap.Toast(toastElement);
toast.show();
}
Expand Down

0 comments on commit 274f14e

Please sign in to comment.