@@ -157,25 +157,21 @@ function renderPokemonIndex(pokemons: Array<Pokemon>): string {
157157 </tr>` )
158158 . join ( '\n' ) ;
159159
160- const descriptionsSelect = pokemon . pokedexDescriptions [ ]
160+ const descriptionsSelect = pokemon . pokedexDescriptions
161161 . map ( description => `
162162 <option value="${ description . version } " class="tag">${ description . version . charAt ( 0 ) . toUpperCase ( ) + description . version . slice ( 1 ) } </option>` )
163163 . join ( '\n' ) ;
164164
165- const descriptionsRows = pokemon . pokedexDescriptions [ ]
166- . map ( description => `
167- <p class="description" data-version='${ description . version } '>${ description . flavor_text } </p>` )
165+ const descriptionsRows = pokemon . pokedexDescriptions
166+ . map ( ( description , index ) => `
167+ <p class="description" data-version='${ description . version } ' style=" ${ index !== 0 ? 'display: none;' : '' } " >${ description . flavor_text } </p>` )
168168 . join ( '\n' ) ;
169169
170170 return `
171171 <html>
172172 ${ head ( pokemon . name ) }
173173 <body>
174174 <h1><a href="index.html" class="back-to-menu"><i class="fas fa-arrow-left"></i></a> ${ pokemon . name . charAt ( 0 ) . toUpperCase ( ) + pokemon . name . slice ( 1 ) } <span class="pokemon-id">#${ String ( pokemon . id ) . padStart ( 4 , '0' ) } </span></h1>
175- <h2 class="section-title">Pokédex Description</h2>
176- <select id="version-select" class="version-select">
177- ${ descriptionsSelect }
178- </select> ${ descriptionsRows }
179175 <div class="pokemon-container">
180176 <img src="${ pokemon . officialArtworkUrl } " alt="${ pokemon . name } " />
181177 <table>
@@ -204,23 +200,32 @@ function renderPokemonIndex(pokemons: Array<Pokemon>): string {
204200 ${ statsTableRows }
205201 </table>
206202 </div>
203+ <h2 class="section-title">Pokédex Description</h2>
204+ <div class="pokedex-container">
205+ <div class="version-container">
206+ <select id="version-select" class="version-select">
207+ ${ descriptionsSelect }
208+ </select>
209+ </div>
210+ <div class="description-container">
211+ ${ descriptionsRows }
212+ </div>
213+ </div>
207214 <a href="index.html" class="back-button">Back to Menu</a>
208215 <script>
209216 function filterVersions() {
210217 const selectedVersion = document.getElementById("version-select").value;
211218 const dexDescriptions = document.querySelectorAll(".description");
212219 for (const dexDescription of dexDescriptions) {
213- const version = JSON.parse(dexDescription.dataset.version);
214- const first_version = JSON.parse(dexDescriptions[0].dataset.version);
215- const versionMatch = (selectedVersion === "" && first_version === version) || (selectedVersion === version);
216- if (versionMatch) {
217- dexDescription.parentElement.style.display = "inline-block";
220+ const version = dexDescription.dataset.version;
221+ if (selectedVersion === version) {
222+ dexDescription.style.display = "block";
218223 } else {
219- dexDescription.parentElement. style.display = "none";
224+ dexDescription.style.display = "none";
220225 }
221226 }
222227 }
223- document.getElementById("version-select").addEventListener("input ", filterVersions);
228+ document.getElementById("version-select").addEventListener("change ", filterVersions);
224229 </script>
225230 </body>
226231 </html>` ;
@@ -284,7 +289,7 @@ function head(title: string): string {
284289}
285290
286291( async ( ) => {
287- const pokemons = await loadPokemons ( 1010 ) ;
292+ const pokemons = await loadPokemons ( 20 ) ;
288293 const indexHtml = renderPokemonIndex ( pokemons ) ;
289294 await writeFile ( "index.html" , indexHtml ) ;
290295
0 commit comments