ProjetRIOT/components/search.riot

55 lines
1.8 KiB
Plaintext

<search>
<label>
<input onkeydown={searchF} type="input" placeholder= {state.formation}>
<div id="list-formations">
<ul>
<li each={item in this.state.items}>
<a href={item.path} target="_blank">{item.name}</a>
<span>{item.count}</span>
</li>
</ul>
</div>
</label>
<script>
async function formation(){
let result = await fetch("https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&sort=tri&facet=fili&timezone=Europe%2FBerlin")
let resultats = await result.json()
let table = resultats["facet_groups"][0]["facets"]
return table
}
export default function search(){
return {
onBeforeMount(props, state) {
// initial state
this.state = {
formation: props.formation,
items: null,
allitems: null
}
formation().then((response) => {
this.update({
items: response,
allitems: response
})
})
},
searchF(e){
let responseFiltered=[]
this.state.allitems.forEach(formation => {
if (formation.name.includes(e.target.value)) {
responseFiltered.push(formation)
}
});
this.update({
items: responseFiltered
})
console.log(this.state.items)
}
}
}
</script>
</search>