ajout de la persistance des données et authentification

This commit is contained in:
2026-03-20 02:35:15 +01:00
parent 70aed67ba6
commit c3ba9c39c1
5 changed files with 1152 additions and 753 deletions
+49 -8
View File
@@ -2,12 +2,15 @@
<header class="site-header">
<div class="header-inner">
<a class="logo" href="#/">
<span class="logo-icon">🎓</span>
<span class="logo-icon"></span>
<span class="logo-text">Parcoursup <span class="logo-light">Explorer</span></span>
</a>
<a href="#/comparateur" class="header-badge badge-clickable" if={ state.selectedFormations.length > 0 }>
{ state.selectedFormations.length } sélection(s)
</a>
<div class="header-right">
<a href="#/comparateur" class="header-badge badge-clickable" if={ state.selectedFormations.length > 0 }>
{ state.selectedFormations.length } sélection(s)
</a>
<auth-panel user={ state.user } onauth={ onUserAuth } onlogout={ onUserLogout }></auth-panel>
</div>
</div>
</header>
@@ -158,7 +161,8 @@
filters: {},
page: 1,
limit: 20,
total: 0
total: 0,
user: null
},
onMounted() {
@@ -174,6 +178,23 @@
var self = this
// Écouter les changements d'authentification Firebase
window.firebaseServices.onUserChanged(function(user) {
self.update({ user: user })
if (user) {
// Charger la sélection depuis Firestore
window.firebaseServices.loadUserData(user.uid).then(function(data) {
if (data && data.selection) {
self.update({ selectedFormations: data.selection })
localStorage.setItem('selectionFormations', JSON.stringify(data.selection))
}
}).catch(function(err) {
console.error('Erreur chargement Firestore:', err)
})
}
})
window.addEventListener('hashchange', function() {
self.handleRoute()
})
@@ -181,6 +202,26 @@
this.handleRoute()
},
onUserAuth() {
// Appelé après connexion/inscription réussie — l'écouteur onUserChanged gère le reste
},
onUserLogout() {
// On garde la sélection locale après déconnexion
},
async saveSelection(selection) {
localStorage.setItem('selectionFormations', JSON.stringify(selection))
if (this.state.user) {
try {
await window.firebaseServices.saveUserData(this.state.user.uid, { selection: selection })
} catch (err) {
console.error('Erreur sauvegarde Firestore:', err)
}
}
},
handleRoute() {
var hash = window.location.hash || '#/'
var path = hash.slice(1) || '/'
@@ -330,7 +371,7 @@
if (!exists) {
selection.push(formation)
this.update({ selectedFormations: selection })
localStorage.setItem('selectionFormations', JSON.stringify(selection))
this.saveSelection(selection)
}
},
@@ -346,12 +387,12 @@
}
this.update({ selectedFormations: newSelection })
localStorage.setItem('selectionFormations', JSON.stringify(newSelection))
this.saveSelection(newSelection)
},
clearSelection() {
this.update({ selectedFormations: [] })
localStorage.setItem('selectionFormations', JSON.stringify([]))
this.saveSelection([])
},
updateNote(e) { this.update({ note: Number(e.target.value) }) },