-
Notifications
You must be signed in to change notification settings - Fork 5
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
Header 알림 기능 구현 (issue#45) #58
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a211692
chore: gitignore dist 추가
Parkhanyoung 2443dcb
feat: header 알림 아이콘 추가
Parkhanyoung ecee9ea
feat: 알림 모달 컨테이너 구현
Parkhanyoung 544a5f9
feat: 알림 확인 기능 추가
Parkhanyoung a3f9dae
refactor: Section Tag와의 혼동을 방지하기 위해 Left/RightSection 명을 Left/RightPa…
Parkhanyoung 1e3ee15
Merge branch 'main' of https://github.com/woowacourse-teams/2024-deve…
Parkhanyoung 99e67e4
chore: index.html 불필요한 태그 삭제
Parkhanyoung 4e097c4
chore: 불필요한 eslint 수정 사항 삭제
Parkhanyoung ee0d6ea
chore: 불필요한 스타일링 제거
Parkhanyoung 79f9bf8
refactor: NotiList 불필요한 div 삭제
Parkhanyoung 778c751
refactor: useKeyDown을 컴포넌트 형태로 수정
Parkhanyoung 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,3 +1,5 @@ | ||
node_modules | ||
.env | ||
.DS_Store | ||
.DS_Store | ||
dist | ||
settings.json |
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,11 +1,11 @@ | ||
<!doctype html> | ||
<html lang="ko"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>데벨업 프론트엔드</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>데벨업 프론트엔드</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,24 @@ | ||
import { useEffect } from 'react'; | ||
|
||
interface ListenKeyDownProps { | ||
targetKey: string; | ||
onKeyDown: () => void; | ||
} | ||
|
||
export default function ListenKeyDown({ targetKey, onKeyDown }: ListenKeyDownProps) { | ||
useEffect(() => { | ||
const handleKeyDown = (e: KeyboardEvent) => { | ||
if (e.key === targetKey) { | ||
onKeyDown(); | ||
} | ||
}; | ||
|
||
window.addEventListener('keydown', handleKeyDown); | ||
|
||
return () => { | ||
window.removeEventListener('keydown', handleKeyDown); | ||
}; | ||
}, []); | ||
Check warning on line 21 in frontend/src/components/common/ListenKeyDown.tsx GitHub Actions / build-and-test
|
||
|
||
return null; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as S from './NotiModal.styled'; | ||
import { NOTI_MOCKS } from './notiMocks'; | ||
|
||
export default function NotiList() { | ||
const handleRead = () => { | ||
alert('읽음'); | ||
}; | ||
|
||
// 알림 data를 일단 mock으로 처리 @라이언 | ||
const notifications = NOTI_MOCKS; | ||
|
||
const isEmpty = notifications.length === 0; | ||
|
||
return isEmpty ? ( | ||
<div>알림이 없습니다.</div> | ||
) : ( | ||
notifications.map(({ id, message }) => ( | ||
<S.NotiItem key={id}> | ||
{message} | ||
<S.NotiReadBtn onClick={handleRead}>✅</S.NotiReadBtn> | ||
</S.NotiItem> | ||
)) | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
frontend/src/components/header/notiModal/NotiModal.styled.ts
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,39 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const NotiModalContainer = styled.div` | ||
z-index: 101; | ||
position: fixed; | ||
top: 5.5rem; | ||
right: 17rem; | ||
width: 30rem; | ||
box-shadow: 0 0 8px rgba(0, 0, 0, 0.1); | ||
|
||
border-radius: 1rem; | ||
padding: 2rem; | ||
background-color: var(--grey-100); | ||
`; | ||
|
||
export const NotiItem = styled.div` | ||
position: relative; | ||
font-size: 1.1rem; | ||
margin-bottom: 1rem; | ||
padding: 1rem; | ||
border-radius: 1rem; | ||
background-color: white; | ||
box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.1); | ||
`; | ||
|
||
export const NotiTitle = styled.h2` | ||
font-size: 1.5rem; | ||
font-weight: 700; | ||
margin-bottom: 1.5rem; | ||
`; | ||
|
||
export const NotiReadBtn = styled.button` | ||
font-size: 1.5rem; | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
position: absolute; | ||
right: 0; | ||
bottom: 0; | ||
`; |
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,20 @@ | ||
import NotiList from './NotiList'; | ||
import * as S from './NotiModal.styled'; | ||
import ListenKeyDown from '@/components/common/ListenKeyDown'; | ||
import useClickOutside from '@/hooks/useClickOutside'; | ||
|
||
interface NotiModalProps { | ||
closeModal: () => void; | ||
} | ||
|
||
export default function NotiModal({ closeModal }: NotiModalProps) { | ||
const { targetRef } = useClickOutside<HTMLDivElement>(closeModal); | ||
|
||
return ( | ||
<S.NotiModalContainer ref={targetRef}> | ||
<ListenKeyDown targetKey="Escape" onKeyDown={closeModal} /> | ||
<S.NotiTitle>🔔 알림</S.NotiTitle> | ||
<NotiList /> | ||
</S.NotiModalContainer> | ||
); | ||
} |
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,18 @@ | ||
export interface Notification { | ||
id: number; | ||
message: string; | ||
isRead: boolean; | ||
} | ||
|
||
export const NOTI_MOCKS: Notification[] = [ | ||
{ | ||
id: 1, | ||
message: '버건디님과 페어 매칭이 완료되었습니다.', | ||
isRead: false, | ||
}, | ||
{ | ||
id: 2, | ||
message: '리브님으로부터 리뷰가 도착했습니다. 지금 미션 현황 페이지에서 확인해보세요.', | ||
isRead: false, | ||
}, | ||
]; |
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,31 @@ | ||
import { router } from '@/index'; | ||
import { useEffect, useRef } from 'react'; | ||
|
||
const useClickOutside = <T extends Node = HTMLElement>(callback: () => void) => { | ||
const ref = useRef<T>(null); | ||
|
||
useEffect(() => { | ||
const handleClickOutside = (event: MouseEvent) => { | ||
if (ref.current && !ref.current.contains(event.target as Node)) { | ||
callback(); | ||
} | ||
}; | ||
|
||
// 이벤트 버블링에 의해 모달이 렌더되는 즉시 callback이 호출되는 것을 방지하기 위해 setTimeout 사용 (추후 리팩토링 예정) @라이언 | ||
const timer = setTimeout(() => { | ||
document.addEventListener('click', handleClickOutside); | ||
}, 0); | ||
|
||
return () => { | ||
clearTimeout(timer); | ||
document.removeEventListener('click', handleClickOutside); | ||
}; | ||
}, [callback]); | ||
|
||
// react-router-dom Link 클릭 시 클릭 이벤트가 감지되지 않는 문제를 해결하기 위함 @라이언 | ||
router.subscribe(callback); | ||
|
||
return { targetRef: ref }; | ||
}; | ||
|
||
export default useClickOutside; |
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
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.
이놈의 라우터..