Coder Social home page Coder Social logo

react-omdb's Introduction

React OMDB

See Headers Below For Step By Step Outline

Note: each step has a corresponding commit with the implemented actions on the solution branch of this repo.

Step 0: Examine the Solution

Fork and clone the app locally.

Check out to the solution branch and spend time playing around with the completed exercise. Think about how you would separate your different components and functionality.

git checkout solution
npm install
npm start

Step 1: Set up a HelloWorld Component

Before we start building our React app, let's create a HelloWorld component just to make sure that we've tied everything together properly.

  • npm install the dependencies you'll need
  • In your /src directory, configure your App.js and index.js files to render a HelloWorld component
  • Run npm start and make sure everything is working

Step 2: Add UI for Home

  • Rename App.js to Home.js to better indicate the purpose of the file. Make sure to update references to this file elsewhere in your application accordingly.
  • Create a Home component that returns a container <div> element, which should in turn contain a <h1> element.
  • Render that component to the DOM in your app's main index.js file

Step 3: Add UI for Search

  • Create a new file for your Search component.
  • Define a Search component that renders a search form. This can be a simple form with a single input and submit button.
  • Import the Search file to your Home file.
  • Render the Search component in the Home component.

Step 4: Wire up the Search Button

  • Define your Search component's initial state. It should have a query value that corresponds to a search term.
  • Define a function that is triggered whenever the user submits the Search form. Start by just logging "searched!" to make sure it works.
    • Use an event listener to attach this function to your form. Try googling onSubmit.
  • Define a function that updates your query value in state whenever a change is made to the input field. Try googling onChange.
  • Update your submit function so that it now logs the query value in state.

Step 5: Move search logic to a SearchContainer component

  • Create a new SearchContainer component that that renders the Search component. This SearchContainer will also handle search results.
  • Refactor your Search component so that it only renders a UI. It should use properties passed into the Search component.
  • Move all of the business logic related to state for the search into the SearchContainer component. The SearchContainer component should still render the Search component, with any necessary properties.

Step 6: When a User Searches...

  • Define a Results component that will take in a collection of movie gif objects and render each one's movie's title and poster source url as well as a fixed height image. Go ahead an look at the OMDB API documentation Giphy documentation to see the structure of the data it will return.
  • Update your SearchContainer component's states to include whether the user has submitted a search.
  • Update SearchContainer's state to include a list of results, as well.
  • If a user has searched, instead of rendering the Search component, render a Results component with hard coded data.
  • This is starting to look like a single page app, but we don't have routing yet. Update the component so that the search bar and any results are always displayed on the page, and clear out old results when a new search is submitted.
click for simplified hard-coded data you dould use ```js { "data": [ { "type": "gif", "id": "iuHaJ0D7macZq", "url": "http://giphy.com/gifs/cat-day-tomorrow-iuHaJ0D7macZq", "source": "https://www.reddit.com/r/CatGifs/comments/5f0h9a/tomorrow_is_legs_day/", "rating": "pg", "images": { "fixed_height": { "url": "http://media4.giphy.com/media/iuHaJ0D7macZq/200.gif" } } }, { "type": "gif", "id": "Z1kpfgtHmpWHS", "url": "http://giphy.com/gifs/cat-way-make-Z1kpfgtHmpWHS", "source": "http://shewhoseeks.blogspot.com/2016/03/cat-gifs-that-make-me-laugh-way-more.html", "rating": "g", "images": { "fixed_height": { "url": "http://media4.giphy.com/media/Z1kpfgtHmpWHS/200.gif" } } } ], "meta": { "status": 200, "msg": "OK" }, "pagination": { "total_count": 1947, "count": 25, "offset": 0 } } ```

Bonus

Step 7: Search the Omdb Giphy API

  • With the API we're using, you don't need to register for an API key. Go ahead an look at the OMDB API documentation documentation to determine the API's proper usage.
  • We're going to be searching the movie giphy API based on title a word or phrase to return a collection of results.
  • Load in jQuery, and use it to make an AJAX HTTP request to the API search endpoint using the user's query.
  • Pass the movie data to the Results component to be displayed.

Step 8: Add Styles to your React app

  • Load in Bootstrap CDN in index.html.
  • Modify UI to include Bootstrap classes.
  • Create a styles directory and make a file for your CSS rule definitions - this will be written in Javascript!.
  • Load in that file in any component and then use that to apply inline styling.

Step 9: Add a single Result detail Component

  • Create a Result or Details component that renders information about a movie gif.
  • When a user clicks on a movie gif in the results view, render the movie detail UI.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.