Skip to content
Snippets Groups Projects
Commit e8d54df1 authored by Noe Decobecq's avatar Noe Decobecq
Browse files

c'est bon je rigolais ca marche

parent d12c80c7
No related branches found
No related tags found
No related merge requests found
import View from './View.js';
import Router from './Router.js';
export default class AboutView extends View {
element;
export class AboutView extends View {
constructor(element) {
super(element);
this.element = document.querySelector('.about');
}
showFileContent(html) {
this.element.innerHTML = html;
}
OnClickSupport(event) {
event.preventDefault();
Router.navigate('/help');
}
show() {
super.show();
fetch('./about.html')
.then(response => response.text())
.then(responseText => this.showFileContent(responseText))
.then(() =>
this.element
.querySelector('.button')
.addEventListener('click', event => this.OnClickSupport(event))
);
.then(responseText => this.showFileContent(responseText));
}
showFileContent(html) {
this.element.innerHTML = html;
super.show();
}
}
......@@ -34,42 +34,36 @@ export default class GameListView extends View {
* @param {string} ordering ordre d'affichage des résultats
*/
renderGameList(search = '', ordering) {
// calcul de la fonction de tri selon le paramètre ordering
let sortingFunction;
switch (ordering) {
case '-metacritic':
sortingFunction = (a, b) => b.metacritic - a.metacritic;
break;
case '-released':
sortingFunction = (a, b) => b.released.localeCompare(a.released);
break;
}
// parcours du tableau + génération du code HTML de la gameList
let html = '';
this.element.querySelector('.results').classList.add('is-loading');
this.element.querySelector('.button submit').setAttribute('disabled', '');
fetch(
`https://api.rawg.io/api/games?search=${search}&ordering=${ordering}&key=7ed131e6be6b455ba809caad17f4f260`
`https://api.rawg.io/api/games?key=7ed131e6be6b455ba809caad17f4f260&search=${search}&ordering=${ordering}`
)
.then(response => response.text())
.then(() =>
this.element
.querySelector('.button submit')
.setAttribute('', 'disabled')
)
.then(res => JSON.parse(res))
.then(donne =>
donne.results.forEach(game => {
html += renderGameThumbnail(game);
})
.then(responseText => JSON.parse(responseText))
.then(games =>
games.results.forEach(game => (html += renderGameThumbnail(game)))
)
.then(() => (this.element.querySelector('.results').innerHTML = html))
.then(() =>
this.element.querySelector('.results').classList.remove('is-loading')
);
/*data
/*// calcul de la fonction de tri selon le paramètre ordering
let sortingFunction;
switch (ordering) {
case '-metacritic':
sortingFunction = (a, b) => b.metacritic - a.metacritic;
break;
case '-released':
sortingFunction = (a, b) => b.released.localeCompare(a.released);
break;
}
// parcours du tableau + génération du code HTML de la gameList
let html = '';
data
.filter(game => game.name.toLowerCase().includes(search.toLowerCase())) // recherche
.sort(sortingFunction) // tri
.forEach(game => (html += renderGameThumbnail(game))); // génération du HTML
......
import GameListView from './GameListView.js';
import HelpView from './HelpView.js';
import Router from './Router.js';
import AboutView from './AboutView.js';
import { AboutView } from './AboutView.js';
import View from './View.js';
// Modification du footer
document.querySelector('body > footer > div:nth-of-type(2)').innerHTML +=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment