For this challenge, you will combine your knowledge of HTML, CSS, JavaScript, and React to build a simple weather application.
- Open Weather Map
- React
- Review:
- fetch
- localStorage
Please perform the following steps in your challenges repo (on your personal machine) to update your repo and pull down the latest starter code.
- First, verify you have no uncommitted changes:
git status
- Switch back to your
master
branch:git checkout master
- Pull the latest code into your
master
branch:git pull origin master
- Only if you have not done so on your current computer already, you will need to connect your challenges repo to the main challenges repo. To do so, perform this command (you only need to perform this command once for each computer):
git remote add upstream https://github.com/info343a-au17/challenges.git
- Create a new branch for this challenge:
git checkout -b challenge7
- Now update your repo with the new starter code for this challenge. To do so, perform this command (you will need to perform this command once each week when a new challenge is posted):
git pull upstream master
- If you receive a permissions error, please check your email for an invite to the organization, and accept the invite. If you cannot find the invite, please contact the teaching team immediately.
- If you encounter a merge conflict, you will need to resolve the merge conflict before you can start. Please contact the teaching team if you need help.
- You can now push this new branch to Github:
git push origin challenge7
To obtain an API key for Open Weather Map, perform the following steps:
- Go to https://openweathermap.org/
- Click Sign Up.
- You will be presented with a modal to provide your company name and purpose. You can put "University of Washington" and select the Education option.
- To generate an API key, go to the API Keys tab.
- You will need to include this API key with each request you make to their API.
- Documentation on the current weather API can be found at http://openweathermap.org/current
- Update your repo with the new starter code (see above).
- Change directories into your
challenge7
folder:cd challenge7
- Install the project dependencies by running:
npm install
- Obtain an API key from Open Weather Map (see above).
- In your
challenge7
folder, open thepackage.json
file. In order to be able to properly publish to Github Pages, you must update thehomepage
url to use yourchallenges-
repo name instead ofchallenges-jasonnutter
. So if your challenges repo is namedchallenges-uwnetid
, thehomepage
property should be updated to"homepage": "https://info343a-au17.github.io/challenges-uwnetid/challenge7"
- To run your app locally,
cd challenges7
and runnpm start
- To run lint, run
npm run lint
- To publish your app to Github Pages, run
npm run deploy
(you need to do this every time you want to update your app on Github Pages). You do not need to manually merge yourchallenge7
branch intogh-pages
, asnpm run deploy
will do that for you.
build
: Folder contains files generated from runningnpm run build
. You should not edit any files in this folder.node_modules
: Folder contains project dependencies downloaded from runningnpm install
. You should not edit any files in this folder.public
: Folder contains static files that you want to use outside the module system.src
: Folder contains JavaScript modules, React Components, and CSS files for your app..eslintc.json
: Configuration file foreslint
. You should not edit this file..npmrc
: Configuration file fornpm
. You should not edit this file.package-lock.json
: Lock file fornpm
. You should not manually edit this file (npm
will automatically edit this file).package.json
: Manifest file fornpm
. Contains list of dependencies and scripts to use withnpm run
. If you addnpm
modules to your project usingnpm install
,npm
will automatically edit this file.
For this assignment, the overall look and feel of your application is up to you, however, the functionality must satisfy the following requirements:
A. Look / Feel
- Your application must work correctly on both small and large screens (from 320px to 1200px, at least).
- It should be styled with more than just the default browser styling. It is recommended to use a CSS Framework such as Bootstrap, Material Design Lite, or Foundation.
- Regardless of which CSS Framework you use, your app must have a consistent and appealing look and feel.
B. Hosting
- Any data from for your app must be stored in the browser's localStorage.
- Your page should be hosted on Github Pages. Important: To automatically deploy your app to Github Pages, run
npm run deploy
. You must also update thehomepage
property inside of thepackage.json
file to bechallenges-{your github user name}
instead ofchallenges-jasonnutter
.
C. Pages
- There must be a React component named
App
where users can view the weather information. It should be rendered into thediv
with an id ofroot
.
D. Weather Page
- The page must display the name of your weather app at the top of the page and in the title of the browser tab.
- There must be an input box where a user can search for a location by postal code or city name.
- When the user submits a location search, your app must retrieve the current weather about that location from the openweathermap.org API.
- If the user provides a location that doesn't exist, or the openweathermap.org API returns any other error when searching for the city, you must show an error to the user (e.g. "Invalid location").
- The page must show at least the following information about the weather:
- The name of the location (e.g. if the user enters "98115", it must show "Seattle").
- The "short" and "long" description of the current weather. (e.g. "Clouds" and "scattered clouds")
- An icon for the current conditions.
- The temperature in Fahrenheit (with no decimal places).
- A button to Save that location to their saved locations.
- When the user clicks the button Save the current location, the query the user provided for that location must be saved in a list of locations, and that list of locations must be visible to the user on the page.
- The current list of saved locations must be saved to the browser's local storage.
- When the user clicks a previously saved location, the page must show the current weather for that location.
- The user must have the ability to remove a location from the saved locations list.
- If the user refreshes their page (or closes their browser and reopens your app), the page must show the previously saved locations.
- Users should not be able to save queries that are invalid (i.e. an error was returned when searching for the location).
- When the page first loads, if the user has any saved locations, the page should show the weather for the first location in the list.
E. Technical Requirements
- All HTML elements in your app must be written in React. You may not add additional HTML elements to
index.html
directly (other thanscript
,link
, or othermeta
tags). - You cannot use any other JS libraries such as jQuery for DOM manipulation or traversal. You may use the jQuery AJAX API instead of
fetch
orXMLHttpRequest
. - You must create separate React components for each main piece of UI (e.g.
WeatherSearch
,WeatherCurrent
,WeatherSaved
, etc). - Each React component must be written in its own file (1 component per file).
- Your solution must not contain any errors reported by running
npm run lint
. Warnings are okay, however, it is recommended to fix all warnings as well.
Below are screenshots of a sample solution that satisfies all of the functional requirements above. You can use this as a starting point, but I recommend trying to make something that looks even better.
Initial Page Load (no saved locations)
Search Error
Weather for Seattle
Seattle saved to My Locations
New York saved to My Locations
98115 saved to My Locations
Mobile view
All code for this challenge must be committed to the challenge7 branch in your repo. Push this branch to Github, open a pull request to your master branch (do not merge it yourself), and then submit the URL to your pull request on Canvas. In the description of your pull request, please include a link to your app on Github Pages, and please list any extra credit options you completed.
- Firebase (5 points): Instead of using
localStorage
, store the saved locations on Firebase, using either anonymous authentication or traditional email/password accounts. If you provide functionality for a user to sign up/sign in, that UI must also be written exclusively in React (it can be on a new html page, which redirects the user to the weather page). - Styling (5 points max): Style your app with more than just the default styling for your CSS framework.
- Additional Data (5 points max): In addition to the basic weather data, using the OWM API to display more information about the current weather in an informative, useful, and pleasing way.
- User preferences (5 points): Provide controls for the user to change their preferences (e.g. changing from temperature imperial units to metric units). These preferences must also persist between sessions.
- Current location (5 points): When the page first loads, show the weather data for the user's current location. Alternatively, provide a button the user can click to load the weather data for their current location.