- Highlight: Use of React hooks for state and effects, Axios for async data fetching, and Bootstrap for responsive UI.
- Emphasize: Clean separation of concerns—search, display, and layout are in their own components.
- Mention: Accessibility and responsiveness are considered (clear button, mobile-friendly layout).
- Point out: The app is easy to extend (e.g., add more weather details, support for more units, etc.).
- React: The core library for building user interfaces with components and hooks.
- Axios: For making HTTP requests to the OpenWeather API.
- Bootstrap: For responsive, mobile-first UI and utility classes.
- Custom CSS: For background video and responsive tweaks (Lander.css).
- Purpose: Main layout and entry point for the weather UI.
- Features:
- Renders a full-screen looping video background.
- Overlays a centered container with the app title, "Powered by OpenWeather" line, the search box, and the weather card.
- Uses Bootstrap classes for layout and spacing.
- Holds the main weather state, which is passed to the
WeatherCardcomponent.
- Key Points:
- Responsive design: The container adapts to screen size.
- Imports and uses
SearchandWeatherCardcomponents.
- Purpose: Allows users to search for a city and fetches suggestions as they type.
- Features:
- Controlled input field for city search.
- Shows a clear ("×") button inside the input when there’s text.
- Fetches city suggestions from the OpenWeather Geocoding API using Axios and useEffect (runs on every input change).
- Displays suggestions in a dropdown; clicking a suggestion fetches weather data for that city.
- Key Functions:
- useEffect: Watches the
querystate and fetches suggestions when it changes. - handleInput: Updates the
querystate as the user types. - handleSelect: Fetches weather data for the selected city and updates the parent’s weather state.
- useEffect: Watches the
- Accessibility: The clear button is accessible and focuses the input after clearing.
- Purpose: Displays the current weather for the selected city.
- Features:
- Shows city name, temperature, feels like, humidity, sunrise, and sunset.
- Allows toggling between Celsius and Fahrenheit.
- Includes a close ("×") button to remove the card.
- Responsive and visually clean, using Bootstrap for layout.
- Key Functions:
- formatTime: Converts UNIX timestamps to readable AM/PM times, considering timezone offset.
- Unit Toggle: Switches between Celsius and Fahrenheit for temperature display.
- Purpose: Handles the background video, overlay, and responsive tweaks.
- Features:
.lander-bgand.lander-video: Ensures the video covers the entire background..lander-overlay: Adds a semi-transparent overlay for readability.- Media queries: Adjusts padding and width for mobile screens.
- Ensures
.cardand overlay containers are responsive.
- User opens the app: Sees a video background, app title, "Powered by OpenWeather", and a search box.
- User types a city: Search.jsx fetches and displays city suggestions in real-time.
- User selects a city: The app fetches current weather data for that city and displays it in WeatherCard.jsx.
- User can toggle temperature units or close the weather card to search again.
- State Management:
useStatefor local state in each component. - Side Effects:
useEffectin Search.jsx for API calls on input change. - Props: Passing data and callbacks between parent (Lander.jsx) and children (Search.jsx, WeatherCard.jsx).
- Refs:
useReffor focusing the input after clearing. - Conditional Rendering: Only shows the weather card if weather data is present.
- OpenWeather Geocoding API:
- Endpoint:
https://api.openweathermap.org/geo/1.0/direct - Used for city suggestions as the user types.
- Endpoint:
- OpenWeather Current Weather API:
- Endpoint:
https://api.openweathermap.org/data/2.5/weather - Used to fetch weather details for the selected city.
- Endpoint:
In summary:
This app demonstrates modern React practices, clean component structure, real-world API integration, and responsive design—all essential skills for a front-end developer.