diff --git a/src/AboutView.js b/src/AboutView.js index 50c6f8837ce241f13eb189189a9817f79a66b6b5..c1d1e06bb412320a40f9e6a08805fa688cd55be3 100644 --- a/src/AboutView.js +++ b/src/AboutView.js @@ -1,32 +1,18 @@ 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(); } } diff --git a/src/GameListView.js b/src/GameListView.js index 9ba8454aa32cd8220f04f8d0d271a99e02c51f18..6e4d03be044d3eb817c7354ee1af6bb6de7ecd5f 100644 --- a/src/GameListView.js +++ b/src/GameListView.js @@ -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 diff --git a/src/main.js b/src/main.js index 50f31d0320225dc73e2973c8bb1c47172bdbefb2..8c925367c147dd673f00182cff7987bd4a880f00 100644 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,8 @@ 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 +=