Version 1.0.0 - Création du Header
This commit is contained in:
23
src/utils/Events.js
Normal file
23
src/utils/Events.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const Events = new Map()
|
||||
|
||||
export default {
|
||||
on(eventName, fn) {
|
||||
if(!Events.has(eventName)) {
|
||||
Events.set(eventName, [])
|
||||
}
|
||||
|
||||
Events.get(eventName).push(fn)
|
||||
},
|
||||
|
||||
off(eventName, fn) {
|
||||
throw {message:'Not implemented'}
|
||||
},
|
||||
emit(eventName, data) {
|
||||
if(Events.has(eventName)) {
|
||||
Events.get(eventName).forEach(fn => fn(data))
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
Events.clear()
|
||||
},
|
||||
}
|
@@ -11,6 +11,7 @@ import { useRouter } from 'vue-router';
|
||||
import { IOListener, IORequest } from '@/utils/IORequest';
|
||||
import { useUserStore } from '@/stores/userStore';
|
||||
import { useGlobalStore } from '@/stores/globalStore';
|
||||
import events from '@/utils/Events.js';
|
||||
|
||||
const router = useRouter();
|
||||
const interuptionMessage = ref(null);
|
||||
@@ -29,16 +30,15 @@ import { useGlobalStore } from '@/stores/globalStore';
|
||||
}
|
||||
|
||||
IOListener("/USER/READY", () => {
|
||||
IORequest("/USER/INFO", (data) => {
|
||||
IORequest("/USER/INFO", (data) => {
|
||||
interuptionMessage.value = null;
|
||||
userStore.setUserInfo(data);
|
||||
events.emit("UPDATE")
|
||||
console.log("User info received:", data);
|
||||
globalStore.setLoading(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
IOListener("AUTH_ERROR", (error) => {
|
||||
console.error("Authentication error:", error);
|
||||
loginStore.setToken(null);
|
||||
|
Reference in New Issue
Block a user