Giter Club home page Giter Club logo

react-async-gif-search-lab's Introduction

Giphy Search!

Instructions

You're going to be building out a Gif search using the Giphy API. In this lab, there are no tests to pass. Rather, your task is to create a working app in your browser using the instructions below. When finished, you should have an application that can take in a user's input, fetch JSON data from the Giphy API, and display the results. As there are no tests, to register completion, run learn submit.

giphy search

Getting Started

The URL for the API is

https://api.giphy.com/v1/gifs/search?q=YOUR QUERY HERE&api_key=dc6zaTOxFJmzC&rating=g

While the above API key may work, we recommend creating your own API key by following the instructions on Giphy's developer site. Creating a key is free and only requires an account. Using your own key will prevent any potential rate limiting if other students are also working on this lesson.

Once you've got your key, you should be able to access the Giphy API from a browser and receive a JSON response to confirm everything is working.

https://api.giphy.com/v1/gifs/search?q=dolphin&api_key=YOUR API KEY&rating=g

You should get back an array of objects, each containing information about a particular image.

  "data": [
    {
      "type": "gif",
      "id": "l0HlNQ03J5JxX6lva",
      "slug": "bbc-wildlife-l0HlNQ03J5JxX6lva",
      "url": "https://giphy.com/gifs/bbc-wildlife-l0HlNQ03J5JxX6lva",
      "bitly_gif_url": "https://gph.is/2iC32M8",
      "bitly_url": "https://gph.is/2iC32M8",

      ...

      "images": {
        "fixed_height_still": {
          "url": "https://media0.giphy.com/media/l0HlNQ03J5JxX6lva/200_s.gif?cid=e1bb72ff5b9fa2866168584b51f13892",
          "width": "400",
          "height": "200",
          "size": "55556"
        },
        ...
        "original": {
          "url": "https://media0.giphy.com/media/l0HlNQ03J5JxX6lva/giphy.gif?cid=e1bb72ff5b9fa2866168584b51f13892",
          "width": "480",
          "height": "240",
        }
        ...
      }
    }
    ]

Note: Notice there are many URL keys on each image object. The first url key, just below type, id, and slug, will bring you to the images page on giphy.com. We only want the path to the actual image, which is found at images.original.url. Using other url keys may cause CORS issues.

Your Components

<App/>

Your top level component will be the <App /> component - no surprises there! It will be responsible for rendering the <NavBar /> component (this component is already provided for you, note the project has bootstrap loaded in) and the <GifListContainer /> component.

<GifListContainer />

<GifListContainer /> should be a container that does data fetching and then renders its corresponding sub-component. That’s it.

If you haven't learned about container vs presentation components yet, don't worry. We'll dig deeper into them soon enough. For now, just know that container components contain other components. They themselves usually aren't visible on the page. Presentational components, on the other hand, are components can you can visibly see on the page (like our Navbar).

In our app, the <GifListContainer /> will be responsible for fetching the data from the Giphy API, storing the first 3 gifs from the response in its component state, and passing that data down to its child, the <GifList> component, as a prop.

It will also render a <GifSearch /> component that renders the form. <GifListContainer /> should pass down a submit handler function to <GifSearch /> as a prop.

<GifList />

<GifList /> is a presentational component. It receives data from its props and renders html given the input data. It can render a top level <ul> with each gif as an <li>.

<GifSearch />

The <GifSearch /> component will render a form that receives the user input for the Giphy search. The text input should be a controlled component that stores the value of the input in its component state and renders the DOM accordingly. The React component is always in charge of what the DOM looks like.

<GifSearch /> should receive a callback prop from its parent. On a submit event, it should invoke that callback prop with the value of the text input. It is this callback function, defined in <GifListContainer />, that will actually query the API with the text the user has entered.

When finished, submit your work using learn submit.

Container vs. Presentational Components

Note: You may notice that Dan Abramov, one of the original proponents of using Container components, has added a more recent note recommending against them. It is true that there are newer approaches to writing React apps that reduce the need for having components specialize. However, while we're practicing the basics of React, becoming familiar with how components form a tree and pass data from parent to child is highly valuable. For this reason, we'll keep our components separated here.

react-async-gif-search-lab's People

Contributors

curtisgreene avatar dependabot[bot] avatar dstoll243 avatar gj avatar ihollander avatar ipc103 avatar kreopelle avatar lizbur10 avatar maxwellbenton avatar realandrewcohn avatar rrcobb avatar sdcrouse avatar thuyanduong-flatiron avatar vibraniumforge avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-async-gif-search-lab's Issues

Unable to open lesson

Here's what I get when I click on the "Open IDE" link and it tries to open on IDE:

W
[19:40:20] ~
// ♥ learn open react-async-gif-search-lab-v-000
Looking for lesson...
/usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/lessons/ios_lesson.rb:6:in detect': undefined method any?' for false:FalseClass (NoMethodError)
from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/lessons.rb:20:in block in classify' from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/lessons.rb:19:in each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/lessons.rb:19:in find' from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/lessons.rb:19:in classify'
from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/opener.rb:36:in run' from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/lib/learn_open/opener.rb:11:in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/learn-open-1.2.21/bin/learn-open:7:in <top (required)>' from /usr/local/rvm/gems/ruby-2.3.1/bin/learn-open:23:in load'
from /usr/local/rvm/gems/ruby-2.3.1/bin/learn-open:23:in `

'

Its not it's -- again

Need to remove the apostrophe here:
"It receives data from it's props and renders html given the input data."

Thank you.

Weird CORB issue

There's a tricky bit with the fetch request that tripped a number of people in my cohort up: CORB blocks the url that seems like it would be the right one for loading the GIFs, which is the value of the "url" key in "data"; you have to use images.original.url. A note about that might save some people a lot of unnecessary headaches in the future.

It already done

This Lab is already coded out and working, not sure if it is supposed to be like that or not. there really wasn't anything to do

Bootstrap Not Applying

The top bar and search bar render as plain text with no styling, which the lab expressly states will not happen.

Solution in Master Branch ?

It looks like the latest commit (bbcc70b) may actually include the solution to this lab. When I ran npm start, the app was fully functional, and all components appeared to be built correctly.

Cross-Origin Read Blocking Prevents Gifs From Loading Due To Incorrect Content-Type

The gifs that are returned by the Giphy API for this lab are blocked by CORB. After following the documentation provided in the warning message, it appears that Giphy is providing the wrong Content-Type in its response.

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://giphy.com/gifs/dolphin-cute-ZhEdAJ6aqEjYc with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

The warning states that the MIME type is text/html. In the documentation provided by chromium, it states that rarely CORB will block a response for this reason. The only solution it offers is to notify the site they are providing the wrong Content-Type. Beyond that, completely disabling the security check is likely the only other way to allow these gifs through.

Here is a link to the documentation: https://www.chromium.org/Home/chromium-security/corb-for-developers

In the third paragraph under "What should I do about CORB warnings reported by Chrome?", it addresses this issue.

Article You Recommend Advises AGAINST Containers

Update from 2019: I wrote this article a long time ago and my views have since evolved. In particular, I don’t suggest splitting your components like this anymore. If you find it natural in your codebase, this pattern can be handy. But I’ve seen it enforced without any necessity and with almost dogmatic fervor far too many times. The main reason I found it useful was because it let me separate complex stateful logic from other aspects of the component. Hooks let me do the same thing without an arbitrary division. This text is left intact for historical reasons but don’t take it too seriously.

-- Presentational vs Container Componets: Dan Abramov

Communal API Key Leads To Limit Issues (CORS)

Because the lab instructs students to use the same API key, they can hit limit issues which creates a CORS error. This can be circumvented by having the students get their own API key, but that's a lot of work for one lab. While it's cool to use an external API, we may want to rework this to use a local one just for simplicity's sake.

Text Revisions

  1. Add missing letter "I"
    original:
    following the **[]**nstructions on Giphy's developer site.

  2. Missing period
    original:
    and the component**[]**

  3. Change "container" to "contain"
    original:
    For now, just know that container components [container] other components

Is this the completed lab?

I read through the instructions, but it looks like all of the code complete the requirements has already been written. I had to fix one bug, but otherwise everything worked as described. Perhaps you uploaded the solution instead of the template?

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.