1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-04 20:55:19 +02:00

Refactor success toast and show appropriate messages

This commit is contained in:
Sean Morley 2024-04-11 18:18:35 +00:00
parent 53f7f90dbc
commit af07ea29ef
2 changed files with 6 additions and 7 deletions

View file

@ -4,6 +4,6 @@
<div class="toast toast-top toast-end z-50"> <div class="toast toast-top toast-end z-50">
<div class="alert alert-info"> <div class="alert alert-info">
<span>Adventure {action} successfully!</span> <span>{action}</span>
</div> </div>
</div> </div>

View file

@ -48,12 +48,10 @@
function showToast(action: string) { function showToast(action: string) {
toastAction = action; toastAction = action;
isShowingToast = true; isShowingToast = true;
console.log("showing toast");
setTimeout(() => { setTimeout(() => {
isShowingToast = false; isShowingToast = false;
toastAction = ""; toastAction = "";
console.log("hiding toast");
}, 3000); }, 3000);
} }
@ -87,7 +85,7 @@
]; ];
newName = ""; // Reset newName and newLocation after adding adventure newName = ""; // Reset newName and newLocation after adding adventure
newLocation = ""; newLocation = "";
showToast("added"); showToast("Adventure added successfully!");
visitCount.update((n) => n + 1); visitCount.update((n) => n + 1);
}) })
.catch((error) => { .catch((error) => {
@ -121,7 +119,7 @@
editName = ""; editName = "";
editLocation = ""; editLocation = "";
editCreated = ""; editCreated = "";
showToast("edited"); showToast("Adventure edited successfully!");
}) })
.catch((error) => { .catch((error) => {
console.error("Error:", error); console.error("Error:", error);
@ -155,6 +153,7 @@
console.log("Success:", data); console.log("Success:", data);
let url = window.location.origin + "/shared/" + key; let url = window.location.origin + "/shared/" + key;
navigator.clipboard.writeText(url); navigator.clipboard.writeText(url);
showToast("Link copied to clipboard!");
}) })
.catch((error) => { .catch((error) => {
console.error("Error:", error); console.error("Error:", error);
@ -180,7 +179,7 @@
console.log("Success:", data); console.log("Success:", data);
// remove adventure from array where id matches // remove adventure from array where id matches
adventures = []; adventures = [];
showToast("removed"); showToast("Adventure removed successfully!");
visitCount.set(0); visitCount.set(0);
}) })
.catch((error) => { .catch((error) => {
@ -205,7 +204,7 @@
adventures = adventures.filter( adventures = adventures.filter(
(adventure) => adventure.id !== event.detail, (adventure) => adventure.id !== event.detail,
); );
showToast("removed"); showToast("Adventure removed successfully!");
visitCount.update((n) => n - 1); visitCount.update((n) => n - 1);
}) })
.catch((error) => { .catch((error) => {