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

조정현 과제 제출입니다. #3

Open
wants to merge 2 commits 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
28 changes: 28 additions & 0 deletions 8week/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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?


#SERVICE_KEY
.env
50 changes: 50 additions & 0 deletions 8week/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
Binary file added 8week/assets/movietheater.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions 8week/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions 8week/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/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions 8week/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "8week",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.9",
"less": "^4.2.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.15.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.12.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.15.0",
"vite": "^6.0.1"
}
}
58 changes: 58 additions & 0 deletions 8week/src/App.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
html,
body {
margin: 0; //magin 초기화
padding: 0; //magin 초기화
height: 100%; /* 화면 전체 높이를 100%로 설정 */
width: 100%; /* 화면 전체 너비를 100%로 설정 */
overflow: hidden; /* 화면을 넘는 요소를 숨깁니다. */
}
.appContainer {
margin: 0; //magin 초기화
padding: 0; //magin 초기화
height: 100vh; /* 화면 전체 높이를 100%로 설정 */
width: 100vw; /* 화면 전체 너비를 100%로 설정 */
overflow: hidden; /* 화면을 넘는 요소를 숨깁니다. */
}
.header {
height: 10%;
width: 100%;
font-size: 30px;
background-color: rgb(0, 0, 0);
color: white;
display: flex;
justify-content: center; /* 가로 가운데 정렬 */
align-items: center; /* 세로 가운데 정렬 */
}
main {
height: 80%;
width: 100%;
background-image: url("./assets/movietheater.png"); /* 배경 이미지 추가 */
background-size: cover; /* 배경 이미지를 화면에 맞게 확장 */
background-position: center; /* 배경 이미지를 중앙에 배치 */
background-repeat: no-repeat; /* 배경 이미지 반복을 방지 */
padding: 20px; /* 내부 여백 추가 */
color: white;
}

input {
padding: 10px;
font-size: 16px;
border: 2px solid white;
border-radius: 5px; /* 둥근 모서리 */
margin-left: 10px;
outline: none;
}
.date {
font-size: 20px;
}

footer {
height: 10%;
width: 100%;
background-color: rgb(0, 0, 0);
display: flex;
}
.footerContent {
color: white;
margin: 0px auto;
}
115 changes: 115 additions & 0 deletions 8week/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { useState, useEffect } from "react";
import axios from "axios";
import style from "./App.module.less";

// Movie 인터페이스 정의
// 내가 사용할 데이터는
// 해당 날짜를 검색했을 경우 해당 날짜의 영화 순위, 이름, 개봉일, 매출액, 관객수,
interface Movie {
rnum: string; // 순번을 출력: 문자열
rank: string; // 해당일자의 박스오피스 순위를 출력: 문자열
movieNm: string; // 영화이름 출력: 문자열
// salesAmt: string; // 해당일의 매출액을 출력: 문자열
// audiCnt: string; // 해당날관객수: 문자열
openDt: string; // 영화 개봉일: 문자열
}

function App() {
// 상태 관리: 영화 리스트, 날짜 입력 값, 로딩 상태
const [movies, setMovies] = useState<Movie[]>([]);
const [date, setDate] = useState<string>(""); // 빈칸

const SERVICE_KEY = import.meta.env.VITE_SERVICE_KEY; // 제공된 API 키

// input 박스에서 사용할 함수
const handleDateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setDate(e.target.value);
};

// 영화 데이터를 가져오는 함수
// 비동기 함수로 만들어서 접근해서 받을 때까지 await키워드를 이용해서 기다리기
const movieData = async (targetDate: string) => {
try {
const response = await axios.get(
`http://kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json`,
{
params: {
key: SERVICE_KEY, // API 키
targetDt: targetDate, // 넣고 싶은 날짜 넣기
},
}
);

//api 응답 성공
if (response.data.boxOfficeResult) {
setMovies(response.data.boxOfficeResult.dailyBoxOfficeList); // 영화 데이터 저장
}
} catch (error) {
// api응답 실패 했을 때 콘솔로 확인
console.error("API 요청 오류:", error);
}
};

// useEffect로 컴포넌트가 마운트될 때 기본 날짜로 영화 데이터 로드
useEffect(() => {
movieData(date); // 내가 인풋박스에서 만든 날짜를 기준으로
}, [date]); // `date` 값이 변경될 때마다 위의 함수를 작동시킨다!

return (
<div className={style.appContainer}>
<header className={style.header}>오늘의 영화!!</header>

{/* 날짜를 넣을 인풋박스를 만들것이다.*/}
<main>
<label>
<span className={style.date}>
궁금한 날짜를 입력해봐! (YYYYMMDD 형식):
</span>
<input
type="text"
value={date}
onChange={handleDateChange}
placeholder="날짜를 입력하세요"
/>
</label>

{/* 영화 데이터 테이블 */}

<table>
<thead>
<tr>
<th>순위</th>
<th>영화 제목</th>
<th>개봉일</th>
</tr>
</thead>
<tbody>
{/*3항 연산자 사용하기*/}
{movies.length > 0 ? (
movies.map((movie) => (
<tr key={movie.rnum}>
<td>{movie.rank}</td>
<td>{movie.movieNm}</td>
<td>{movie.openDt}</td>
</tr>
))
) : (
<tr>
<td colSpan={3}>해당 날짜에 대한 데이터가 없습니다.</td>
</tr>
)}
</tbody>
</table>
</main>
<footer className={style.footerContent}>
Copyright (c) 2011. Korean Film Council. All rights reserved
<br />
(48058) 부산광역시 해운대구 수영강변대로 130(우동) l 고객센터:
02-6261-6573 l 이용시간: 09:00 ~ 18:00(평일) l E-mail:
[email protected]
</footer>
</div>
);
}

export default App;
Loading