<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Danarkey</title>
    <description>The latest articles on DEV Community by Danarkey (@danarkey).</description>
    <link>https://dev.to/danarkey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1163221%2F2274124b-cd8a-4011-86ac-c1c559aa7313.jpg</url>
      <title>DEV Community: Danarkey</title>
      <link>https://dev.to/danarkey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danarkey"/>
    <language>en</language>
    <item>
      <title>The react pokedex pages</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Fri, 17 Nov 2023 03:45:11 +0000</pubDate>
      <link>https://dev.to/danarkey/the-react-pokedex-pages-39pd</link>
      <guid>https://dev.to/danarkey/the-react-pokedex-pages-39pd</guid>
      <description>&lt;p&gt;For a final post I feel like I should discuss the pages themselves and how they render the way they do. &lt;/p&gt;

&lt;h2&gt;
  
  
  Pokedex page
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IJfdsfww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvev5qf19v8g166ev09s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IJfdsfww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvev5qf19v8g166ev09s.png" alt="Image description" width="800" height="749"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ra0OTL7X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cikobef6iw5sp32n0dgj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ra0OTL7X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cikobef6iw5sp32n0dgj.png" alt="Image description" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import statements&lt;/li&gt;
&lt;li&gt;Functional component declaration for Pokedex component&lt;/li&gt;
&lt;li&gt;State hooks to create and manage state variables (when a component needs to “remember” some information between renders) within the pokedex component&lt;/li&gt;
&lt;li&gt;getAllPokemons function is responsible for fetching data about Pokemon from the PokeAPI. It updates the state with the fetched data and the URL for the next set of Pokemon.&lt;/li&gt;
&lt;li&gt;Modal interaction functions to make it visible/hidden&lt;/li&gt;
&lt;li&gt;useEffect hook is used here to run the getAllPokemons function when the component mounts (due to the empty dependency array []). This ensures that the initial set of Pokemon is fetched when the component is first rendered.&lt;/li&gt;
&lt;li&gt;JSX structure that defines how the component is rendered&lt;/li&gt;
&lt;li&gt;Export statement&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Favourites page
&lt;/h2&gt;

&lt;p&gt;Again the favourites page functions a little differently as it is fetching data from the json server rather than the API. Here is the code breakdown of the page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8_uV0r2C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewidndr8h1goy1r5dxpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8_uV0r2C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewidndr8h1goy1r5dxpd.png" alt="Image description" width="800" height="633"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jxnRFgju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80q5djqbdbm2p5lolfjk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jxnRFgju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80q5djqbdbm2p5lolfjk.png" alt="Image description" width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import statements&lt;/li&gt;
&lt;li&gt;Functional component declaration for the Favourites component&lt;/li&gt;
&lt;li&gt;The useState hooks create and manage state variables within the Favourites component. State allows the component to keep track of data that may change over time.&lt;/li&gt;
&lt;li&gt;The useEffect hook is used here to run the fetchFavourites function when the component mounts (due to the empty dependency array []). This ensures that the list of favorite Pokemon is fetched when the component is first rendered.&lt;/li&gt;
&lt;li&gt;Function to fetch favourite pokemon data - updates the state with the fetched data&lt;/li&gt;
&lt;li&gt;Modal interaction functions - open and close&lt;/li&gt;
&lt;li&gt;Function to update favourite pokemon - passed down to the FavouritesModal component. It updates the state with the latest list of favorite Pokemon after a Pokemon is added or removed.&lt;/li&gt;
&lt;li&gt;JSX structure to render the component&lt;/li&gt;
&lt;li&gt;Export statement&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;So that pretty much sums up the entire project and how I was able to make it. Big thanks to Albert for being an amazing mentor. If you want to check out the app you can access it here: &lt;a href="https://p2-app.vercel.app/pokedex"&gt;https://p2-app.vercel.app/pokedex&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React pokedex - FavouritesModal</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Fri, 17 Nov 2023 03:30:26 +0000</pubDate>
      <link>https://dev.to/danarkey/react-pokedex-favouritesmodal-3b8l</link>
      <guid>https://dev.to/danarkey/react-pokedex-favouritesmodal-3b8l</guid>
      <description>&lt;p&gt;Welcome back! From the previous post we are going to be discussing the FavouritesModal and how it differs from the PokemonModal when in reality they look indentical.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;As was previously mentioned, I couldn't simply use the same component in the same way as this page was fetching the data from the json server rather than the API.&lt;/p&gt;

&lt;p&gt;Now I'm sure there's a way to incorporate both so that you are saving just the pokemon's name in the backend and then you can fetch the relevant data from the API, however I couldn't figure that out and I was pulling out my hair at the best of times.&lt;/p&gt;

&lt;p&gt;So to get around that, all of the data that was being rendered on the modal I decided to pass to the json server so that we could simply get that data and render it on a new component.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;Here is the code for the FavouritesModal.jsx&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PuA1cUUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a3j314wlzfkwdu9ubtl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PuA1cUUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a3j314wlzfkwdu9ubtl.png" alt="Image description" width="800" height="567"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oxariuT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i4jtvb267kkbungtl24.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oxariuT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i4jtvb267kkbungtl24.png" alt="Image description" width="800" height="631"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9QH0uOIx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fibldugyqeup31cgczgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9QH0uOIx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fibldugyqeup31cgczgm.png" alt="Image description" width="800" height="624"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import statements&lt;/li&gt;
&lt;li&gt;Functional component declaration for pokemon, closeModal function, favourites and updateFavourites&lt;/li&gt;
&lt;li&gt;Type color mapping that maps pokemon types to specific colours&lt;/li&gt;
&lt;li&gt;Set default background colour to gray again if a type can’t be identified&lt;/li&gt;
&lt;li&gt;useState hook to create a piece of state (isInFavourites) and a function (setIsInFavourites) to manage whether the current Pokemon is in the user's favourites&lt;/li&gt;
&lt;li&gt;useEffect hook checks whether the current Pokemon is in the user's favorites and updates the state accordingly whenever the favourites array or the pokemon.id changes&lt;/li&gt;
&lt;li&gt;handleFavourites function is responsible for handling the addition or removal of a Pokemon from the user's favorites. It uses the fetch function to communicate with a server. If the Pokemon is already in the favorites, it removes it; otherwise, it adds it&lt;/li&gt;
&lt;li&gt;JSX structure for the modal component&lt;/li&gt;
&lt;li&gt;Export statement&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing remarks
&lt;/h2&gt;

&lt;p&gt;So that's the favourites modal for ya. Again I'm sure there's a more efficient way to do this so that you don't need a separate component but I found this method the easiest for myself!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React pokedex - component breakdown</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Fri, 17 Nov 2023 03:19:51 +0000</pubDate>
      <link>https://dev.to/danarkey/react-pokedex-component-breakdown-51d8</link>
      <guid>https://dev.to/danarkey/react-pokedex-component-breakdown-51d8</guid>
      <description>&lt;p&gt;The first proper component (sorry header and footer) I would need to create are the pokemon cards that would appear on the page. The plan was that the cards would have the dex number, image, name and the typing of pokemon. &lt;/p&gt;

&lt;p&gt;Once these cards are clicked a modal would pop up with more information and favourites button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the pokemon card component
&lt;/h2&gt;

&lt;p&gt;I know I wanted each card to be coloured with the corresponding type of each pokemon so we had to include some sort of styling variable.&lt;/p&gt;

&lt;p&gt;Pokemoncards.jsx:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--la1qODYb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuoaw9x9im3vmnhjc53b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--la1qODYb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuoaw9x9im3vmnhjc53b.png" alt="Image description" width="611" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The breakdown of how it works is here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functional component declaration that takes in the data parameters of id, image, name, type and openModal function.&lt;/li&gt;
&lt;li&gt;CSS class name styling that combines the ‘type’ property with the string “card-container”&lt;/li&gt;
&lt;li&gt;JSX structure for the content&lt;/li&gt;
&lt;li&gt;The outermost  has a class name assigned based on the style variable we defined earlier. It also has an onClick event that triggers the openModal function when the component is clicked.
&lt;/li&gt;
&lt;li&gt;Inside this container, there's another  displaying the Pokemon number (&lt;small&gt;#0{id}&lt;/small&gt;).
&lt;/li&gt;
&lt;li&gt;Depending on whether there's an image ({img ? ... : ...}), it renders either an &lt;img&gt; tag with the Pokemon image or a paragraph (&lt;p&gt;) saying "No image available."&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Finally, there's another  containing the Pokemon's name and type
&lt;/li&gt;
&lt;li&gt;Export statement so that the PokemonCard component can be used in other parts of the application&lt;/li&gt;


&lt;p&gt;In my App.css file I had declared a hex value for each pokemon type so that the cards would be coloured depending on that. In the future I would love to add some sort of colour effect for pokemon with multiple types. I had seen some people do a gradient if the pokemon was dual typed where the top of the card was one colour blending into a new colour at the bottom.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the pokemon modal component
&lt;/h2&gt;

&lt;p&gt;Unfortunately the pokemon modal component proved more difficult than the pokemon card which led me to having to create separate components for the favourited component and you'll see why shortly.&lt;/p&gt;

&lt;p&gt;PokemonModal.jsx:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p37dcYT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcavy3o5vmvfkbvmc2g9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p37dcYT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcavy3o5vmvfkbvmc2g9.png" alt="Image description" width="698" height="885"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6UbHqpl6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1d9bqgklwfh6ve9o4gry.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6UbHqpl6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1d9bqgklwfh6ve9o4gry.png" alt="Image description" width="706" height="930"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c2EoQpOo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2kqyxmkbrb6ekcyl2cn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c2EoQpOo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2kqyxmkbrb6ekcyl2cn.png" alt="Image description" width="800" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functional declaration for parameters pokemon, image, type and the closeModal function&lt;/li&gt;
&lt;li&gt;Object typeColorMap maps the pokemon types to specific colors&lt;/li&gt;
&lt;li&gt;modalStyle variable sets the background colour to gray if a type can’t be identified&lt;/li&gt;
&lt;li&gt;useState hook to create a piece of state isInFavourites and a function setIsInFavourites to manage whether the current pokemon is in the user’s favourites&lt;/li&gt;
&lt;li&gt;useEffect hook is used to fetch data when the component mounts or the pokemon.id changes – it checks if the current pokemon is in the user’s favourites and updates the state accordingly&lt;/li&gt;
&lt;li&gt;handleFavourites uses the fetch function to add or a remove a pokemon from the users favourites&lt;/li&gt;
&lt;li&gt;JSX structure to render the component&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing remarks
&lt;/h2&gt;

&lt;p&gt;As you can see the initial modal is fetching the data from the pokemon API. Once you add the pokemon to favourites the favourites page is using the information in the db.json file rather than the API.&lt;/p&gt;

&lt;p&gt;To work around this I passed each of the rendered values for the pokemon to the json server so that the new modal can use that data to produce the component that looks the same.&lt;/p&gt;

&lt;p&gt;In the next post I'll go over the favourites modal and how that works.&lt;/p&gt;


&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Planning the react pokedex</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Fri, 17 Nov 2023 02:52:16 +0000</pubDate>
      <link>https://dev.to/danarkey/planning-the-react-pokedex-5321</link>
      <guid>https://dev.to/danarkey/planning-the-react-pokedex-5321</guid>
      <description>&lt;p&gt;Having had no prior react experience this project was proving quite a challenge as I wasn't able to fall back on past knowledge. From such I found this project the hardest as it was learning something completely new and applying that learning.&lt;/p&gt;

&lt;p&gt;Like with all problems though the best way to start is to plan an action of attack.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should it do?
&lt;/h2&gt;

&lt;p&gt;As previously stated I had acquired the json file of all competitive pokemon movesets and wanted users to be able to view them save them for later. &lt;/p&gt;

&lt;p&gt;Spoiler alert we didn't manage to do that as it was taking me far too long to do the basics.&lt;/p&gt;

&lt;p&gt;So the functionality I settled on was that it would be a card like list that featured the full 1010 entries that would load on a 24 card basis.&lt;/p&gt;

&lt;p&gt;If a user clicks on a pokemon a modal will appear with its name, stats and the option to add to favourites. If the pokemon is already in favourites the button will change to remove and users can delete its entry. There will be a favourites page where users can view their favourited pokemon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;With the functionality plan sorted it was time to start. First step creating a new react app in my console and installing the relevant node modules such as router for the navigation. &lt;/p&gt;

&lt;p&gt;Initially I started building everything out in the App.jsx component which I came soon to realise would be a headache to transfer everything.&lt;/p&gt;

&lt;p&gt;I shortly changed to the page approach and had a Pokedex and Favourites page. With the structure sorted it was time to plan the components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;The components I created for this app were the:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Header&lt;/li&gt;
&lt;li&gt;Footer&lt;/li&gt;
&lt;li&gt;Individual pokemon cards&lt;/li&gt;
&lt;li&gt;Load more button&lt;/li&gt;
&lt;li&gt;Pokemon modal&lt;/li&gt;
&lt;li&gt;Modal background overlay&lt;/li&gt;
&lt;li&gt;Favourited pokemon modal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I know looking at the list you can see a double up on the modal and then a modal overlay sitting there as well but how I had set up the initial modal made it &lt;em&gt;much harder&lt;/em&gt; for that functionality to work for the favourited section. &lt;/p&gt;

&lt;h2&gt;
  
  
  Closing remarks
&lt;/h2&gt;

&lt;p&gt;In the next post I'll go over the modals and cards as the header and footer were pretty basic.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The react pokedex project</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Fri, 17 Nov 2023 02:43:18 +0000</pubDate>
      <link>https://dev.to/danarkey/the-react-pokedex-project-1k0j</link>
      <guid>https://dev.to/danarkey/the-react-pokedex-project-1k0j</guid>
      <description>&lt;p&gt;The final project of the front end web dev course with Academy Xi was to create a web app using react. There were a few requirements that also needed to be fulfilled to ensure that the knowledge that we learnt from the course was applied.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a single page application using create-react-app&lt;/li&gt;
&lt;li&gt;Have 5 components to ensure the code is organised&lt;/li&gt;
&lt;li&gt;Use React Router to have at least 3 client-side routes&lt;/li&gt;
&lt;li&gt;Include a nav bar or other UI navigation elements&lt;/li&gt;
&lt;li&gt;Use a json-server to create a RESTful API for the backend&lt;/li&gt;
&lt;li&gt;Add some styling to make it aesthetically pleasing&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Starting off
&lt;/h2&gt;

&lt;p&gt;Having just finished the phase 1 project which was using javascript to connect and fetch data from the pokemon API - I wanted to use that previous knowledge to my advantage.&lt;/p&gt;

&lt;p&gt;I decided to create a new pokedex app but this time using react. During our online sessions we had discussed using hooks to add and remove entries from our db.json file to act as a favourites section.&lt;/p&gt;

&lt;p&gt;My initial plan was to get the external smogon json movesets for each pokemon and apply that to each card for the pokemon. Allowing users to view competitive battle sets and save them for later. However my ambition got the best of me and ended delaying the final product where I had scrapped that functionality entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing remarks
&lt;/h2&gt;

&lt;p&gt;In the next post I'll go through my planning phase and how I set up the app initially and the styling choices I ended up going with.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Bringing it all together - Pokedex Project 5</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Sun, 17 Sep 2023 12:18:20 +0000</pubDate>
      <link>https://dev.to/danarkey/bringing-it-all-together-pokedex-project-5-3g49</link>
      <guid>https://dev.to/danarkey/bringing-it-all-together-pokedex-project-5-3g49</guid>
      <description>&lt;p&gt;Thanks for sticking with this series all the way up to here. The fruits of our labour are done and it's time to showcase the final product. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dXThHxGn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/final-1.JPG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dXThHxGn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/final-1.JPG%3Fraw%3Dtrue" alt="Final image" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SnjQJjUI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/final-2.JPG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SnjQJjUI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/final-2.JPG%3Fraw%3Dtrue" alt="Final image with Tyranitar input" width="798" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see once a user has input a Pokemon into the search field the species, typing and stats update below.&lt;/p&gt;

&lt;p&gt;After the final push into github and making the github pages, the favicon and background image were no longer loading. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MbPlOexi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/Danarkey/phase-1-project/95559bc7f81ebdc1cff5c65df85c105ca15bdf51/blog%2520screenshots/live-test-no-bg.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MbPlOexi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/Danarkey/phase-1-project/95559bc7f81ebdc1cff5c65df85c105ca15bdf51/blog%2520screenshots/live-test-no-bg.JPG" alt="No background image" width="800" height="636"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was an easy fix though as I forgot that github doesn't like it when you start your URLs with a /&lt;/p&gt;

&lt;h2&gt;
  
  
  Future features
&lt;/h2&gt;

&lt;p&gt;In the future I do hope to add in that functionality where you press the speaker button and you can hear the cry of the Pokemon. Unfortunately that isn't apart of the API but I did find an external site that has all of the saved.&lt;/p&gt;

&lt;p&gt;Additionally I would also like to have it so that if you click on the dropdown preview, the input field will auto populate. After hours of trying to get that to work I decided to throw in the towel and focus on finishing the other aspects of the project such as this blog series and the video tutorial on how to use the app. &lt;/p&gt;

&lt;p&gt;If you want to see the app for yourself you can find it &lt;a href="https://danarkey.github.io/phase-1-project/"&gt;here.&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The big part - Pokedex Project 4</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Sun, 17 Sep 2023 11:31:18 +0000</pubDate>
      <link>https://dev.to/danarkey/the-big-part-pokedex-project-4-418a</link>
      <guid>https://dev.to/danarkey/the-big-part-pokedex-project-4-418a</guid>
      <description>&lt;p&gt;Hello and welcome back to the my Pokedex Project blog series. In the last post we explored using Javascript to get a dropdown list option for users when they are searching for a Pokemon. While that was in a different environment, we now need to merge the solutions and make a start on the Pokedex itself.&lt;/p&gt;

&lt;p&gt;At the end of the day if the Single Page Application doesn't look good, what's the point of it. Making things look good especially in a CSS sense is arguably one of the most time consuming parts - for me anyway!&lt;/p&gt;

&lt;h2&gt;
  
  
  Approaching the new problem
&lt;/h2&gt;

&lt;p&gt;If you have read my previous posts you're probably sick of me mentioning my problem solving approach. Luckily for you and me, this first new problem had two paths we could take.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use an image of a Pokedex and have our code input everything over the top of it&lt;/li&gt;
&lt;li&gt;Style it in CSS and make it more responsive&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Maybe if I knew what was involved in creating your own elements in CSS and HTML I would've opted for the easier route but man, this part was difficult.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using an image would've been easier
&lt;/h2&gt;

&lt;p&gt;Now if you're an experienced programmer you'll know what is involved when it comes to creating your own webpage elements such as SVGs. Naive me, did not and was tasked with creating their own functioning Pokedex from scratch for a very important course project. &lt;/p&gt;

&lt;p&gt;Having a reference image did help in the fact that we are essentially reverse engineering something and just need to create elements to match those that already exist. &lt;/p&gt;

&lt;p&gt;For those of you who are unaware what a Pokedex even is, the following image is what I am referring too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hye1pDKN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/pokedex-kanto-1.jpg%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hye1pDKN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/pokedex-kanto-1.jpg%3Fraw%3Dtrue" alt="Kanto Pokedex image" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see there are a lot of small buttons which means creating a lot of elements. Not knowing where to start I had a browse online to see what other people had done as creating a Single Page Application Pokedex is nothing new.&lt;/p&gt;

&lt;p&gt;There are heaps out there, so many talented coders who were able to simply create the entire thing from scratch. Others had opted for the easier route of simply using an image for the background and rendering details over the top of that.&lt;/p&gt;

&lt;p&gt;Looking at what was involved I came to the conclusion that less is probably more in this case as I need something that works without taking me 5 years to finish.&lt;/p&gt;

&lt;p&gt;I decided to strip back on the styling and have two main screens. The left would be where the Pokemon sprite would appear and the right would be where the information appears.&lt;/p&gt;

&lt;p&gt;Stripping back the problem and tackling each part of the Pokedex individually definitely made the task a bit easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;Now the time you have all been waiting for, the CSS code for a Pokedex. How I went about this was to have a background and then render each individual area as a part of the device.&lt;/p&gt;

&lt;p&gt;I utilised the before and after tags to better target each individual element and not break it by trying to do it all in one go.&lt;/p&gt;

&lt;p&gt;For example here is the styling for the light classes:&lt;/p&gt;

&lt;p&gt;.light {&lt;br&gt;
    position: relative;&lt;br&gt;
    height: 1.5rem;&lt;br&gt;
    width: 1.5rem;&lt;br&gt;
    margin-top: 1rem;&lt;br&gt;
    margin-right: 0.5rem;&lt;br&gt;
    border: 1px solid black;&lt;br&gt;
    border-radius: 100%;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light::before {&lt;br&gt;
    content: "";&lt;br&gt;
    position: absolute;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light::after {&lt;br&gt;
    content: "";&lt;br&gt;
    position: absolute;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;I could then go into more detail for each individual light on the device as there were going to be a few:&lt;/p&gt;

&lt;p&gt;.light-red {&lt;br&gt;
    background-color: #ee0707;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light-red::after {&lt;br&gt;
    background-color: #ee0707;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.left-screen-top .light--yellow {&lt;br&gt;
    background-color: #dde214;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.left-screen-top .light--yellow::after {&lt;br&gt;
    background-color: #dde214;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light-green {&lt;br&gt;
    background-color: #91f913;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light-green::after {&lt;br&gt;
    background-color: #91f913;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light-blue {&lt;br&gt;
    background-color: #0ad1ff;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.light-blue::after {&lt;br&gt;
    background-color: #0ad1ff;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;To get the 3D like effect of the device I had seen that someone utilised borders to make a drop-shadow like effect but with the colouring scheme made it look like it was 3D. Once the position of the left bottom part of the screen was aligned that's when we could then give it those borders to give it that effect:&lt;/p&gt;

&lt;p&gt;.left-screen-bottom {&lt;br&gt;
    position: relative;&lt;br&gt;
    height: 78%;&lt;br&gt;
    display: flex; &lt;br&gt;
    flex-direction: column; &lt;br&gt;
    justify-content: space-between; &lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.left-screen-bottom::after {&lt;br&gt;
    content: "";&lt;br&gt;
    position: absolute;&lt;br&gt;
    width: 90%;&lt;br&gt;
    height: 100%;&lt;br&gt;
    border-left: 2px solid #73121e;&lt;br&gt;
    border-bottom: 2px solid #73121e;&lt;br&gt;
    border-bottom-left-radius: 20px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;As you can see the left screen was broken up into top and bottom where the lights would sit in the top and the main screen would sit in the bottom. Getting this blank screen was step one.&lt;/p&gt;

&lt;p&gt;Additional styling then had to be done for the top lights container and the main screen where the sprite would appear. Trying to stick to the original source material as close as possible, I even got the speaker to be on the page.&lt;/p&gt;

&lt;p&gt;.main-screen-speaker {&lt;br&gt;
    margin-left: auto;&lt;br&gt;
    margin-right: 0.5rem;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.main-screen-speaker &amp;gt; * {&lt;br&gt;
    width: 3.8rem;&lt;br&gt;
    height: 0.3rem;&lt;br&gt;
    margin-top: 3px;&lt;br&gt;
    border-radius: 10px;&lt;br&gt;
    background-color: #4d4d4d;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;By declaring this class, any div that would be made would look like an old plastic speaker line.&lt;/p&gt;

&lt;p&gt;I could probably drone on and on about the styling elements but that might take longer than actually doing all of it. &lt;/p&gt;

&lt;p&gt;To be honest using resources online really helped me get through this part as trying to do something like this from scratch as a novice proved very difficult!&lt;/p&gt;

&lt;p&gt;In the next post I'll go over the final result and future features that I would like to implement.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Pokedex Project 3 - getting a dropdown list</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Sun, 17 Sep 2023 11:01:38 +0000</pubDate>
      <link>https://dev.to/danarkey/pokedex-project-3-getting-a-dropdown-list-39p</link>
      <guid>https://dev.to/danarkey/pokedex-project-3-getting-a-dropdown-list-39p</guid>
      <description>&lt;p&gt;Welcome back to the Pokedex project series! In this post we are going to be exploring getting a dropdown list enabled on our SPA.&lt;/p&gt;

&lt;p&gt;The goal is for when users are typing out a Pokemon name into the input field, the entire Pokedex will appear based on the letters they have input thus far. I also was considering having their dex entry and maybe a small sprite appear as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;The first decision I had to make when thinking about the dropdown list was how it should appear on the page and the correct elements I should be using.&lt;/p&gt;

&lt;p&gt;As I previously mentioned I had theorised using the  element to make the list as it would be an easy solution for people to click on and the value would autopopulate into the input field. However it looked terrible and I wasn't able to change the styling due to how the element works within browsers. &lt;/p&gt;

&lt;p&gt;To get around this I decided upon using an unordered list when I would then fetch the Pokemon from the API and have them as list items.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting anew
&lt;/h2&gt;

&lt;p&gt;As to not completely destroy what I had previously created I decided to test this dropdown field on a new set of files starting from scratch.&lt;/p&gt;

&lt;p&gt;I had a brief understanding of how I could get the elements to populate however I came to a crossroads that lead me down a YouTube tutorial rabbit hole to implement this feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  First steps
&lt;/h2&gt;

&lt;p&gt;To get started as I mentioned before I started a with a new set of HTML, CSS and JS files as to not ruin what I had already done. The video tutorial I was watching fetched a list of countries and had the filter feature that I was after with the Pokemon.&lt;/p&gt;

&lt;p&gt;All I had to do was swap out their API for my own right?&lt;/p&gt;

&lt;p&gt;Unfortunately things are never that simple and the solution proved to be a bit more involved. &lt;/p&gt;

&lt;p&gt;So going back to our basics we need to break the problem down into smaller little problems and tackle it one step at a time.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetch the entire Pokedex list&lt;/li&gt;
&lt;li&gt;Load the name of each Pokemon&lt;/li&gt;
&lt;li&gt;Filter the list by the text that a user has input&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Solving the problem
&lt;/h2&gt;

&lt;p&gt;Breaking the problem down into smaller pieces makes things that seem daunting a lot more manageable, especially when you are just a novice in this area.&lt;/p&gt;

&lt;p&gt;We had already tackled fetching the API data once, so yay step one done.&lt;/p&gt;

&lt;p&gt;Eventually I came to a conclusion that suited what I was after.&lt;/p&gt;

&lt;p&gt;const apiUrl = "&lt;a href="https://pokeapi.co/api/v2/pokemon/"&gt;https://pokeapi.co/api/v2/pokemon/&lt;/a&gt;";&lt;/p&gt;

&lt;p&gt;let pokemon = [];&lt;br&gt;
const pokemonListElement = document.querySelector('#pokemon-list');&lt;br&gt;
const pokemonInputElement = document.querySelector('#pokemon-input');&lt;/p&gt;

&lt;p&gt;function fetchPokemon() {&lt;br&gt;
    fetch(apiUrl + &lt;code&gt;?limit=1020&amp;amp;offset=0&lt;/code&gt;)&lt;br&gt;
        .then((response) =&amp;gt; response.json())&lt;br&gt;
        .then((data) =&amp;gt; {&lt;br&gt;
            pokemon = data.results.map((x) =&amp;gt; x.name);&lt;br&gt;
            pokemon.sort();&lt;br&gt;
    });&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function loadData(data, element) {&lt;br&gt;
    if (data) {&lt;br&gt;
        element.innerHTML = "";&lt;br&gt;
        let innerElement = "";&lt;br&gt;
        data.forEach((item) =&amp;gt; {&lt;br&gt;
            innerElement += &lt;code&gt;&lt;br&gt;
            &amp;lt;li&amp;gt;${item}&amp;lt;/li&amp;gt;&lt;/code&gt;;&lt;br&gt;
        });&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    element.innerHTML = innerElement;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;function filterData(data, searchText) {&lt;br&gt;
    return data.filter((x) =&amp;gt; x.toLowerCase().includes(searchText.toLowerCase()));&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;fetchPokemon();&lt;/p&gt;

&lt;p&gt;pokemonInputElement.addEventListener("input", function () {&lt;br&gt;
    const filteredData = filterData(pokemon, pokemonInputElement.value);&lt;br&gt;
    loadData(filteredData, pokemonListElement);&lt;br&gt;
});&lt;/p&gt;

&lt;h3&gt;
  
  
  Breakdown of what is happening
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Declare our API url for ease of use&lt;/li&gt;
&lt;li&gt;Create an empty array to assign values too&lt;/li&gt;
&lt;li&gt;Declare our list and element inputs&lt;/li&gt;
&lt;li&gt;Fetch the entire 1010 Pokedex list&lt;/li&gt;
&lt;li&gt;Load the data from the API where each Pokemon becomes an LI item&lt;/li&gt;
&lt;li&gt;Filter the data from the user's input (have included extra measures to not make it case sensitive)&lt;/li&gt;
&lt;li&gt;Create an event listener that triggers the list to appear once a user has input something&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Styling
&lt;/h2&gt;

&lt;p&gt;Cool now that this input is working we can adjust the styling for it and since it is an unordered list, we can use CSS for this. At the time this is the CSS I had for this test batch:&lt;/p&gt;

&lt;p&gt;.autocomplete-input {&lt;br&gt;
    padding: 25px 15px;&lt;br&gt;
    width: calc(100% - 30px);&lt;br&gt;
    border-radius: 1px;&lt;br&gt;
    border: none;&lt;br&gt;
    outline: none;&lt;br&gt;
    font-weight: bold;&lt;br&gt;
    background-color: #fff;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.autocomplete-list {&lt;br&gt;
    position: absolute;&lt;br&gt;
    top: 70px;&lt;br&gt;
    left: 0;&lt;br&gt;
    list-style-type: none;&lt;br&gt;
    margin: 0;&lt;br&gt;
    padding: 0;&lt;br&gt;
    background-color: #fff;&lt;br&gt;
    width: 100%;&lt;br&gt;
    max-height: 200px;&lt;br&gt;
    overflow-y: auto;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.autocomplete-list li {&lt;br&gt;
    padding: 15px;&lt;br&gt;
    width: calc(100% - 30px);&lt;br&gt;
    font-weight: bold;&lt;br&gt;
    cursor: pointer;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The plan was for it to sit just below the input field and not be too wide as to account for the input field and page length.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing items
&lt;/h2&gt;

&lt;p&gt;Thanks for tuning into part 3! In the next edition I will go over how I implemented this into my current environment and how we went about the styling for the Pokedex itself!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting into the Pokedex code - Project post 2</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Sun, 17 Sep 2023 10:22:03 +0000</pubDate>
      <link>https://dev.to/danarkey/getting-into-the-pokedex-code-3gj5</link>
      <guid>https://dev.to/danarkey/getting-into-the-pokedex-code-3gj5</guid>
      <description>&lt;p&gt;Hi there, welcome back to part two of the Pokedex Project series. So far we had gotten to the pitching part of the project where we talked to our mentor to see if what we have planned was feasible and met the criteria for the project.&lt;/p&gt;

&lt;p&gt;As mentioned previously, I had done some initial coding leading up to the pitch to better visualise in mine and the mentor's head my plan. &lt;/p&gt;

&lt;h2&gt;
  
  
  Baby code
&lt;/h2&gt;

&lt;p&gt;To begin the initial coding I wanted to have that input field that would then update the table below once a Pokemon had been selected. Initial styling wasn't important as I just wanted something on a page.&lt;/p&gt;

&lt;p&gt;Below was the HTML for that first instance:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EVIyobbM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/HTML-initial.JPG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EVIyobbM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/HTML-initial.JPG%3Fraw%3Dtrue" alt="Initial HTML snippet" width="664" height="926"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the JS to work
&lt;/h2&gt;

&lt;p&gt;After the basic setup of the HTML document I needed to get the code to fetch the Pokemon stats from the name of the Pokemon that the user has input. So following our plan and attack methodology we need to break down the problem into each individual section and find a solution one step at a time.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set up a const of when a user inputs a Pokemon&lt;/li&gt;
&lt;li&gt;Fetch the stats from the API for said Pokemon&lt;/li&gt;
&lt;li&gt;Update the table with the stats for each corresponding value&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So from those points our initial JS code was looking a little something like this:&lt;/p&gt;

&lt;p&gt;const apiUrl = "&lt;a href="https://pokeapi.co/api/v2/pokemon/"&gt;https://pokeapi.co/api/v2/pokemon/&lt;/a&gt;";&lt;br&gt;
const updateStats = (selectedPokemon) =&amp;gt; {&lt;br&gt;
  fetch(apiUrl + selectedPokemon)&lt;br&gt;
    .then((response) =&amp;gt; response.json())&lt;br&gt;
    .then((data) =&amp;gt; {&lt;br&gt;
      const stats = data.stats;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  stats.forEach((stat) =&amp;gt; {
    const statName = stat.stat.name;
    const baseStat = stat.base_stat;

    const statValueElement = document.getElementById(`${statName}-value`);
    const statBarElement = document.getElementById(`${statName}-bar`);

    statValueElement.textContent = baseStat;
    statBarElement.style.width = `${calculateBarWidth(baseStat)}%`;
    statBarElement.style.backgroundColor = calculateBarColor(baseStat);
  });
})
.catch((error) =&amp;gt; {
  console.error("Error fetching API data:", error);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;const searchInput = document.getElementById("pokemon-search");&lt;br&gt;
const datalist = document.getElementById("pokemon-options");&lt;/p&gt;

&lt;p&gt;searchInput.addEventListener("input", (event) =&amp;gt; {&lt;br&gt;
  const searchText = event.target.value.toLowerCase();&lt;br&gt;
  datalist.innerHTML = "";&lt;/p&gt;

&lt;p&gt;fetch(apiUrl + &lt;code&gt;?limit=10&amp;amp;offset=0&lt;/code&gt;)&lt;br&gt;
    .then((response) =&amp;gt; response.json())&lt;br&gt;
    .then((data) =&amp;gt; {&lt;br&gt;
      const pokemonList = data.results.map((pokemon) =&amp;gt; pokemon.name);&lt;br&gt;
      const filteredList = pokemonList.filter((pokemon) =&amp;gt; pokemon.includes(searchText));&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  filteredList.forEach((pokemon) =&amp;gt; {
    const option = document.createElement("option");
    option.value = pokemon;
    datalist.appendChild(option);
  });
})
.catch((error) =&amp;gt; {
  console.error("Error fetching API data:", error);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;searchInput.addEventListener("change", (event) =&amp;gt; {&lt;br&gt;
  const selectedPokemon = event.target.value.toLowerCase();&lt;br&gt;
  updateStats(selectedPokemon);&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;At first I was thinking about having a datalist as an option for users to select what Pokemon they want - hence the datalist const but I later scrapped this as you can't style them as they are browser specific.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adjusting the stats table
&lt;/h2&gt;

&lt;p&gt;Okay so we have our JS to allow users to input a Pokemon name and once they do our event listener will change the values of the table.&lt;/p&gt;

&lt;p&gt;I also added an event listener to change any input to all lowercase when searching so that it won't be case sensitive when people are searching. &lt;/p&gt;

&lt;p&gt;The next step was the get this table to update in a manner where the bars would be proportional for their value and I wanted for them to be a different colour ranging from a red to green dependent upon if the value was low to high. &lt;/p&gt;

&lt;p&gt;const calculateBarWidth = (value) =&amp;gt; (value / 255) * 100;&lt;br&gt;
const calculateBarColour = (value) =&amp;gt; {&lt;br&gt;
    console.log("Value:", value);&lt;br&gt;
    if (value &amp;gt;= 120) {&lt;br&gt;
      return "#4eff00"; // Bright Green&lt;br&gt;
    } else if (value &amp;gt;= 100) {&lt;br&gt;
      return "#52ff00"; // Green&lt;br&gt;
    } else if (value === 100) {&lt;br&gt;
      return "#ccff00"; // Yellow&lt;br&gt;
    } else if (value &amp;gt;= 90) {&lt;br&gt;
      return "#ffe400"; // Yellow&lt;br&gt;
    } else if (value &amp;gt;= 80) {&lt;br&gt;
      return "#ffac00"; // Orange&lt;br&gt;
    } else if (value &amp;gt;= 70) {&lt;br&gt;
      return "#ff6600"; // Orange&lt;br&gt;
    } else if (value &amp;gt;= 60) {&lt;br&gt;
      return "#ff4c00"; // Dark Orange&lt;br&gt;
    } else {&lt;br&gt;
      return "#ff0400"; // Red&lt;br&gt;
    }&lt;br&gt;
  }; &lt;/p&gt;

&lt;p&gt;The bar width takes the percentage of the stat where 255 is the max and adjusts the bar to the size based on the percentage.&lt;/p&gt;

&lt;p&gt;Calculating the bar colour involved taking that value and then returning a hex value. I trailed using ranges to assign the colour but that had inconsistent results for me. In the future I could simplify this but I wanted a decent range of colours for the different stat values.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Pokedex project</title>
      <dc:creator>Danarkey</dc:creator>
      <pubDate>Sun, 17 Sep 2023 09:00:03 +0000</pubDate>
      <link>https://dev.to/danarkey/the-pokedex-project-20g2</link>
      <guid>https://dev.to/danarkey/the-pokedex-project-20g2</guid>
      <description>&lt;p&gt;As part of the Front-End web development course with Academy Xi, our phase one project was to create a Single Page Application (SPA). The goal of this project was to bring together our learnings from the course thus far where the front end of the application would be utilising our HTML and CSS skills while we will also be communicating with an API of our choice with Javascript.&lt;/p&gt;

&lt;p&gt;We also had to create a video no longer than 3 minutes how to use the SPA as well as a 5 blog post series that documents how we learnt throughout the Javascript Phase of the course.&lt;/p&gt;

&lt;p&gt;I have decided to use the blog requirement to showcase how I made the Pokedex and my thoughts along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Project requirements&lt;/li&gt;
&lt;li&gt;Planning the features&lt;/li&gt;
&lt;li&gt;Pitching the project&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Project requirements &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Your app must be a HTML/CSS/JS frontend that accesses data from a public API or from a db.json file using json-server. Your API or db.json should return a collection of at least 5 objects with each object having at least 3 attributes. All interactions between the client and the API should be handled asynchronously and use JSON as the communication format. Try to avoid using an API that requires a key. APIs that are free and require no authorization will be easiest to use. &lt;/p&gt;

&lt;p&gt;Your entire app must run on a single page. There should be NO redirects or reloads. In other words, your project will contain a single HTML file.&lt;/p&gt;

&lt;p&gt;Use at least 3 distinct event listenersLinks to an external site. (3 events of different types) that enable interactivity. What this means is that, if you had 3 click events, that would only count as 1 distinct event and you would need to add at least 2 more. Think search or filter functionality, toggling dark/light mode, upvoting posts, etc. Each of your event listeners should also have its own unique callback function. These must be added using JavaScript's .addEventListener() method. Events embedded into HTML elements and CSS will not count toward the total. Please ask your instructor if you have questions regarding this requirement.&lt;/p&gt;

&lt;p&gt;Your project must implement at least one instance of array iteration using available array methods (map, forEach, filter, etc). Manipulating your API data in some way should present an opportunity to implement your array iteration.&lt;/p&gt;

&lt;p&gt;Follow good coding practices. Keep your code DRY (Do not repeat yourself) by utilizing functions to abstract repetitive code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initial thoughts
&lt;/h3&gt;

&lt;p&gt;After reading the project and browsing the the list of no-auth APIs my initial thought was to use the Pokemon API. Already having a decent amount of Pokemon knowledge stored away, I thought this would be an interesting one to work with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Planning the features &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;As with all coding problems the first step after thinking of an idea is to plan out how it should work. Following the steps from our course manual:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plan out your features&lt;/li&gt;
&lt;li&gt;Develop user stories&lt;/li&gt;
&lt;li&gt;“As [ a user ], I want [ to perform this action ] so that [ I can accomplish this goal ].”&lt;/li&gt;
&lt;li&gt;Features should not need you there to explain them to users&lt;/li&gt;
&lt;li&gt;Plan out the structure of your JSON requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wanted users to be able to search for a Pokemon in a pokedex like environment. Once they have selected their Pokemon the Pokedex will update with their name, typing, stats and sprite. &lt;/p&gt;

&lt;p&gt;Most other Pokedex SPAs tend to just have basic information so I wanted to extend that a bit more and display their base stats. Long-long down the road I could see myself adding in cries for the Pokemon when a button is pressed and potentially having optimal movesets and training spreads to appear as well. But first thing first is to get something down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitching the project &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;To avoid what happened to my previous project where I misinterpreted what needed to be done, I wanted to pitch the project to our mentor ASAP. &lt;/p&gt;

&lt;p&gt;I told him the features I had planned for it and he encouraged me to push forward with the concept and even gave me some pointers for how I could potentially style the stats. &lt;/p&gt;

&lt;p&gt;To make the most of the initial pitch, I had put together the basic concept of an input field that once you have typed in a name of the Pokemon, the table below it would update based on their stats. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1gse1qkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/initial-code.JPG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1gse1qkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/initial-code.JPG%3Fraw%3Dtrue" alt="Initial table image" width="308" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NOuoJUu0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/initial-table-ditto.JPG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NOuoJUu0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Danarkey/phase-1-project/blob/main/blog%2520screenshots/initial-table-ditto.JPG%3Fraw%3Dtrue" alt="Initial table with Ditto inputted" width="279" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing out
&lt;/h2&gt;

&lt;p&gt;Thanks for reading part 1 of the creation of the pokedex project. Come back and see the other instalments once everything is complete :) &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
