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

[ 4주차 기본/심화 과제 ] 비니의 날씨 입니다 #9

Merged
merged 29 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8c943cd
init: 초기 설치
eunbeann May 10, 2023
2c216e2
feat: yarn 설치
eunbeann May 10, 2023
004aab4
styles: 샘플 컨텐츠 삭제
eunbeann May 10, 2023
7649446
chore: styled-component 설치
eunbeann May 10, 2023
d85b48e
styles: GlobalStyles 설정
eunbeann May 10, 2023
e0cd6bf
styled: styled-reset 설치
eunbeann May 10, 2023
030a4ef
styles: 전역 스타일 설정 (GlobalStyles, styled-reset)
eunbeann May 10, 2023
1135b8c
chore: 날씨 이미지 상수 데이터 추가
eunbeann May 10, 2023
013f743
design: header 뷰 짜기
eunbeann May 10, 2023
de0ae0d
design: 서칭바 뷰 제작
eunbeann May 10, 2023
3971ee4
desing:날씨 섹션 뷰 제작
eunbeann May 10, 2023
9a279a9
desgin: 전역 테마 색 수정, 폰트 수정
eunbeann May 10, 2023
f16e9a4
style: MainPage 렌더링
eunbeann May 10, 2023
9c07f43
chore:react-router-dom 설치
eunbeann May 10, 2023
eb67cc2
sttyles: 스타일드컴포넌트 형식 바꾸기 St.~
eunbeann May 11, 2023
67ce2a5
feat: Error 페이지 추가
eunbeann May 12, 2023
62b2ae8
styles; day뷰 분리
eunbeann May 12, 2023
37d1363
feat: day 불러온 데이터 띄워주기
eunbeann May 12, 2023
486b116
styles: Week 뷰 분리 작성
eunbeann May 12, 2023
bb437fe
feat: Week 데이터 불러오기
eunbeann May 12, 2023
a061f65
styles: 각 날씨 내부 헤더 일반 태그로 변경
eunbeann May 12, 2023
174322c
feat: 검색할 때 day/:area로 보이게
eunbeann May 12, 2023
f07343b
feat:select 박스에 기능 추가 + 일간 주간 선택
eunbeann May 12, 2023
d49875d
feat: 기본 과제 끝!
eunbeann May 12, 2023
f01e8c6
styles:서치바 태그 수정으로 가독성 개선
eunbeann May 12, 2023
f3af660
style:placeholder 스타일 추가
eunbeann May 12, 2023
e7509c4
feat: 검색창에 value 남기기
eunbeann May 12, 2023
0ca15fb
feat: skeletone 추가
eunbeann May 12, 2023
9e73472
styles: 스타일 정렬
eunbeann May 12, 2023
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
2 changes: 2 additions & 0 deletions weather-forecast/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# VITE_APP_WEATHER='587bd6b133db966f6015b13ee1898879';//언니꺼
VITE_APP_WEATHER='fb02f9333a202901a648da747fc19542' #내꺼
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭐야 이거 왜 올라가잇어

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋㅋgitignore에 얼른 추가해줘

15 changes: 15 additions & 0 deletions weather-forecast/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
},
}
24 changes: 24 additions & 0 deletions weather-forecast/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions weather-forecast/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image" href="https://cdn-icons-png.flaticon.com/512/2570/2570524.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>비니의 날씨입니다</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions weather-forecast/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "weather-forecast",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.1",
"styled-components": "^6.0.0-rc.1",
"styled-reset": "^4.4.7",
"yarn.lock": "^0.0.1-security"
},
"devDependencies": {
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^4.0.0",
"eslint": "^8.38.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"vite": "^4.3.2"
}
}
18 changes: 18 additions & 0 deletions weather-forecast/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import GlobalStyles from './styles/GlobalStyles.jsx'
import { ThemeProvider } from 'styled-components'
import theme from "./styles/theme";
import Router from "./Router";

function App() {

return (
<>
<ThemeProvider theme={theme}>
<GlobalStyles />
<Router />
</ThemeProvider>
</>
)
}

export default App
26 changes: 26 additions & 0 deletions weather-forecast/src/Router.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Main from './pages/Main'
import { BrowserRouter, Route, Routes} from 'react-router-dom'
import Error from './components/Error'
import DayList from './pages/DayList'
import DaySection from './components/DaySection'
import WeekList from './pages/WeekList'
import WeekSection from './components/WeekSection'

const Router = () => {
return (
<BrowserRouter>
<Routes>
<Route index element={<Main/>} />
<Route path="day" element={<DayList />}>
<Route path=":area" element={<DaySection />}/>
</Route>
<Route path="week" element={<WeekList />}>
<Route path=":area" element={<WeekSection />}/>
</Route>
<Route path="*" element={<Error/>} />
</Routes>
</BrowserRouter>
)
}

export default Router
205 changes: 205 additions & 0 deletions weather-forecast/src/components/DaySection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import { styled } from 'styled-components'
import { WEATHER_TYPE } from '../data/weatherImg'
import axios from 'axios';
import { useState, useEffect } from 'react'
import { useParams } from 'react-router-dom';

const DaySection = () => {
const {area} = useParams();
const [isLoading, setIsLoading] = useState(false);
const [dayWeather, setDayWeather] = useState(
{
id: 0,
name: "",
weather: "",
temp: 0.0,
feels_like: 0.0,
temp_min: 0.0,
temp_max: 0.0,
clouds: 0.0,
});

const getDayWeather = async() => {
// 일간 데이터
try{
setIsLoading(true);
await axios
.get(`https://api.openweathermap.org/data/2.5/weather?q=${area}&appid=${import.meta.env.VITE_APP_WEATHER}&units=metric`)
.then((res) => res.data)
.then((data)=> {
if(data.cod == 200) {
console.log(data)
setDayWeather(
{
id: 0,
name: data.name,
weather_description: data.weather[0].description,
weather_img_url: WEATHER_TYPE.filter(
(weather) => weather.description === data.weather[0].description
)[0].imgURL,
temp: data.main.temp,
feels_like: data.main.feels_like,
temp_min: data.main.temp_min,
temp_max: data.main.temp_max,
clouds: data.clouds.all,
})
}
})
} catch (err) {
console.log(err);
}
setIsLoading(false);
}

useEffect(() => {
getDayWeather();
}, [area])

return (
<>
{isLoading?(
<>
<St.MockCard>
<h3 className='skeleton-title'></h3>
<img className='skeleton-img'/>
<div className='skeleton-div'>
<span className='skeleton-span'> </span>
<p className='skeleton-p'> </p>
</div>
</St.MockCard>
</>
):(
<>
<St.MockCard>
<h3>{dayWeather.name}</h3>
<img src={dayWeather.weather_img_url} alt={dayWeather.weather_description} />
<div>
<span> 온도 </span>
<p> {dayWeather.temp} </p>
</div>
<div>
<span> 체감 온도 </span>
<p> {dayWeather.feels_like}</p>
</div>
<div>
<span> 최저 / 최고 </span>
<p> {dayWeather.temp_max} / {dayWeather.temp_min} </p>
</div>
<div>
<span> 구름 </span>
<p> {dayWeather.clouds}% </p>
</div>
</St.MockCard>
</>
)}
</>
)
}

export default DaySection

const St = {

MockCard : styled.article `
display: flex;
flex-flow: column wrap;
justify-content: space-around;
align-items: center;
width: 24rem;
height: 40rem;
border-radius: 1rem;
background-color: ${(props) => props.theme.muteGreen};
padding: 2rem 1rem;
margin: 1rem;
> h3 {
height: fit-content;
font-size: 4rem;
color: ${(props) => props.theme.backgroundColor};
}
> img {
/* width: 17rem; */
height: 17rem;
object-fit: contain;
border-radius: 1rem;
}
> div {
display: flex;
justify-content: space-between;
width: 17rem;
font-size: 2.3rem;
font-weight: 600;
>span {
text-align: start;
}
>p {
text-align: end;
}
}
@keyframes skeleton-gradient {
0% {
background-color: rgba(165, 165, 165, 0.1);
}
50% {
background-color: rgba(165, 165, 165, 0.3);
}
100% {
background-color: rgba(165, 165, 165, 0.1);
}
}
.skeleton-title {
width: 12rem;
height: 4rem;
background: ${(props) => props.theme.lightgrey};
overflow: hidden;
position: relative;
}

.skeleton-title::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: skeleton-gradient 1.5s infinite ease-in-out;
}


.skeleton-img {
width: 14rem;
height: 14rem;
background: ${(props) => props.theme.lightgrey};
margin: 2rem 2rem;
overflow: hidden;
position: relative;
}

.skeleton-img::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: skeleton-gradient 1.5s infinite ease-in-out;
}

.skeleton-div {
width: 14rem;
height: 14rem;
background: ${(props) => props.theme.lightgrey};
overflow: hidden;
position: relative;
}

.skeleton-div::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: skeleton-gradient 1.5s infinite ease-in-out;
}
`,
};
43 changes: 43 additions & 0 deletions weather-forecast/src/components/Error.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'
import PageLayout from './PageLayout'
import { styled } from 'styled-components'

const Error = () => {
return (
<div>
<PageLayout>
<St.Error>
<h1>
Error 404
</h1>
<p>
주소가 잘못되진 않았나요?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 친절하고 귀엽다ㅎㅎ

</p>
</St.Error>
</PageLayout>
</div>
)
}

export default Error


const St = {
Error : styled.div `
margin-top: 10rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

width: 60vh;

h1 {
font-size:10rem;
}

p {
font-size: 4rem;
}
`
}
Loading