-
Notifications
You must be signed in to change notification settings - Fork 4
[Feature/Notifications] 알림 기능 구현 #66
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
kyubumjang
wants to merge
9
commits into
develop
Choose a base branch
from
feature/notifications
base: develop
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4397a6f
Squashed commit of the following:
kyubumjang 95b335b
feat(NotificationsPage): 알림 페이지 UI 구성
kyubumjang f899b81
feat(Notifications): 알림 API 연동
kyubumjang 0ed06c2
feat(Notifications): 라우팅 추가
kyubumjang d4c4574
feat(Badge): Badge 추가
kyubumjang 2a9d123
feat(Skeleton): Notification 스켈레톤 추가
kyubumjang 7c4bc57
feat(Notificaiton): API 연동 및 기능 구현
kyubumjang f08525b
Squashed commit of the following:
kyubumjang 360e845
Merge branch 'develop' into feature/notifications
kyubumjang 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
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
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,67 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| const BadgeContainer = styled.div` | ||
| position: relative; | ||
| display: inline-block; | ||
| `; | ||
|
|
||
| const Super = styled.sup` | ||
| position: absolute; | ||
| top: 0; | ||
| right: 0; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| height: 20px; | ||
| padding: 0 8px; | ||
| font-size: 12px; | ||
| border-radius: 20px; | ||
| color: white; | ||
| border-radius: 20px; | ||
| background-color: #f44; | ||
| transform: translate(50%, -50%); | ||
|
|
||
| &.dot { | ||
| padding: 0; | ||
| width: 4px; | ||
| height: 4px; | ||
| border-radius: 50%; | ||
| } | ||
| `; | ||
|
|
||
| const Badge = ({ | ||
| children, | ||
| count, | ||
| maxCount, | ||
| showZero, | ||
| dot = false, | ||
| backgroundColor, | ||
| textColor, | ||
| ...props | ||
| }) => { | ||
| const colorStyle = { | ||
| backgroundColor, | ||
| color: textColor, | ||
| }; | ||
| let badge = null; | ||
| if (count) { | ||
| badge = ( | ||
| <Super style={colorStyle}> | ||
| {maxCount && count > maxCount ? `${maxCount}+ ` : count} | ||
| </Super> | ||
| ); | ||
| } else { | ||
| if (count !== undefined) { | ||
| badge = showZero ? <Super style={colorStyle}>0</Super> : null; | ||
| } else if (dot) { | ||
| badge = <Super className='dot' style={colorStyle} />; | ||
| } | ||
| } | ||
| return ( | ||
| <BadgeContainer {...props}> | ||
| {children} | ||
| {badge} | ||
| </BadgeContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export default Badge; |
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,21 @@ | ||
| import styled from 'styled-components'; | ||
| import Circle from './Circle'; | ||
| import Paragraph from './Paragraph'; | ||
|
|
||
| const Notification = () => { | ||
| return ( | ||
| <Wrapper> | ||
| <Circle size={60}></Circle> | ||
| <Paragraph line={3} style={{ width: '300px' }}></Paragraph> | ||
| </Wrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default Notification; | ||
|
|
||
| const Wrapper = styled.div` | ||
| display: flex; | ||
| flex-direction: row; | ||
| gap: 0.5em; | ||
| margin: 0.5em 0 0.5em 0; | ||
| `; |
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,11 +1,12 @@ | ||
| import Box from './Box'; | ||
| import Circle from './Circle'; | ||
| import Paragraph from './Paragraph'; | ||
|
|
||
| import Notification from './Notification'; | ||
| const Skeleton = { | ||
| Box, | ||
| Circle, | ||
| Paragraph, | ||
| Notification, | ||
| }; | ||
|
|
||
| export default Skeleton; |
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
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,101 @@ | ||
| import styled from 'styled-components'; | ||
| import { StyledLink, Avatar, Text } from '@/components/atoms'; | ||
| import { putNotificationsSeen } from '@/api/Api.js'; | ||
|
|
||
| const Notification = ({ notification, posts }) => { | ||
| const notificationPost = posts.filter( | ||
| (post) => post._id === notification.post, | ||
| )[0]; | ||
| const title = JSON.parse(notificationPost.title).postTitle; | ||
| const handleClick = async () => { | ||
| await putNotificationsSeen(); | ||
| }; | ||
|
|
||
| if (notification.seen === false) { | ||
| return ( | ||
| <Wrapper onClick={handleClick}> | ||
| <StyledLink to={`/controversy/result/${notification.post}`}> | ||
| <NotificationWrapper> | ||
| <AvatarWrapper> | ||
| <Avatar src={notification.author.image} size={60} /> | ||
| </AvatarWrapper> | ||
| <ColWrapper> | ||
| <TextWrapper> | ||
| <Text color='#000'> | ||
| {notification.comment | ||
| ? notification.author.username + | ||
| ' 님이 ' + | ||
| title + | ||
| '에 댓글을 남겼습니다!' | ||
| : ''} | ||
| {notification.like | ||
| ? notification.author.username + | ||
| ' 님이 ' + | ||
| title + | ||
| '에 좋아요를 눌렀습니다!' | ||
| : ''} | ||
| </Text> | ||
| </TextWrapper> | ||
| <TextWrapper> | ||
| <Text color='#000' strong> | ||
| {notification.comment | ||
| ? JSON.parse(notification.comment.comment).content | ||
| : ''} | ||
| </Text> | ||
| </TextWrapper> | ||
| <TextWrapper> | ||
| <Text color='#2f66d2'> | ||
| {notification.updatedAt.split('T')[0]}일 | ||
| {' ' + | ||
| new Date(Date.parse(notification.updatedAt) + 3240 * 10000) | ||
| .toISOString() | ||
| .split('T')[1] | ||
| .slice(0, 5)} | ||
| 분에 업데이트 되었습니다. | ||
| </Text> | ||
| </TextWrapper> | ||
| </ColWrapper> | ||
| </NotificationWrapper> | ||
| </StyledLink> | ||
| </Wrapper> | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| export default Notification; | ||
|
|
||
| const Wrapper = styled.div` | ||
| display: flex; | ||
| align-items: center; | ||
| padding: 1rem; | ||
| box-shadow: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px; | ||
| border-radius: 4px; | ||
| &:hover { | ||
| background-color: #eee; | ||
| } | ||
| `; | ||
|
|
||
| const NotificationWrapper = styled.div` | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| const AvatarWrapper = styled.div` | ||
| display: flex; | ||
| `; | ||
|
|
||
| const ColWrapper = styled.div` | ||
| display: flex; | ||
| justify-content: center; | ||
| flex-direction: column; | ||
| margin-left: 1rem; | ||
| `; | ||
|
|
||
| const TextWrapper = styled.div` | ||
| display: flex; | ||
| align-items: center; | ||
|
|
||
| word-break: keep-all; | ||
| line-height: 1.5em; | ||
| `; |
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
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
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
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.
이 부분에서 단순히 사용자가 받은 알림의 길이에 따라 뱃지를 보여줄지 말지를 결정하고 있는 것 같은데, 사용자 입장에서 받은 알림이 있지만 알림을 읽었을 때에도 뱃지가 떠 있는 건 UX 측면에서는 좋지 않은 것 같습니다! 해당 부분을 알림 배열의
seen이false인 값이 있을 때에만 뱃지를 출력하는 건 어떨까요?