A small, responsive weather dashboard built with React, Vite, and Tailwind CSS.
It fetches weather data from OpenWeatherMap and uses Unsplash / Pixabay to show background imagery for each forecast day. The app supports searching by city name and getting the user's current location via the Geolocation API. Recent searches are saved to localStorage.
- Search for a city to view a multi-day forecast.
- Use your device location to auto-populate the city search.
- Photo-backed weather cards pulled from Unsplash/Pixabay based on weather conditions.
- Search history stored in
localStorage(click to re-fetch, or remove). - Built with Vite for fast dev builds and Tailwind CSS for styling.
- React 18
- Vite
- Tailwind CSS
- DaisyUI (via
react-daisyui) for some UI elements - Unsplash / Pixabay (background photos)
- OpenWeatherMap (forecast data)
- Utilities:
lodash-es,clsx,react-icons, loader spinners
Prerequisites
- Node.js (18+) or Bun (the repo contains a
bun.lockbif you prefer Bun) - An OpenWeatherMap API key (required)
- An Unsplash access key (recommended — falls back to Pixabay if you choose)
- (Optional) Pixabay API key if you want to use Pixabay directly
Install dependencies
Using npm:
npm installUsing bun:
bun installRun the dev server
npm run dev
# or
bun run devBuild for production
npm run buildPreview production build
npm run previewLinting
npm run lintThe app expects environment variables prefixed with VITE_ so Vite exposes them to the client. Create a .env file in the project root (do not commit secrets) with the following values:
VITE_OPENWEATHER_APIKEY=your_openweather_api_key
VITE_UNSPLASH_ACCESSKEY=your_unsplash_access_key
VITE_PIXBAY_APIKEY=your_pixabay_api_keyVITE_OPENWEATHER_APIKEY— required. The app calls OpenWeatherMap endpoints for geocoding and forecast data.VITE_UNSPLASH_ACCESSKEY— optional but used to fetch attractive background photos for forecast cards.VITE_PIXBAY_APIKEY— optional alternative photo provider used by a hook in the project.
Notes on APIs
- The code uses the OpenWeatherMap geocoding (
/geo/1.0/reverse) and the daily forecast endpoint (/data/2.5/forecast/daily) withunits=metric. - Make sure your OpenWeather account has the appropriate access and quota for these endpoints.
- The main component is
src/components/Dashboard.jsx. It manages state for loading, search history, and fetched weather data. src/components/Query.jsxrenders the search input and the geolocation button. It uses the browsernavigator.geolocationAPI to retrieve coordinates and then reverse-geocodes with OpenWeather.src/components/WeatherCard.jsxdisplays a single day's forecast and askssrc/hooks/unsplash.js(orpixbay.js) for a related background photo.- Recent searches are saved in
localStorageunder the keysearchHistoryand displayed bysrc/components/SearchHistory.jsx.
index.html— Vite entry HTMLsrc/main.jsx— React entrysrc/App.jsx— root App (rendersDashboard)src/components/Dashboard.jsx— app container and data fetch orchestrationsrc/components/Query.jsx— search input, location buttonsrc/components/WeatherCard.jsx— daily forecast cardsrc/components/City.jsx— header showing current city and conditionsrc/components/SearchHistory.jsx— recent searches UIsrc/components/Skeleton.jsx— small placeholder skeleton UIsrc/hooks/unsplash.js— helper that calls Unsplash APIsrc/hooks/pixbay.js— helper that calls Pixabay APIsrc/hooks/weather.js— small helper wrapper for fetching/parsing OpenWeather responsestailwind.config.js,postcss.config.js— Tailwind setupvite.config.js— Vite config
- The app expects lower-case history entries; the Dashboard component ensures history items are stored in lower case and prevents duplicates.
- If you see a blank screen or
undefineddata, confirm yourVITE_OPENWEATHER_APIKEYis set and valid. - Geolocation requires HTTPS (or
localhost) and will prompt the user for permission. - If background images fail to load, the weather cards will still display textual data and icons from OpenWeather.
- CORS / blocked requests: If a third-party API rejects requests from the browser, test the request in a server-side proxy or ensure your API plan allows browser usage.
- Missing env variables: The app will not fetch weather data without
VITE_OPENWEATHER_APIKEY. - API rate limits: Watch quota for Unsplash/Pixabay/OpenWeather; consider caching or server-side proxy for heavy usage.
Feel free to open issues or PRs. Small suggestions:
- Improve accessibility and ARIA attributes for interactive controls.
- Add unit or integration tests for the fetch logic in
Dashboard.jsx. - Add error boundary components to better surface fetch errors.
This repository doesn't include a license file — add one if you plan to open-source it publicly.
If you'd like, I can also:
- Add a minimal
.env.examplefile with the VITE_ variables populated with placeholders. - Create a short CONTRIBUTING.md or update the repo
package.jsonto include astartscript.
Status: README generated from source files present in the repository on Sep 17, 2025.
