-
Notifications
You must be signed in to change notification settings - Fork 0
8회차 과제 - 김정운 #2
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
Open
vni911
wants to merge
6
commits into
main
Choose a base branch
from
feature/kim_jeong_un
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+154
−2
Open
8회차 과제 - 김정운 #2
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| import React from "react"; | ||
| import FetchMovies from "./fetchMovies"; | ||
|
|
||
| const App = () => { | ||
| return <div>App</div>; | ||
| return ( | ||
| <div> | ||
| <FetchMovies/> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; | ||
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
|
|
||
| const fetchMovies = () => { | ||
| const movies = []; | ||
|
|
||
| // movies 배열 안에 객체 형태의 데이터 추가 | ||
| for (let i = 1; i <= 2500; i++) { | ||
| movies.push({ | ||
| id: i, | ||
| title: `Movie ${i}`, | ||
| description: `Description for Movie ${i}`, | ||
| }); | ||
| console.log("2500개의 영화 목록을 가져오는 중..."); | ||
| } | ||
|
|
||
| // fetchMovies함수가 동작하는데 오래 걸린다고 가정하기 위한 코드 | ||
| alert("데이터를 가져오는 중입니다..."); | ||
|
|
||
| return movies; | ||
| }; | ||
|
|
||
| const FetchMovies = () => { | ||
| const [movies, setMovies] = useState([]); | ||
| const [loading, setLoading] = useState(true); | ||
| const [watched, setWatched] = useState([]); | ||
| const [toWatch, setToWatch] = useState([]); | ||
|
|
||
| useEffect(() => { | ||
| const loadMovies = async () => { | ||
| setLoading(true); // 로딩 시작 | ||
| const data = await fetchMovies(); | ||
| setMovies(data); | ||
| setLoading(false); // 로딩 종료 | ||
| }; | ||
|
|
||
| loadMovies(); | ||
| }, []); | ||
|
|
||
| const sortById = (list) => list.sort((a, b) => a.id - b.id); | ||
|
|
||
| const addWatchedList = (movie) => { | ||
| setWatched((prev) => sortById([...prev, movie])); | ||
| setMovies((prev) => sortById(prev.filter((m) => m.id !== movie.id))); | ||
| }; | ||
|
|
||
| const addToWatchList = (movie) => { | ||
| setToWatch((prev) => sortById([...prev, movie])); | ||
| setMovies((prev) => sortById(prev.filter((m) => m.id !== movie.id))); | ||
| }; | ||
|
|
||
| const removeWatchedList = (movie) => { | ||
| setWatched((prev) => sortById(prev.filter((m) => m.id !== movie.id))); | ||
| setMovies((prev) => sortById([...prev, movie])); | ||
| }; | ||
|
|
||
| const removeToWatchList = (movie) => { | ||
| setToWatch((prev) => sortById(prev.filter((m) => m.id !== movie.id))); | ||
| setMovies((prev) => sortById([...prev, movie])); | ||
| }; | ||
|
|
||
| if (loading) { | ||
| return ( | ||
| <div> | ||
| <div className="text-center border bg-gray-700 text-white font-bold text-2xl p-3"> | ||
| Movie List | ||
| </div> | ||
| <div className="mb-7 text-center text-xl font-bold mt-10"> | ||
| Loading... | ||
| </div> | ||
| <div className="text-center border bg-gray-700 text-white font-bold text-xl p-3"> | ||
| Footer | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
Comment on lines
+61
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로딩 중일 때의 화면도 구현하는 것도 좋은 것 같습니다! |
||
|
|
||
| return ( | ||
| <div className="flex flex-col justify-between text-center h-screen pl-3 pr-3 pb-0.5"> | ||
| <div className="text-center border bg-gray-700 text-white font-bold text-4xl p-6 mt-1 h-[170px]"> | ||
| Movie List | ||
| </div> | ||
| <div className="justify-between flex align-center overflow-hidden text-center mt-3"> | ||
| <div className="bg-gray-100 w-[250px]"> | ||
| <div className="pt-15 font-bold "> | ||
| <div className="pb-10 font-bold text-2xl">시청한 영화 목록</div> | ||
| {watched.map((movie) => ( | ||
| <div key={movie.id} className="mb-3 border-b pb-3 border-gray-300"> | ||
| <div>{movie.title}</div> | ||
| <button | ||
| onClick={() => removeWatchedList(movie)} | ||
| className="text-sm mt-1 px-2 py-1 border rounded bg-white hover:bg-gray-200" | ||
| > | ||
| 삭제 | ||
| </button> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| <ul className="flex-1 overflow-auto font-semibold"> | ||
| {movies.map((movie) => ( | ||
| <li key={movie.id} className="border-b p-4"> | ||
| <div>{movie.title}</div> | ||
| <div>{movie.description}</div> | ||
| <div className="just"> | ||
| <button | ||
| onClick={() => addWatchedList(movie)} | ||
| className="bg-white hover:bg-gray-500 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded mt-4 mr-3"> | ||
| 시청한 영화 담기 | ||
| </button> | ||
| <button | ||
| onClick={() => addToWatchList(movie)} | ||
| className="bg-white hover:bg-gray-500 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded "> | ||
| 볼 영화 담기 | ||
| </button> | ||
| </div> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
|
|
||
|
|
||
| <div className="bg-gray-100 w-[250px]"> | ||
| <div className="pt-15 font-bold "> | ||
| <div className="pb-10 font-bold text-2xl">볼 영화 목록</div> | ||
| {toWatch.map((movie) => ( | ||
| <div key={movie.id} className="mb-3 border-b pb-3 border-gray-300"> | ||
| <div>{movie.title}</div> | ||
| <button | ||
| onClick={() => removeToWatchList(movie)} | ||
| className="text-sm mt-1 px-2 py-1 border rounded bg-white hover:bg-gray-200" | ||
| > | ||
| 삭제 | ||
| </button> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
| <div className="text-center border bg-gray-700 text-white font-bold text-4xl p-6 mt-3"> | ||
| Footer | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default FetchMovies; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sortById라는 함수를 통해 인덱스를 삭제하면 해당 함수 호출을 통한 정렬을 편리하게 구현하셨군요!