-
Notifications
You must be signed in to change notification settings - Fork 21
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
[정성현] sprint7 #104
Merged
GANGYIKIM
merged 4 commits into
codeit-bootcamp-frontend:React-정성현
from
jsh1147:React-정성현-sprint7
Sep 23, 2024
The head ref may contain hidden characters: "React-\uC815\uC131\uD604-sprint7"
Merged
[정성현] sprint7 #104
Changes from all commits
Commits
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 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
This file contains 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
This file contains 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
This file contains 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,54 +1,50 @@ | ||
import { useState, useEffect } from "react"; | ||
import "./Dropdown.css"; | ||
|
||
export default function Dropdown({ setParamObj }) { | ||
export default function Dropdown({ onSelect, children }) { | ||
const [isActive, setIsActive] = useState(false); | ||
const [value, setValue] = useState("recent"); | ||
const [value, setValue] = useState(children[0].props.value); | ||
|
||
const handleSelectClick = () => { | ||
setIsActive((prev) => !prev); | ||
}; | ||
const handleSelectBlur = (e) => { | ||
if (e.relatedTarget?.className === "orderSelect__option") return; | ||
if (e.relatedTarget?.className === "dropdown__option") return; | ||
setIsActive(false); | ||
}; | ||
const handleRecentClick = () => { | ||
setValue("recent"); | ||
setIsActive(false); | ||
}; | ||
const handleFavoriteClick = () => { | ||
setValue("favorite"); | ||
const handleOptionClick = (e) => { | ||
setValue(e.target.value); | ||
setIsActive(false); | ||
}; | ||
|
||
useEffect(() => { | ||
setParamObj((prevObj) => ({ ...prevObj, page: 1, orderBy: value })); | ||
}, [setParamObj, value]); | ||
onSelect(value); | ||
}, [onSelect, value]); | ||
|
||
return ( | ||
<div className="orderSelect"> | ||
<div className="dropdown"> | ||
<button | ||
className="orderSelect__select" | ||
className="dropdown__select" | ||
type="button" | ||
onClick={handleSelectClick} | ||
onBlur={handleSelectBlur} | ||
> | ||
{value === "recent" ? "최신순" : "좋아요순"} | ||
{children.find((child) => value === child.props.value).props.children} | ||
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. P2: |
||
</button> | ||
{isActive && ( | ||
<ul className="orderSelect__optionList"> | ||
<li className="orderSelect__optionListItem"> | ||
<button className="orderSelect__option" onClick={handleRecentClick}> | ||
최신순 | ||
</button> | ||
</li> | ||
<li className="orderSelect__optionListItem"> | ||
<button | ||
className="orderSelect__option" | ||
onClick={handleFavoriteClick} | ||
> | ||
좋아요순 | ||
</button> | ||
</li> | ||
<ul className="dropdown__optionList"> | ||
{children.map((child) => ( | ||
<li key={child.props.value} className="dropdown__optionListItem"> | ||
<button | ||
className="dropdown__option" | ||
type="button" | ||
onClick={handleOptionClick} | ||
value={child.props.value} | ||
> | ||
{child.props.children} | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
|
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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,51 @@ | ||
import { Link, NavLink } from "react-router-dom"; | ||
import { useMediaQuery } from "../../hooks/useMediaQuery.js"; | ||
import logo from "../../assets/logo_w153x3.png"; | ||
import logoText from "../../assets/logo_w81x3.png"; | ||
import profileImage from "../../assets/profile_image_w40x3.png"; | ||
import "./Header.css"; | ||
|
||
export default function Header() { | ||
const media = useMediaQuery(); | ||
|
||
const getLogo = (media) => { | ||
return media !== "MOBLE" ? logo : logoText; | ||
}; | ||
|
||
return ( | ||
<header className="header"> | ||
<Link to="/"> | ||
<img | ||
className="header__logo" | ||
src={getLogo(media)} | ||
alt="판다마켓 바로가기" | ||
/> | ||
</Link> | ||
<nav className="header__nav"> | ||
<ul className="header__navList"> | ||
<li> | ||
<NavLink | ||
className={({ isActive }) => | ||
isActive ? "header__navItem--active" : undefined | ||
} | ||
to="/boards" | ||
> | ||
자유게시판 | ||
</NavLink> | ||
</li> | ||
<li> | ||
<NavLink | ||
className={({ isActive }) => | ||
isActive ? "header__navItem--active" : undefined | ||
} | ||
to="/items" | ||
> | ||
중고마켓 | ||
</NavLink> | ||
</li> | ||
</ul> | ||
</nav> | ||
<img className="header__profile" src={profileImage} alt="프로필 사진" /> | ||
</header> | ||
); | ||
} |
This file contains 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,45 +1,10 @@ | ||
import { Link, Outlet, useLocation } from "react-router-dom"; | ||
|
||
import { useMediaQuery } from "../../hooks/useMediaQuery.js"; | ||
import logo from "../../assets/logo_w153x3.png"; | ||
import logoText from "../../assets/logo_w81x3.png"; | ||
import profileImage from "../../assets/profile_image_w40x3.png"; | ||
import "./Layout.css"; | ||
import { Outlet } from "react-router-dom"; | ||
import Header from "./Header.js"; | ||
|
||
export default function Layout() { | ||
const { pathname } = useLocation(); | ||
const media = useMediaQuery(); | ||
|
||
const getLogo = (media) => { | ||
return media !== "MOBLE" ? logo : logoText; | ||
}; | ||
|
||
const checkPath = (path) => { | ||
return pathname === path ? "header__navItem--active" : undefined; | ||
}; | ||
|
||
return ( | ||
<> | ||
<header className="header"> | ||
<Link to="/"> | ||
<img | ||
className="header__logo" | ||
src={getLogo(media)} | ||
alt="판다마켓 바로가기" | ||
/> | ||
</Link> | ||
<nav className="header__nav"> | ||
<ul className="header__navList"> | ||
<li className={checkPath("/boards")}> | ||
<Link to="/boards">자유게시판</Link> | ||
</li> | ||
<li className={checkPath("/items")}> | ||
<Link to="/items">중고마켓</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
<img className="header__profile" src={profileImage} alt="프로필 사진" /> | ||
</header> | ||
<Header /> | ||
<Outlet /> | ||
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. P3: |
||
</> | ||
); | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
P1:
Dropdown 컴포넌트 내부 state인 value가 바뀌었을 때 이를 onSelect 함수로 전달하는 것보다
handleOptionClick 함수에서 onSelect(value)로 전달하는게 더 좋을 것 같아요.