-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Feat/#47] 누락된 아이콘 활성화 로직 반영 #48
Closed
Closed
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,35 @@ | ||
import { useState } from "react"; | ||
import { useLocation, useNavigate } from "react-router-dom"; | ||
import { useNavigate, useLocation } from "react-router-dom"; | ||
import * as styles from "./Nav.css"; | ||
import { NAV_CONTENT } from "./constant"; | ||
|
||
const Nav = () => { | ||
const location = useLocation(); | ||
|
||
const extractFirstPath = (): string => { | ||
const pathName = location.pathname; | ||
const parts = pathName.split("/"); | ||
const basePath = `/${parts[1]}`; | ||
|
||
return basePath; | ||
}; | ||
|
||
const [activeItem, setActiveItem] = useState<string>(extractFirstPath()); | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
||
const handleClick = (itemId: string, path: string) => { | ||
setActiveItem(itemId); | ||
if (itemId !== "/review") { | ||
navigate(path); | ||
} else { | ||
// 버튼 클릭시 활성화 및 페이지 이동 | ||
const handleClick = (path: string) => { | ||
if (path === "/review") { | ||
alert("추후 구현 예정입니다."); | ||
} else { | ||
navigate(path); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
{NAV_CONTENT.map((item) => { | ||
const SvgComponent = item.svg; | ||
|
||
return ( | ||
<button | ||
key={item.id} | ||
type="button" | ||
onClick={() => handleClick(item.id, item.path)} | ||
className={styles.navItem({ | ||
state: activeItem === item.id, | ||
})} | ||
> | ||
<SvgComponent /> | ||
{item.label} | ||
</button> | ||
); | ||
})} | ||
{NAV_CONTENT.map(({ id, path, svg: SvgComponent, label }) => ( | ||
<button | ||
key={id} | ||
type="button" | ||
onClick={() => handleClick(path)} | ||
className={styles.navItem({ | ||
state: location.pathname === path, | ||
})} | ||
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) 만약 위에서 언급한 extractFirstPath 를 살린다면 extractFirstPath() === path 같은 방식으로 아이콘 활성화 여부를 결정하면 좋을 것 같습니다 ~ (아니면 extractFirstPath를 리팩토링해서 인자를 받는 형식으로 한다면, extractFirstPath(location.pathname) === path 으로 활성화 여부를 결정해도 좋을 것 같아요!) |
||
> | ||
<SvgComponent /> | ||
{label} | ||
</button> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import Nav from "@common/component/Nav/Nav"; | ||
|
||
const Mypage = () => { | ||
return <Nav />; | ||
return <></>; | ||
}; | ||
|
||
export default Mypage; |
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.
p3) 이거는 살려두면 어떨까요? 나중에 location 이 만약 /main이 아니라 /main/어쩌구 등등 뒤에 붙는 형식이 되면 pathName이 일치하지 않는다고 인식되어 아이콘이 활성화가 되지 않을 수도 있을 것 같아서요!
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.
아! 확장성 면에서 기존 로직이 좋은거 같아서 해당 브랜치 폭파 완료했습니다 :)