Home 컴포넌트가 어느정도 끝났다. 네비게이션바도 일단 구현은 해놨는데 기능들 다 구현이 되면 모달창과 함께 수정해야겠다.
NavBar는 화면 전환을 위한 달 아이콘, 모달로 이동하는 Info 아이콘이 있다.
달 아이콘을 누르면 다른 아이콘으로 전환 되며 색상이 변경된다.
Info 아이콘을 누르면 모달창이 생긴다. 모션은 framer-motion의 layoutId로 구현했다.
아직 모달 정보는 생각 중이라 차차 구현할 예정이다.
// api.ts
export const weatherAPI = async (city:string) => {
try {
const res = await axios.get(city === '' ? `https://api.openweathermap.org/data/2.5/weather?q=Seoul&appid=${appId}` : `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${appId}`);
return res.data;
} catch(error) {
console.log(error);
}
}
// Home.tsx
const [city, setCityState] = useState('');
const handleOnKeyDown = (e:React.KeyboardEvent<HTMLInputElement>) => {
if(e.key === 'Enter') {
setCityState(e.currentTarget.value);
setInputState(false);
}
}
const {data:data} = useQuery<IWeatherInfo>(["api", "weather"], weatherAPIDefault(city));