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 === 0) {
} else if(this.state.page.curIndex === 1) {
this.getDataSection0(this.state.page.cat)
this.getDataSection0()
} 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. */
@ -163,14 +163,14 @@
if(this.state.page.curIndex+1 <= 3 ) {
if(this.state.page.curIndex === 0) {
this.state.page.cat = `${ event.target.textContent }`
this.getDataSection1(event.target.textContent)
this.getDataSection1()
} else if(this.state.page.curIndex === 1) {
this.getDataSection2(this.state.page.cat)
} else if(this.state.page.curIndex === 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) {
@ -183,55 +183,82 @@
* Chaque getDataSectionN() sert a charge les donnees en fonction de la section choisit.
* */
async getDataSection0() {
try {
const link = `${ this.state.api.link }` +
`&facet=${this.state.api.facet.filiaire}`;
if(!localStorage.getItem("sec0")) {
try {
const link = `${ this.state.api.link }` +
`&facet=${this.state.api.facet.filiaire}`
const response = await fetch(link);
const data = await response.json();
const response = await fetch(link)
const data = await response.json()
this.update({ data: data.facet_groups[0].facets });
} catch (e) {
console.error(e);
this.update({ data: data.facet_groups[0].facets })
localStorage.setItem("sec0", JSON.stringify(data.facet_groups[0].facets))
} catch (e) {
console.error(e)
}
} else {
try {
this.update({ data: JSON.parse(localStorage.getItem("sec0")) })
} catch(e) {
console.error(e)
}
}
},
async getDataSection1() {
try {
const link = `${ this.state.api.link }` +
`&facet=${ this.state.api.facet.filiaire }` +
`&facet=${ this.state.api.facet.formation }` +
`&facet=${ this.state.api.facet.spec }` +
`&refine.${this.state.api.facet.filiaire}=${ this.state.page.cat }`
if(!localStorage.getItem(`sec1-${this.state.page.cat}`)) {
try {
const link = `${this.state.api.link}` +
`&facet=${this.state.api.facet.filiaire}` +
`&facet=${this.state.api.facet.formation}` +
`&facet=${this.state.api.facet.spec}` +
`&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}`
const response = await fetch(link);
const data = await response.json();
const response = await fetch(link)
const data = await response.json()
this.update({ data: data.facet_groups[1].facets });
} catch (e) {
console.error(e);
this.update({data: data.facet_groups[1].facets})
localStorage.setItem(`sec1-${this.state.page.cat}`, JSON.stringify(data.facet_groups[1].facets))
} catch (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() {
try {
const api = `${ this.state.api.link }` +
`&facet=${ this.state.api.facet.filiaire }` +
`&facet=${ this.state.api.facet.formation }` +
`&facet=${ this.state.api.facet.spec }` +
`&refine.${this.state.api.facet.filiaire}=${ this.state.page.cat }`
if(!localStorage.getItem(`sec2-${this.state.page.cat}`)) {
try {
const api = `${this.state.api.link}` +
`&facet=${this.state.api.facet.filiaire}` +
`&facet=${this.state.api.facet.formation}` +
`&facet=${this.state.api.facet.spec}` +
`&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}`
const response = await fetch(api);
const data = await response.json();
const response = await fetch(api)
const data = await response.json()
this.update({ data: data.facet_groups[2].facets });
} catch (e) {
console.error(e);
this.update({data: data.facet_groups[2].facets})
localStorage.setItem(`sec2-${this.state.page.cat}`, JSON.stringify(data.facet_groups[2].facets))
} catch (e) {
console.error(e)
}
} else {
try {
this.update({ data: JSON.parse(localStorage.getItem(`sec2-${this.state.page.cat}`)) })
} catch(e) {
console.error(e)
}
}
},
onBeforeMount() {
this.getDataSection0();
this.getDataSection0()
},
};
</script>