<?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: Joseph Martin</title>
    <description>The latest articles on DEV Community by Joseph Martin (@joe1350).</description>
    <link>https://dev.to/joe1350</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%2F778559%2Fda568315-336d-4123-9450-5bba0bf12862.png</url>
      <title>DEV Community: Joseph Martin</title>
      <link>https://dev.to/joe1350</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joe1350"/>
    <language>en</language>
    <item>
      <title>Authentication</title>
      <dc:creator>Joseph Martin</dc:creator>
      <pubDate>Fri, 24 Feb 2023 02:06:28 +0000</pubDate>
      <link>https://dev.to/joe1350/authentication-3p6o</link>
      <guid>https://dev.to/joe1350/authentication-3p6o</guid>
      <description>&lt;p&gt;While learning about user authentication in web development, I had some difficulty grasping all of the concepts, so I did a little research and I am writing about what I learned. Authentication, in the sense of web development, is the process of making sure our user is who they say they are before they are allowed to access the content.&lt;/p&gt;

&lt;p&gt;So, if I'm building a website with users, and I want my users information to be secure, there' a few things I have to know. First, HTTP is a stateless protocol. It does not store the user data for me. Cookies allow additional information to be sent along with the request to the server. Cookies are usually used to save session info. Without them, a user would have to log in and be authenticated for every request. The session is a special cookie that Rails encrypts and signs. Rails manages all of the session data in a single cookie, serializing all of the key-value pairs into a single string. Whenever a key is set Rails updates the value of the session cookie to this big string. When cookies are set like this Rails signs them to prevent users from tampering with them. The Rails server has a key, configured in &lt;code&gt;config/credentials.yml.enc&lt;/code&gt;. Rails has a method that returns a signature. The signature is an encrypted string. Given the same message and key, it will produce the same string. Also, without the key, it is practically impossible to know what would be returned for a given message. Meaning, signatures can't be forged. When a cookie is received, Rails will verify that the signatures match. Once the username and password have been authenticated, you receive a cookie. With it, you do not need to provide your username and password for every request. When a user logs in a cookie is set on the user's browser. That cookie writes their user id into the session's hash. &lt;/p&gt;

&lt;p&gt;The password should never be stored in the database as plain text. Instead, it should be stored as a hashed version, an encrypted string. There are many kinds of hashes, but they need to be complex enough to not be easily decrypted. Another common issue with hashes is that similar passwords can generate hashes with similar values. Sometimes these values "collide" with each other. One library that makes hashes is BCrypt. BCrypt is designed so that similar strings come out to be very different values, it is a cryptographic hash and is designed to be slow. it is intentionally computationally expensive. A salt is a random string prepended to the password before hashing it. It's stored in plain text next to the password, so it's not a secret. Rails makes this easier for us. There is a macro called &lt;code&gt;has_secure_password&lt;/code&gt;. It is placed in the user model, and it gives access to methods used to authenticate the user. The macro grants access to two instance methods on the &lt;code&gt;user&lt;/code&gt; model. These two methods enable &lt;code&gt;password&lt;/code&gt; and &lt;code&gt;password_confirmation&lt;/code&gt; to easily be added to a signup form. &lt;code&gt;has_secure_password&lt;/code&gt; has a hook that checks if the password and password confirmation match unless the password confirmation is nil. If they match or the value is nil then the user is saved and the hashed version of the password is stored in the &lt;code&gt;password_digest&lt;/code&gt;. It stores two values, the salt and the return value of BCrypt. &lt;code&gt;User.authenticate&lt;/code&gt; is another method &lt;code&gt;has_secure_password&lt;/code&gt; allows me to use. It takes the password the user inputs, puts it through the same encryption process, then checks that it matches the password_digest in the database.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>discuss</category>
      <category>career</category>
    </item>
    <item>
      <title>useContext in React</title>
      <dc:creator>Joseph Martin</dc:creator>
      <pubDate>Mon, 20 Feb 2023 23:22:43 +0000</pubDate>
      <link>https://dev.to/joe1350/usecontext-in-react-2p3n</link>
      <guid>https://dev.to/joe1350/usecontext-in-react-2p3n</guid>
      <description>&lt;p&gt;I have just finished working on another project, and one of the project requirements was to persist the user's state in the front &lt;br&gt;
end with &lt;code&gt;useContext&lt;/code&gt;. So, I had to relearn how to use &lt;code&gt;useContext&lt;/code&gt;. I wanted to share some of the things I learned.&lt;/p&gt;

&lt;p&gt;Typically our state is stored in a component where all the components that need access to it can easily get access to it. In this project, since most of my components needed access to the user, I made a &lt;code&gt;userContext&lt;/code&gt;. To start, you need a file to store your context in. I created a &lt;code&gt;context&lt;/code&gt; folder in my &lt;code&gt;src&lt;/code&gt; folder, and a &lt;code&gt;user.js&lt;/code&gt; file in the &lt;code&gt;context&lt;/code&gt; folder. Then, create the context and the context provider.&lt;br&gt;
Create the context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserContext = React.createContext();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a provider component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function UserProvider({ children }) {
  return &amp;lt;UserContext.Provider value={{ user, setUser }}&amp;gt;{children}&amp;lt;/UserContext.Provider&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value is the context that I am passing, and it will be available to the children of the provider. Now that it's created it needs to be passed in to the application. To do this, I import the &lt;code&gt;UserProvider&lt;/code&gt;into the app and wrap the components in &lt;code&gt;UserProvider&lt;/code&gt;. I also no longer need to pass the &lt;code&gt;user&lt;/code&gt; and &lt;code&gt;setUser&lt;/code&gt; props into the component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
import { UserProvider } from "../context/user";

function App() {
  return(
    &amp;lt;UserProvider&amp;gt;
      &amp;lt;AComponent /&amp;gt;
    &amp;lt;/UserProvider&amp;gt;
  )
}
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, I need to add the context to the component I'm going to use it in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useContext } from "react";
import { UserContext } from "../context/user";

function AComponent() {
  const { user, setUser } = useContext(UserContext);

  {now you have access to your context values here}

  return (
    {and here too}
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, that is how you use context to store state globally. One thing that gave me a lot of trouble was, when I was initializing my user state I initialized it with an empty array rather than null. While I probaly could have rewritten the code to make the first way work, it was giving me a lot of trouble, and changing it to null really helped me out.&lt;br&gt;
Not like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [user, setUser] = useState([])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [user, set user] = useState(null)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>redis</category>
      <category>systemdesign</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
    <item>
      <title>Calorie Tracker</title>
      <dc:creator>Joseph Martin</dc:creator>
      <pubDate>Thu, 17 Nov 2022 23:32:23 +0000</pubDate>
      <link>https://dev.to/joe1350/calorie-tracker-3edd</link>
      <guid>https://dev.to/joe1350/calorie-tracker-3edd</guid>
      <description>&lt;p&gt;For my phase 3 project I decided to make a calorie tracker. I had a lot of fun working on this project. In this project I have two models, &lt;code&gt;Day&lt;/code&gt; and &lt;code&gt;Food&lt;/code&gt;. There are many foods belonging to one day. For the backend, one thing I enjoyed working on was setting up the routes to view the various endpoints for my databases. For viewing the full database I kept my endpoint simple: &lt;code&gt;/days&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;get "/days" do
  days = Day.all
  days.to_json(include: :foods)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this code block is doing is grabbing all instances of the Day class and converting it to JSON. Then, it is nesting each food instance with it's associated Day.&lt;/p&gt;

&lt;p&gt;For my POST routes, I have an endpoint to create a new day and another one to create a new food through the day by id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;post '/days' do
  day = Day.create(
    date: params[:date],
    foods: params[:foods],
  )
  day.to_json(include: :foods)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is creating a Day instance and gives it a date that the user enters in the frontend, and an empty foods array for the value of foods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;post '/day/:id/foods' do
  day = Day.find(params[:id])
  food = day.foods.create!(
    name: params[:name],
    calories: params[:calories],
    fat: params[:fat],
    fiber: params[:fiber],
    day_id: params[:day_id],
  )
  {}.to_json(include: :foods)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is finding a day instance in the class Day. Then, it is creating a food instance in that day.&lt;/p&gt;

&lt;p&gt;I have a PATCH route for both models. They are very similar so I will only talk about the route to patch foods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;patch '/foods/:id' do
  food = Food.find(params[:id])
  food.update(
    name: params[:name],
    calories: params[:calories],
    fat: params[:fat],
    fiber: params[:fiber],
    day_id: params[:day_id],
  )
  food.to_json
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is finding an instance of a food by id. And then, it is updating the instance with information provided by the frontend.&lt;/p&gt;

&lt;p&gt;Similar to my PATCH routes, my DELETE routes are exactly the same just with differnt values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;delete '/days/:id' do
  day = Day.find(params[:id])
  day.destroy
  day.to_json
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This finds a day instance by id. Then it destroys it. In the Day model there is a &lt;code&gt;dependent: :destroy&lt;/code&gt; so that when a day is deleted all of the foods associated with that day are deleted as well. I've been told the last line of the code block is unnecessary, but every time I delete it my delete button stops working in the front end.&lt;/p&gt;

&lt;p&gt;I also wrote some routes that I am not using in this project, but I have seen similar functionality in APIs that I have used. So, I wanted to create some extra endpoints. I have a route to get all days without their associated foods; I have a route to get all foods without their day, and I have a route to get one day by id and another one to get one food by id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/days" do
  days = Day.all
  days.to_json
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns all days&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/foods" do
  foods = Food.all
  foods.to_json
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns all foods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/days/:id" do
  day = Day.find(params[:id])
  day.to_json
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns one day by id. The id is provided from the front end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/foods/:id" do
  food = Food.find(params[:id])
  food.to_json
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns one food by id. The id is provided from the front end.&lt;/p&gt;

&lt;p&gt;I also created a route to get the last seven days with their nested foods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/days_last_seven" do
  week = Day.last(7)
  week.to_json(include: :foods)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I really enjoyed this project and thinking about all of the different routes I may want to access to interact with the front end application.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My Cook Book</title>
      <dc:creator>Joseph Martin</dc:creator>
      <pubDate>Tue, 08 Feb 2022 23:15:45 +0000</pubDate>
      <link>https://dev.to/joe1350/my-cook-book-26h3</link>
      <guid>https://dev.to/joe1350/my-cook-book-26h3</guid>
      <description>&lt;p&gt;For my phase 2 project with Flatiron school I decided to make a cook book to store some of my favorite recipes, and some new ones that I would like to try. This web application was written with React, and this is my first React project. I had a lot of fun working on this project. The major features of this project are the list of recipes that can be filtered in to category's,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q8oAPhTa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4dks5q9rjrf4zuc70ds.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q8oAPhTa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4dks5q9rjrf4zuc70ds.jpg" alt="list of recipes" width="880" height="490"&gt;&lt;/a&gt;&lt;br&gt;
and a form to add new recipes to the database.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EjbVn1fq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tydhux43k0ofkcfirte.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EjbVn1fq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tydhux43k0ofkcfirte.jpg" alt="new recipe form" width="880" height="495"&gt;&lt;/a&gt;&lt;br&gt;
On the list of recipes you can click on one to see the full recipe.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gge1_6Ct--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00gg7rm9usthplta1dxw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gge1_6Ct--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00gg7rm9usthplta1dxw.jpg" alt="full recipe" width="880" height="901"&gt;&lt;/a&gt;&lt;br&gt;
One piece of code that was both challenging, and a lot of fun to work on was the filter. First I had to create a dropdown to select a category.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="category-filter"&amp;gt;
  &amp;lt;label htmlFor="category"&amp;gt;Filter By: &amp;lt;/label&amp;gt;
  &amp;lt;select name="category"&amp;gt;
    &amp;lt;option value="all"&amp;gt;Choose a Category...&amp;lt;/option&amp;gt;
    &amp;lt;option value="appetizers"&amp;gt;Appetizers&amp;lt;/option&amp;gt;
    &amp;lt;option value="beverages"&amp;gt;Beverages&amp;lt;/option&amp;gt;
    &amp;lt;option value="breakfast"&amp;gt;Breakfast&amp;lt;/option&amp;gt;
    &amp;lt;option value="desserts"&amp;gt;Desserts&amp;lt;/option&amp;gt;
    &amp;lt;option value="main dishes"&amp;gt;Main Dishes&amp;lt;/option&amp;gt;
    &amp;lt;option value="salads"&amp;gt;Salads&amp;lt;/option&amp;gt;
    &amp;lt;option value="side dishes"&amp;gt;Side Dishes&amp;lt;/option&amp;gt;
    &amp;lt;option value="soups and stews"&amp;gt;Soups and Stews&amp;lt;/option&amp;gt;
  &amp;lt;/select&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After That I had to control the form in state so I could access the value later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// the recipes prop is a list of recipes from an api
function RecipePage({ recipes }) {

  {/* here I set the initial state */}
  const [filterBy, setFilterBy] = useState("all")

  &amp;lt;div&amp;gt;
    &amp;lt;label htmlFor="category"&amp;gt;Filter By: &amp;lt;/label&amp;gt;

    {/* now I can set the value and onChange */}
    &amp;lt;select
      name="category"
      value={filterBy}
      onChange={e =&amp;gt; setFilterBy(e.target.value)}
    &amp;gt;
      {/* ...
      options
      ... */}
    &amp;lt;/select&amp;gt;
    {/* pass recipes and filterBy in to RecipeList */}
    &amp;lt;RecipeList recipes={recipes} filterBy={filterBy} /&amp;gt;
  &amp;lt;/div&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that I have the value of the dropdown stored in state as &lt;code&gt;filterby&lt;/code&gt;, I can pass that value in to &lt;code&gt;RecipeList&lt;/code&gt;. In &lt;code&gt;RecipeList&lt;/code&gt; we receive two props, recipes, the list of recipes, and &lt;code&gt;filterBy&lt;/code&gt;, the selected category on the dropdown. For recipes, I don't want to alter it (I'll need the original list later) so I create a new variable in state, &lt;code&gt;filteredRecipes&lt;/code&gt;. Next, I filter through the list of recipes and find all of the recipes that match the currently selected category. Then, I save those recipes to &lt;code&gt;filteredRecipes&lt;/code&gt; so I can re-render the list with just the selected recipes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function RecipeList({ recipes, filterBy }) {
  // set new state variable
  const [filteredRecipes, setFilteredRecipes] = useState([])

  //This is a side effect that runs everytime filterBy changes
  useEffect(() =&amp;gt; {
    if (filterBy === "all") {
      setFilteredRecipes(recipes)
    } else {

      // first, I create a new array
      let newFilteredRecipes = []

      // next I filter through the list
      recipes.filter(recipe =&amp;gt; {

        // if the category's match, 
        if (recipe.category === filterBy) {

          // add the recipe to the array
          newFilteredRecipes.push(recipe)
        }
      })
      // set the new filtered list to filteredRecipes
      setFilteredRecipes(newFilteredRecipes)
    }
  }, [filterBy])

  // now the JSX has filtered recipes to work with
  return (
    &amp;lt;div&amp;gt;
      {filteredRecipes.length !== 0 &amp;amp;&amp;amp;
        filteredRecipes.map(recipe =&amp;gt; (
          &amp;lt;RecipeListing key={recipe.id} recipe={recipe} /&amp;gt;
        ))
      }
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, I created a dropdown, and I controlled the dropdown in state. Then, I compared each recipes category to the value in state. Lastly, I stored the new list of filtered recipes in it's own state variable as to not alter the original list and to re-render the filtered list.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Doctor Who Database</title>
      <dc:creator>Joseph Martin</dc:creator>
      <pubDate>Wed, 22 Dec 2021 02:10:53 +0000</pubDate>
      <link>https://dev.to/joe1350/doctor-who-database-4li2</link>
      <guid>https://dev.to/joe1350/doctor-who-database-4li2</guid>
      <description>&lt;p&gt;My phase 1 project is a visual database of Doctor Who episodes. To view my website &lt;a href="https://joe1350.github.io/phase-1-project/" rel="noopener noreferrer"&gt;click here&lt;/a&gt;. Information about episodes can be retrieved by season, Doctor, director, or writer This could be considered a companion app to the Doctor Who Series. While working on this project I had to come up with some creative solutions to a couple challenges I was facing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftitzceh68m5rkp9ulk8e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftitzceh68m5rkp9ulk8e.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The first challenge was to prevent having to scroll to see information. For example, when you first click on a category; season, Doctor, director, or writer(in the example above we are looking at seasons); it fetches the endpoint for that category, and renders all items for that category(all of the seasons for this example) to the page. Since there's over 39 seasons the list can be long. When you click on a season you see all the episodes for that season. Now, lets say you want to see the episodes for the very last season. You click on that season, and nothing happens... That's because you have to scroll all the way back up to the top to see that information. So, I wanted to make the information display on screen no matter where I was on the page. I fixed this in CSS by setting &lt;code&gt;position: fixed;&lt;/code&gt; on the container that holds the list of episodes. Now, this made the information stay fixed in place on the screen, but it was overlapping with the list of seasons. To fix this I moved the container. The final CSS looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#episodes-container {
    position: fixed;
    top: 260px;
    left: 25%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;top: 260px;&lt;/code&gt; made the container display 10 pixels beneath my 250 pixel header, and the &lt;code&gt;left: 25%;&lt;/code&gt; made the container display 25% of the way across from the left side of the window.&lt;/p&gt;

&lt;p&gt;The second challenge was more difficult to solve. The structure of the API  did not easily allow episode details to be displayed. Each category has it's own endpoint within the API that I used, &lt;a href="https://api.catalogopolis.xyz/docs/restapi/index.html" rel="noopener noreferrer"&gt;catalogopolis&lt;/a&gt;. While the endpoint had a way to see what episodes pertained to each item in the category, it did not show the episode details. To see the episode details you had to find it within the episodes endpoint. The two endpoints did not share any data except the episode name. So, I had to come up with a way to take the episode name, fetch the episodes endpoint, and find where the episode names matched. I'm going to break the code down for you. First I saved my endpoint to a variable: &lt;code&gt;const allEpisodesURL = 'https://api.catalogopolis.xyz/v1/episodes'&lt;/code&gt; from there I ran a fetch on the endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchAllEpisodes(episodeName) {
    fetch(allEpisodesURL)
    .then(r =&amp;gt; r.json())
    .then(episodes =&amp;gt; findEpisode(episodes, episodeName))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in &lt;code&gt;fetchAllEpisodes&lt;/code&gt; I passed in the &lt;code&gt;episodeName&lt;/code&gt; so it would be available to pass on to &lt;code&gt;findEpisode&lt;/code&gt;. In &lt;code&gt;findEpisode&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;function findEpisode(episodes, episodeName) {
    for (let episode of episodes) {
        if(episode.title === episodeName) {
            renderEpisodeDetails(episode)
            break;
        } else {
            renderNoEpisodeDetails(episodeName)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am iterating through the array of episodes. I am looking at each episode and checking if the &lt;code&gt;episodeName&lt;/code&gt; strictly equals the &lt;code&gt;episode.title&lt;/code&gt;. If we find the matching episode we pass it to &lt;code&gt;renderEpisodeDetails&lt;/code&gt;. If we don't find the matching episode we pass it to &lt;code&gt;renderNoEpisodeDetails&lt;/code&gt;. In render episode details,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function renderEpisodeDetails(episode) {
    episodeDetailsContainer.innerText = ''
    let title = create('p')
    let airDate = create('p')
    let runtime = create('p')
    let viewers = create('p')
    let rating = create('p')
    title.innerText = episode.title
    airDate.innerText = `Aired: ${episode.originalAirDate.slice(5)}-${episode.originalAirDate.slice(0, 4)}`
    runtime.innerText = `Runtime: ${episode.runtime}`
    viewers.innerText = `Viewers: ${episode.ukViewersMM} million `
    rating.innerText = `Rating: ${episode.appreciationIndex} / 100`
    episodeDetailsContainer.append(title, airDate, runtime, viewers, rating)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I create a &lt;code&gt;p&lt;/code&gt; tag for each detail, fill in the &lt;code&gt;innerText&lt;/code&gt; of each detail with data returned from the API, and append it all to the container that holds the episode details. A quick side note, &lt;code&gt;create&lt;/code&gt; is a helper function I added to the top of my file,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const create = el =&amp;gt; document.createElement(el)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, if we back up a little, if no episode details were found in &lt;code&gt;findEpisode&lt;/code&gt; we pass the &lt;code&gt;episodeName&lt;/code&gt; to &lt;code&gt;renderNoEpisodeDetails&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;function renderNoEpisodeDetails(episodeName) {
    episodeDetailsContainer.innerText = `${episodeName} is not in the database`
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in &lt;code&gt;renderNoEpisodeDetails&lt;/code&gt; I am setting the &lt;code&gt;innerText&lt;/code&gt; of the &lt;code&gt;episodeDetailsContainer&lt;/code&gt; to say, &lt;code&gt;episodeName&lt;/code&gt; is not in the database.&lt;/p&gt;

&lt;p&gt;Finding solutions to these two challenges made the project easier to navigate and provided additional information.&lt;/p&gt;

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