Code Monkey home page Code Monkey logo

iamsainikhil / weather-react Goto Github PK

View Code? Open in Web Editor NEW
95.0 3.0 22.0 18.53 MB

A robust weather application to provide current, 48 hours and 8-day weather forecast based on your geolocation built with ❤️ using React. Weather forecast data is powered by OpenWeather and Wind map is powered by Windy.

Home Page: https://iamsainikhil.com/weather-react

License: MIT License

HTML 0.43% JavaScript 12.06% CSS 86.41% SCSS 1.10%
react weather tailwindcss scss react-hooks weather-forecast javascript openweathermap-api windy

weather-react's Introduction

Table of Contents

Demo

app

Dynamic Weather Backgrounds

Weather.React.-.Backgrounds.-.Made.with.Clipchamp.mp4

🚀 Getting Started

You need to have a OpenWeather Account, follow the instructions described here to create an account and grab an API key.

Basic Setup

  • Clone the repository
git clone https://github.com/iamsainikhil/weather-react.git
  • Install the packages using the command npm install

Environment File

  • Create a .env file in the root directory of the project. Add the following properties in it:

    OPENWEATHER_API_KEY=<your OpenWeather API Key>
    

That's it! You can run the below available scripts to get up and running on the localhost. If you want to dive deeper into the codebase, I recommend you to check the architecture documentation to customize this application as your wish.

These instructions are very important to avoid the Blank Page issue when running the application on http://localhost:3000.

Available Scripts

In the project directory, you can run:

vercel dev

Runs the app in the local development mode (npm run start) while serving serverless functions defined in the /api folder. Open [http://localhost:3000](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.

For more information, check the Vercel docs here

npm run start

Runs the app in the development mode. Open [http://localhost:3000](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.

npm test

Launches the test runner in the interactive watch mode. See the section about

running tests for more information.

npm run build

Builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes. Your app is ready to be deployed!

See the section about deployment for more information.

npm run eject

Note: this is a one-way operation. Once you eject, you can’t go back!

If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However, we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

🧐 What's inside?

A quick look at the top-level files and directories in this weather-react project.

├── api
	├── address.js
	├── forecast.js
	├── hello.js
├── public
├── src
	├── components
	├──	containers
	├── context
	├── fonts
	├── sass
	├── styles
	├── tests
	├── utils
	├── App.js
	├── index.js
	├── serviceWorker.js
├── tailwind.config.js
  1. api: This directory contain all of the code related to the back-end of the application.
    • <name>.js: This file serve as the serverless function which when deployed on Vercel will accept requests from the front-end application and return response.
  2. public: This directory contain all the assets like images, icons, manifest (PWA), and favicons.
  3. src: This directory contain all of the code related to what you see on the front-end of the application. src is a convention for “source code”.
    • components: This directory contain several React components with each component having an own directory.
    • containers: This directory contain several containers with each container wrapping many components defined in the above components directory. Each container have an own directory.
    • context: This directory contain context files with each file holding the logic related to the state shared between the containers & components.
    • fonts: This directory contain font files related to several font variations and formats.
    • sass: This directory contain the application styles written in scss grouped into several directories.
    • styles: This directory contain only two files main.css (styles used in development) and style.css (styles used in production).
    • tests: This directory contain test suites with each file containing several test cases testing a utility function or a component.
    • utils: This directory contain files with each file representing a utility function.
    • App.js: This is the main React component that is rendered in the DOM which contain the containers & components as well as routing.
    • index.js: This is the first file which gets run in the browser after starting the application. App.js component rendering as well as serviceworker registration process takes place in this file.
    • serviceWorker: This file contains the code related to registration/deregistration of a Service worker.
  4. tailwind.config.js: This file contains the configuration related to tailwindcss.

📖 Architecture

Weather React Application Architecture

Application Architecture Live

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Code Splitting

For more info, check here: https://facebook.github.io/create-react-app/docs/code-splitting

Analyzing the Bundle Size

For more info, check here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

Making a Progressive Web App

For more info, check here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

Advanced Configuration

For more info, check here: https://facebook.github.io/create-react-app/docs/advanced-configuration

Deployment

For more info, check here: https://facebook.github.io/create-react-app/docs/deployment

npm run build fails to minify

For more info, check here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

💡 Motivation

I started learning React in February 2020 and thought of putting knowledge into reality by developing an application. I am interested in building an application that is API resource-intensive to challenge me writing efficient code keeping performance, UX, maintainability, scalability, and optimization in mind.

There are so many weather-related applications out in the wild. So, the goal is to create a UI that is beautiful yet simple and effective for any user to use.

💻 Technologies

  • This application is created with Create React App

  • React (v16.12)

  • Styling syntax was written in SCSS and using TailwindCSS

  • There are bunch of scripts that run when you start application to compile scss to css

😢 Challenges

  • First, I used the OpenWeather API to fetch the weather forecast data. However, 5-day forecast data was not reliable i.e. when a user on 14th March 2020 at 7:00 PM EST tries to fetch 5-day forecast data, will get forecast data starting 15th March 2020 at 12:00 AM UTC. This posed a big problem of categorizing 5-day data into individual days since the data is not always consistent and is based on UTC and not based on the user timezone. Finally, I switched to Dark Sky API which is more reliable and provides a robust data model. However, there is a limit of 1000 calls/day.

  • Dark Sky API needs a proxy server to send and receive a response which was easy in the development stage using a browser extension like this to enable CORS in the browser. However, I can't ask every user to install this extension in their browser to check the weather forecast. So, I overcome this issue temporarily for now using the cors-anywhere library which you can get more info by checking here. However, I overcome the temporary solution and built a proxy server by deploying the Node.js API functions on the Vercel's serverless architecture and can be accessed here.

  • Latest challenge I encountered is that Teleport API is temporarily shutdown and this led to broken autocomplete city search, and photos for favorited cities. Moreover, there is a tight coupling of code logic with this API. Now, I made a well thought highly scalable solution of using Algolia Places Rest API for fetching address based on city query as well as fetching city name based on latitude and longitude. I am very much happy about this change since it removed a lot of bad code and improved the application load times and performance.

    Note: The application UI/UX is not affected with this API change.

  • Algolia Places shutdown it's Geocoding API on May 31st, 2022 which broke the address search autocomplete functionality in the app.

  • Dark Sky got acquired by Apple and shut down it's API service at the end of 2021. At the same time, OpenWeather API introduced a new service One Call API 3.0 which is similar to Dark Sky API with more forecast features like hourly forecast for 48 hours, daily forecast for 8 days, national weather alerts, etc.

  • Finally, replaced both Dark Sky & Algolia Places with just OpenWeather API for both weather forecast and reverse geocoding. However, address search autocomplete functionality is removed from the app.

🏎 Roadmap

  • Build a proxy server using Express for Dark Sky API requests

  • Convert to a TypeScript project

  • Unit Testing

  • Add documentation for components using Storybook

  • Publish this project as an NPM package that can be consumed elsewhere.

🙌 Contribution

  • Open pull request with improvements.

  • If you have any new idea, check the feature request template to create a request.

  • If you found any issue or a bug, check the bug report template to create a report.

📃 License

Have a look at the license file for details

📧 Contact

Whether you’d like to discuss a project, ask me about my website or simply say “hello”, I’d love to hear from you.

Email: [email protected]

😍 Featured On

🙏 Acknowledgements

See the Acknowledgements page on the wiki for a list of Acknowledgements for Weather React codebase.

weather-react's People

Contributors

dependabot[bot] avatar iamsainikhil avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

weather-react's Issues

Auto suggested Search Bar

Hi, I think a search bar should be there since there are so many good features inside your project but I think implementing a Search bar helps to find more data about other cities as well.

Search bar included :

Auto Suggestion.
Auto Capitalize.
Enter to proceed.
handleWrongCityName()

LogRocket Issue Tracking confirmation

Sign in to LogRocket here.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlZ3JhdGlvbl9pZCI6ODU5LCJsb2dpbl9uYW1lIjoiaWFtc2FpbmlraGlsIn0.AI_PXpDLAf5y0ciYD61ozl3dphy9LkIMLHzHaKfjNNU

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.