Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added search bar on navbar with optimized code #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions src/Components/WeatherCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,40 @@ const WeatherCard = ({
const [icon, setIcon] = useState(sun);
const { time } = useDate();

const weatherIcons = {
cloud: cloud,
rain: rain,
clear: sun,
thunder: storm,
fog: fog,
snow: snow,
wind: wind,
};

useEffect(() => {
if (iconString) {
if (iconString.toLowerCase().includes('cloud')) {
setIcon(cloud);
} else if (iconString.toLowerCase().includes('rain')) {
setIcon(rain);
} else if (iconString.toLowerCase().includes('clear')) {
setIcon(sun);
} else if (iconString.toLowerCase().includes('thunder')) {
setIcon(storm);
} else if (iconString.toLowerCase().includes('fog')) {
setIcon(fog);
} else if (iconString.toLowerCase().includes('snow')) {
setIcon(snow);
} else if (iconString.toLowerCase().includes('wind')) {
setIcon(wind);
}
}
const lowerCaseIconString = iconString?.toLowerCase();
const matchedIcon = Object.keys(weatherIcons).find((key) =>
lowerCaseIconString?.includes(key)
);
setIcon(matchedIcon ? weatherIcons[matchedIcon] : sun);
}, [iconString]);

const convertTemperature = (temp) => {
return isCelsius ? temp : Math.round((temp * 1.8) + 32);
return isCelsius ? temp : Math.round(temp * 1.8 + 32);
};

return (
<div className='weather-card custom-max:w-[18rem] w-[22rem] custom-max:h-[30rem] min-w-[22rem] h-[30rem] glassCard p-4'>
<div className='flex w-full justify-center items-center gap-4 mt-12 mb-4 custom-max:gap-2'>
<img className='weather-icon w-[5rem]' src={icon} alt="weather_icon" />
<img className='weather-icon w-[5rem]' src={icon} alt="weather_icon" />
<p className='font-bold custom-max:text-4xl text-5xl flex justify-center items-center'>
{convertTemperature(temperature)} &deg;{isCelsius ? 'C' : 'F'}
</p>
</div>
<div className='font-bold text-center custom-max:text-lg text-xl'>{place}</div>
<div className='w-full flex justify-between items-center mt-4'>
<p className='flex-1 text-center p-2 '>{new Date().toDateString()}</p>
<p className='flex-1 text-center p-2 '>{time}</p>
<p className='flex-1 text-center p-2'>{new Date().toDateString()}</p>
<p className='flex-1 text-center p-2'>{time}</p>
</div>
<div className='w-full flex justify-between items-center mt-4 gap-4'>
<p className='flex-1 text-center p-2 font-bold text-base bg-blue-600 shadow rounded-lg'>
Expand Down
Loading