City Weather App

This is a simple Web Application for looking up the weather conditions for various locations around the world and adding them to a favorites list. It's built using React with Typescript.

Features

  • Real-time weather information using the Openweather API.

  • When users first the app asks the user for permission to get their current location and opens the details page for their city after they grant it.

  • Displays a list of the 15 largest cities in the world by population in alphabetical order with the current temperature for each. image

  • Users can remove cities from the list.

  • Clicking on a city opens a page with more weather information and a textarea field for notes.

  • image

    Notes Section

    image

  • Users can search for weather details for other cities.

    image

  • Users can add/remove cities as β€œfavorites”, which appear at the top of the list on the home screen.

    image

  • Basic functionality is retained offline, with the most up-to-date information cached and persisted in local storage.

Installation, Running and Testing

Prerequisites

  1. Openweather API Key
  2. Google Maps API Key
  3. OpenCage Geocoding API Key

Navigate to the project root and replace the values in the .env file with your keys.

Running in Development

  1. Navigate to the root of the project directory and run npm install to install the project dependencies.
  2. Run npm start. Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

Testing

I extended the app's testing to cover the full functionality and layout of the app based on the requirements, using Cypress. There are two modes to run the tests:

Open Mode

This launches the tests in Video mode, to see the UI interactions and console outputs as the tests run. Run npm test to launch this mode and select e2e tests and select your browser(Chrome is preferred) then proceed to the Cypress-controlled Browser environment. Select any of the spec files to run tests for that spec file.

image

Run Mode

This launches the tests in run mode in your console, and outputs the results of each spec file run on the console. Run npm test-all to launch this mode. All Tests will run one by one until every test in each spec file has been executed. Select any of the spec files to run tests for that spec file.

image

Folder Structure

πŸ“¦ 
β”œβ”€ .env
β”œβ”€ .gitignore
β”œβ”€ README.md
β”œβ”€ cypress.config.ts
β”œβ”€ cypress
β”‚  β”‚   
β”‚  β”œβ”€ e2e
β”‚  β”‚  β”œβ”€ 01-cities
β”‚  β”‚  β”‚  β””─ 01-citylist.cy.ts
β”‚  β”‚  β”œβ”€ 02-notes
β”‚  β”‚  β”‚  β””─ 02-notes.cy.ts
β”‚  β”‚  β””─ 03-search
β”‚  β”‚     β””─ 03-searchbar.cy.ts
β”‚  β”œβ”€ fixtures
β”‚  β”‚  β”œβ”€ cities.json
β”‚  β”‚  β”œβ”€ profile.json
β”‚  β”‚  β””─ users.json
β”‚  β”œβ”€ support
β”‚  β”‚  β”œβ”€ commands.ts
β”‚  β”‚  β””─ e2e.ts
|
β”œβ”€ package-lock.json
β”œβ”€ package.json
β”œβ”€ public
β”‚  β”œβ”€ favicon.ico
β”‚  β”œβ”€ index.html
β”‚  β”œβ”€ manifest.json
β”‚  β””─ robots.txt
β”œβ”€ src
β”‚  β”œβ”€ App.css
β”‚  β”œβ”€ App.test.tsx
β”‚  β”œβ”€ App.tsx
β”‚  β”œβ”€ assets
β”‚  β”‚  β”œβ”€ data
β”‚  β”‚  β”‚  β””─ cities.ts
β”‚  β”‚  β”œβ”€ images
β”‚  β”‚  β”‚  β”œβ”€ BackgroundImage.jpeg
β”‚  β”‚  β”‚  β”œβ”€ SunIcon.png
β”‚  β”‚  β”‚  β””─ WeatherBackground.jpeg
β”‚  β”‚  β””─ screenshots
β”‚  β”‚     β”œβ”€ CityDetails.png
β”‚  β”‚     β”œβ”€ DefaultCities.png
β”‚  β”‚     β”œβ”€ FavoriteCities.png
β”‚  β”‚     β”œβ”€ Notes.png
β”‚  β”‚     β”œβ”€ SearchBar.png
β”‚  β”‚     β””─ SpecFile.png
β”‚  β”œβ”€ components
β”‚  β”‚  β”œβ”€ CityDetails
β”‚  β”‚  β”‚  β””─ CityDetails.tsx
β”‚  β”‚  β”œβ”€ CityList
β”‚  β”‚  β”‚  β””─ CityList.tsx
β”‚  β”‚  β”œβ”€ FavoritesList
β”‚  β”‚  β”‚  β””─ FavoritesList.tsx
β”‚  β”‚  β”œβ”€ Notes
β”‚  β”‚  β”‚  β”œβ”€ NotesList.css
β”‚  β”‚  β”‚  β”œβ”€ NotesList.tsx
β”‚  β”‚  β”‚  β”œβ”€ cards
β”‚  β”‚  β”‚  β”‚  β””─ NoteItemCard.tsx
β”‚  β”‚  β”‚  β””─ forms
β”‚  β”‚  β”‚     β”œβ”€ create
β”‚  β”‚  β”‚     β”‚  β”œβ”€ CreateNoteForm.css
β”‚  β”‚  β”‚     β”‚  β””─ CreateNoteForm.tsx
β”‚  β”‚  β”‚     β””─ edit
β”‚  β”‚  β”‚        β”œβ”€ UpdateNoteForm.css
β”‚  β”‚  β”‚        β””─ UpdateNoteForm.tsx
β”‚  β”‚  β”œβ”€ SearchBar
β”‚  β”‚  β”‚  β”œβ”€ SearchBar.tsx
β”‚  β”‚  β”‚  β””─ searchbar.css
β”‚  β”‚  β”œβ”€ UserCity
β”‚  β”‚  β”‚  β””─ UserCityDetails.tsx
β”‚  β”‚  β””─ common
β”‚  β”‚     β”œβ”€ Cards
β”‚  β”‚     β”‚  β”œβ”€ CityTempCard.tsx
β”‚  β”‚     β”‚  β””─ CityWeatherDetailsCard.tsx
β”‚  β”‚     β”œβ”€ CustomComponents
β”‚  β”‚     β”‚  β”œβ”€ CreateUpdateButton.ts
β”‚  β”‚     β”‚  β”œβ”€ DeleteButton.ts
β”‚  β”‚     β”‚  β””─ Spinner.ts
β”‚  β”‚     β””─ Modals
β”‚  β”‚        β”œβ”€ Modal.css
β”‚  β”‚        β””─ Modal.tsx
β”‚  β”œβ”€ context
β”‚  β”‚  β”œβ”€ AppContext.ts
β”‚  β”‚  β””─ ContextValues.ts
β”‚  β”œβ”€ helpers
β”‚  β”‚  β”œβ”€ cities.ts
β”‚  β”‚  β”œβ”€ date.ts
β”‚  β”‚  β”œβ”€ favorites.ts
β”‚  β”‚  β””─ notes.ts
β”‚  β”œβ”€ hooks
β”‚  β”‚  β”œβ”€ useFetchCities.ts
β”‚  β”‚  β””─ useUserLocation.ts
β”‚  β”œβ”€ index.css
β”‚  β”œβ”€ index.tsx
β”‚  β”œβ”€ logo.svg
β”‚  β”œβ”€ pages
β”‚  β”‚  β”œβ”€ CityDetailsPage.tsx
β”‚  β”‚  β””─ Homepage.tsx
β”‚  β”œβ”€ react-app-env.d.ts
β”‚  β”œβ”€ reportWebVitals.ts
β”‚  β”œβ”€ services
β”‚  β”‚  β”œβ”€ api.ts
β”‚  β”‚  β”œβ”€ getUserLocation.ts
β”‚  β”‚  β””─ localStorage.ts
β”‚  β””─ types.ts
└─ tsconfig.json