Git Product home page Git Product logo

fend19-js4-gitjobs's Introduction

FEND19 - JavaScript 4 - GitHub Job Listing

preview

Description

In this task I created a React app that lets the user search for jobs by description. The project is hosted on Firebase and can be visited at this link: https://dmitrijv-att1.web.app/

Search results from the API are saved in context and any future search will check if the value the user is searching for is already in context, if so, it is returned from context instead of a new network request. After a network request has been initated the search button becomes disabled to prevent spamming search against a slow API.

async function getJobsByDescription(keyword) {
  if (searchCache[keyword]) {
    console.log(`getting cached results for "${keyword}"`);
    setResultList(searchCache[keyword]);
  } else {
    console.log(`making network request for "${keyword}"`);
    setResultList(null);
    setSearchInProgress(true);
    const url = `https://us-central1-wands-2017.cloudfunctions.net/githubjobs?description=${keyword}`;
    fetch(url)
      .then((res) => res.json())
      .then((data) => {
        setResultList(data);
        searchCache[keyword] = data;
        setSearchCache(searchCache);
        setSearchInProgress(false);
      });
  }
}

Clicking a job item on the result list will take you to a job details page. A job item is formatted as follows:

<div className="job-container">
  {jobItem && (
    <div>
      <h2>{jobItem.title}</h2>
      <p>
        <strong>{jobItem.type}</strong>
      </p>
      <Image imgUrl={jobItem.company_logo} />
      <a href={jobItem.url}>company url</a>
      <div dangerouslySetInnerHTML={createDescriptionMarkup()} />
    </div>
  )}
  <Link className="App-link" to={"/search"}>
    <p>Back to search</p>
  </Link>
</div>

If a user searches for "react javascript", the string is changed to "react+javascript" since the GitHub API expects spaces to be replaced with plus signs.

async function handleJobSearch(event) {
  event.preventDefault();
  if (searchKeyword.length === 0) return;
  const keyword = searchKeyword.replace(" ", "+");
  await getJobsByDescription(keyword);
}

Tests

There is a total of 10 tests to make sure that all of the components in the project are working as expected. General app test are located in App.test.js file. Tests for specific components are located in the test folder.

You can run these tests by running the following commands:

npm test App.test.js
npm test src/components/__test__/JobList.test.js
npm test src/components/__test__/JobItem.test.js
npm test src/components/__test__/Image.test.js

fend19-js4-gitjobs's People

Contributors

dmitrijv avatar

Watchers

James Cloos avatar  avatar

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.