Skip to content

Commit

Permalink
Merge pull request #186 from abes-esr/ITEM-413-front-afficher-plusieu…
Browse files Browse the repository at this point in the history
…rs-messages-en-meme-temps-sans-quils-ne-soient-supperposes

FIX ITEM-413-front-afficher-plusieurs-messages-en-meme-temps-sans-qui…
  • Loading branch information
SamuelQuetin authored Dec 5, 2024
2 parents 7143ef7 + 998b6ef commit 42c2d90
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<v-main class="d-flex flex-column overflow-auto">
<div class="notificationContainer">
<v-slide-y-transition group>
<v-alert
class="alertMessage"
v-for="notification in errorsNetworkList"
:key="notification[0]"
>
<p class="mb-4">{{ notification[1].message }}</p>
<p class="mb-4">{{ notification[1].description }}</p>
<div style="text-align: right"><v-btn @click="removeNotification(notification[0])" value="Fermer le message d'erreur">FERMER</v-btn></div>
</v-alert>
<v-alert
class="alertMessage"
v-for="notification in errorsList"
Expand Down Expand Up @@ -52,7 +61,9 @@ const alertType = ref(null)
const errorsList = ref(new Map())
let errorType = null
const errorsNetworkList = ref(new Map())
let isErrorNetwork = false
const authStore = useAuthStore();
Expand Down Expand Up @@ -85,7 +96,7 @@ function addError(error) {
description: ''
}
if(!error.response){
errorType = "ERR_NETWORK"
isErrorNetwork = true
newError.message = 'Erreur réseau : ' + error.code
newError.description = 'Service indisponible : merci de réessayer ultérieurement.'
}else{
Expand Down Expand Up @@ -131,20 +142,24 @@ function toggleDrawer() {
}
function addNotification(notificationId, message) {
errorsList.value.set(notificationId, message)
if (errorType === "ERR_NETWORK") {
if (isErrorNetwork) {
errorsNetworkList.value.set(notificationId, message)
setTimeout(() => removeNotification(notificationId), 9000) // impose un timeout au v-alert pour que les alertes de type ERR_NETWORK ne surchargent pas la Map errorsList
isErrorNetwork = false;
} else {
errorsList.value.set(notificationId, message)
}
}
function removeNotification(notificationId) {
if (notificationId != null) {
errorsList.value.delete(notificationId)
errorsNetworkList.value.delete(notificationId)
}
}
function clearErrors() {
errorsList.value = new Map()
errorsNetworkList.value.clear();
}
</script>
Expand Down

0 comments on commit 42c2d90

Please sign in to comment.