cinema/genre-selector.riot
2022-04-01 22:49:14 +02:00

49 lines
1.1 KiB
Plaintext

<genre-selector>
<select id="genre-selector-sel" onchange={choisi}></select>
<script>
const NOTHING = 0;
const RECHERCHE = 1;
const GET_GENRES = 2;
export default {
state: {
loading: false,
error: null,
},
reset() {
this.update({
loading: false,
error: null,
})
},
choisi(e){
this.props.t_changer(e.target.value);
}
}
fetch("https://api.themoviedb.org/3/genre/movie/list?api_key=64a9b2af6577bd1f5553143e0eacd4a8&language=fr")
.then(result => result.json())
.then( genres => {
let selecteur = document.getElementById("genre-selector-sel");
const tout = document.createElement("option");
tout.setAttribute("value", 666);
tout.innerHTML = "Tout";
selecteur.appendChild(tout);
for(let i = 0 ; i < genres.genres.length ; i++){
const newOption = document.createElement("option");
newOption.setAttribute("value", genres.genres[i].id);
newOption.innerHTML = genres.genres[i].name;
selecteur.appendChild(newOption);
}
});
</script>
</genre-selector>