This commit is contained in:
pro.boooooo 2023-03-08 02:26:00 +01:00
parent e49f55991b
commit f712039759

View File

@ -139,9 +139,9 @@
if(this.state.page.curIndex-1 >= 0) { if(this.state.page.curIndex-1 >= 0) {
if(this.state.page.curIndex === 0) { if(this.state.page.curIndex === 0) {
} else if(this.state.page.curIndex === 1) { } else if(this.state.page.curIndex === 1) {
this.getDataSection0(this.state.page.cat) this.getDataSection0()
} else if(this.state.page.curIndex === 2) { } else if(this.state.page.curIndex === 2) {
this.getDataSection1(this.state.page.cat) this.getDataSection1()
} }
if(this.state.page.curIndex !== 0) { /* Sinon ca va aller trop loin a la section 0. */ if(this.state.page.curIndex !== 0) { /* Sinon ca va aller trop loin a la section 0. */
@ -163,14 +163,14 @@
if(this.state.page.curIndex+1 <= 3 ) { if(this.state.page.curIndex+1 <= 3 ) {
if(this.state.page.curIndex === 0) { if(this.state.page.curIndex === 0) {
this.state.page.cat = `${ event.target.textContent }` this.state.page.cat = `${ event.target.textContent }`
this.getDataSection1(event.target.textContent) this.getDataSection1()
} else if(this.state.page.curIndex === 1) { } else if(this.state.page.curIndex === 1) {
this.getDataSection2(this.state.page.cat) this.getDataSection2(this.state.page.cat)
} else if(this.state.page.curIndex === 2) { } else if(this.state.page.curIndex === 2) {
} }
if(this.state.page.curIndex !== 2) { /* Sinon ca va aller trop loin a la section 2. */ if(this.state.page.curIndex !== 2) { /* Sinon ca va aller trop loin a la section 2. */
this.update({ curIndex: this.state.page.curIndex++ }); this.update({ curIndex: this.state.page.curIndex++ })
} }
} }
} catch(e) { } catch(e) {
@ -183,20 +183,30 @@
* Chaque getDataSectionN() sert a charge les donnees en fonction de la section choisit. * Chaque getDataSectionN() sert a charge les donnees en fonction de la section choisit.
* */ * */
async getDataSection0() { async getDataSection0() {
if(!localStorage.getItem("sec0")) {
try { try {
const link = `${ this.state.api.link }` + const link = `${ this.state.api.link }` +
`&facet=${this.state.api.facet.filiaire}`; `&facet=${this.state.api.facet.filiaire}`
const response = await fetch(link); const response = await fetch(link)
const data = await response.json(); const data = await response.json()
this.update({ data: data.facet_groups[0].facets }); this.update({ data: data.facet_groups[0].facets })
localStorage.setItem("sec0", JSON.stringify(data.facet_groups[0].facets))
} catch (e) { } catch (e) {
console.error(e); console.error(e)
}
} else {
try {
this.update({ data: JSON.parse(localStorage.getItem("sec0")) })
} catch(e) {
console.error(e)
}
} }
}, },
async getDataSection1() { async getDataSection1() {
if(!localStorage.getItem(`sec1-${this.state.page.cat}`)) {
try { try {
const link = `${this.state.api.link}` + const link = `${this.state.api.link}` +
`&facet=${this.state.api.facet.filiaire}` + `&facet=${this.state.api.facet.filiaire}` +
@ -204,16 +214,25 @@
`&facet=${this.state.api.facet.spec}` + `&facet=${this.state.api.facet.spec}` +
`&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}` `&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}`
const response = await fetch(link); const response = await fetch(link)
const data = await response.json(); const data = await response.json()
this.update({ data: data.facet_groups[1].facets }); this.update({data: data.facet_groups[1].facets})
localStorage.setItem(`sec1-${this.state.page.cat}`, JSON.stringify(data.facet_groups[1].facets))
} catch (e) { } catch (e) {
console.error(e); console.error(e)
}
} else {
try {
this.update({ data: JSON.parse(localStorage.getItem(`sec1-${this.state.page.cat}`)) })
} catch(e) {
console.error(e)
}
} }
}, },
async getDataSection2() { async getDataSection2() {
if(!localStorage.getItem(`sec2-${this.state.page.cat}`)) {
try { try {
const api = `${this.state.api.link}` + const api = `${this.state.api.link}` +
`&facet=${this.state.api.facet.filiaire}` + `&facet=${this.state.api.facet.filiaire}` +
@ -221,17 +240,25 @@
`&facet=${this.state.api.facet.spec}` + `&facet=${this.state.api.facet.spec}` +
`&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}` `&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}`
const response = await fetch(api); const response = await fetch(api)
const data = await response.json(); const data = await response.json()
this.update({ data: data.facet_groups[2].facets }); this.update({data: data.facet_groups[2].facets})
localStorage.setItem(`sec2-${this.state.page.cat}`, JSON.stringify(data.facet_groups[2].facets))
} catch (e) { } catch (e) {
console.error(e); console.error(e)
}
} else {
try {
this.update({ data: JSON.parse(localStorage.getItem(`sec2-${this.state.page.cat}`)) })
} catch(e) {
console.error(e)
}
} }
}, },
onBeforeMount() { onBeforeMount() {
this.getDataSection0(); this.getDataSection0()
}, },
}; };
</script> </script>