-
Notifications
You must be signed in to change notification settings - Fork 0
신고하기 구현 및 토스트 구현 (issue #254, issue #253, issue #236) #260
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
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
148b0b1
feat : 실시간 알림 데이터를 위한 Toast 띄우기
layout-SY 90a8c62
Merge branch 'develop' of https://github.com/devpalsPlus/frontend int…
layout-SY bab50a1
Merge branch 'develop' of https://github.com/devpalsPlus/frontend int…
layout-SY 3572213
style : 공고 상세 페이지 댓글 부분 하단에 여유 공간 추가
layout-SY 3c34e1e
feat : 신고하기 구현(API 미적용)
layout-SY 9abf6c2
fix : content 길이가 문단을 넘어가면 들여쓰기가 적용되지 않는 문제 해결
layout-SY 645108b
feat : 댓글이 없을 경우 추가
layout-SY b3a79c1
feat : 유저, 댓글/대댓글 등에 따른 신고 인터페이스 변경
layout-SY 0ad9c87
feat : 신고 후 모달 닫기
layout-SY 02db193
feat : 헤더의 알림 조회 스크롤 추가
layout-SY c5727fa
feat : 토스트 구현
layout-SY 80f0aae
fix : 빌드 에러 수정
layout-SY 1d18d2f
refactor : 타입 정리
layout-SY ee8e78e
refactor : 코드 리뷰 사항 적용
layout-SY 962152c
refactor : 파일 위치 변경
layout-SY bb0f4c2
feat : 실시간 알림 타입 토스트에 적용 및 토스트 알림에 route 추가
layout-SY 2310dc8
feat : 헤더 전체 알림에 route 추가
layout-SY 33e2a95
feat : 실시간 알림 타입 생성
layout-SY 51065f6
refactor : 코드 리뷰 수정 사항 반영
layout-SY a9b6503
refactor : 형준님 리뷰 사항 반영
layout-SY aafb853
feat : 현재 시간과 비교하여 알림 지난 시간 표시
layout-SY eb35eac
refactor : 토스트 테스트 버튼 삭제
layout-SY 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
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,15 @@ | ||
| import { ApiPostContent } from '../models/report'; | ||
| import { httpClient } from './http.api'; | ||
|
|
||
| export const postReport = async (formData: ApiPostContent) => { | ||
| try { | ||
| const response = await httpClient.post(`/report`, formData); | ||
| if (response.status !== 200) { | ||
| throw new Error(`${response.status}`); | ||
| } | ||
| return response.status; | ||
| } catch (error) { | ||
| console.error(error); | ||
| throw error; | ||
| } | ||
| }; |
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 |
|---|---|---|
|
|
@@ -18,19 +18,33 @@ const CommentLayout = ({ | |
| const { getCommentList, isLoading, isFetching, isError } = | ||
| useGetComment(projectId); | ||
|
|
||
| if (!getCommentList) { | ||
| return ( | ||
| <S.Container> | ||
| <S.CommentCountsContainer> | ||
| <S.Count>댓글 없음</S.Count> | ||
| </S.CommentCountsContainer> | ||
| </S.Container> | ||
| ); | ||
| } | ||
|
|
||
| if (isLoading || isFetching) { | ||
| return <LoadingSpinner />; | ||
| } | ||
|
|
||
| if (isError) { | ||
| console.error(isError); | ||
| return '댓글을 불러오는 중 오류가 발생했습니다. 다시 시도해 주세요.'; | ||
| return ( | ||
| <S.ErrorMessage> | ||
| 댓글을 불러오는 중 오류가 발생했습니다. 다시 시도해 주세요. | ||
|
||
| </S.ErrorMessage> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <S.Container> | ||
| <S.CommentCountsContainer> | ||
| <S.Count>댓글 {getCommentList?.length || 0}개</S.Count> | ||
| <S.Count>댓글 {getCommentList.length}개</S.Count> | ||
| </S.CommentCountsContainer> | ||
|
|
||
| <S.CommentInput> | ||
|
|
||
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
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,34 @@ | ||
| import styled, { keyframes } from 'styled-components'; | ||
|
|
||
| const fadeInUp = keyframes` | ||
| from { opacity: 0; transform: translateY(20px); } | ||
| to { opacity: 1; transform: translateY(0); } | ||
| `; | ||
| const fadeOut = keyframes` | ||
| from { opacity: 1; } | ||
| to { opacity: 0; } | ||
| `; | ||
|
|
||
| export const Container = styled.div` | ||
| position: fixed; | ||
| width: 330px; | ||
| bottom: 30px; | ||
| right: 30px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
| z-index: 1000; | ||
| `; | ||
|
|
||
| export const Item = styled.div<{ $exiting: boolean }>` | ||
| background-color: rgba(50, 50, 50, 0.9); | ||
| color: ${({ theme }) => theme.color.white}; | ||
| padding: 12px 20px; | ||
| border-radius: 8px; | ||
| font-size: 0.95rem; | ||
| white-space: nowrap; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| animation: ${fadeInUp} 0.3s ease-out, | ||
| ${({ $exiting }) => $exiting && fadeOut} 0.3s ease-in forwards; | ||
| `; |
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,26 @@ | ||
| import { createPortal } from 'react-dom'; | ||
| import { ToastMessage } from './ToastContext'; | ||
| import ToastItem from './ToastItem'; | ||
| import * as S from './Toast.styled'; | ||
|
|
||
| interface ToastContainerProps { | ||
| toasts: ToastMessage[]; | ||
| onRemove: (id: string) => void; | ||
| } | ||
|
|
||
| const ToastContainer = ({ toasts, onRemove }: ToastContainerProps) => { | ||
| return createPortal( | ||
| <S.Container> | ||
| {toasts.map((toast) => ( | ||
| <ToastItem | ||
| key={toast.id} | ||
| {...toast} | ||
| onDone={() => onRemove(toast.id)} | ||
| /> | ||
| ))} | ||
| </S.Container>, | ||
| document.body | ||
| ); | ||
| }; | ||
|
|
||
| export default ToastContainer; |
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,17 @@ | ||
| import { createContext } from 'react'; | ||
|
|
||
| export interface ToastMessage { | ||
| id: string; | ||
| content: string; | ||
| duration: number; | ||
| } | ||
|
|
||
| export interface ToastContextProps { | ||
| addToast: (content: string, duration?: number) => void; | ||
| removeToast: (id: string) => void; | ||
| } | ||
|
|
||
| export const ToastContext = createContext<ToastContextProps>({ | ||
| addToast: () => {}, | ||
| removeToast: () => {}, | ||
| }); |
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,30 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import * as S from './Toast.styled'; | ||
|
|
||
| interface ToastItemProps { | ||
| id: string; | ||
| content: string; | ||
| duration: number; | ||
| onDone: () => void; | ||
| } | ||
|
|
||
| const ToastItem = ({ content, duration, onDone }: ToastItemProps) => { | ||
| const [exiting, setExiting] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| const timer = setTimeout(() => setExiting(true), duration); | ||
| return () => clearTimeout(timer); | ||
| }, [duration]); | ||
|
|
||
| const handleAnimationEnd = () => { | ||
| if (exiting) onDone(); | ||
| }; | ||
|
|
||
| return ( | ||
| <S.Item $exiting={exiting} onAnimationEnd={handleAnimationEnd}> | ||
| {content} | ||
| </S.Item> | ||
| ); | ||
| }; | ||
|
|
||
| export default ToastItem; |
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,30 @@ | ||
| import { PropsWithChildren, useCallback, useEffect, useState } from 'react'; | ||
| import { ToastContext, ToastMessage } from './ToastContext'; | ||
| import ToastContainer from './ToastContainer'; | ||
|
|
||
| export const ToastProvider = ({ children }: PropsWithChildren) => { | ||
| const [toasts, setToasts] = useState<ToastMessage[]>([]); | ||
|
|
||
| const addToast = useCallback((content: string, duration = 4000) => { | ||
| const id = Date.now().toString() + Math.random(); | ||
| setToasts((prev) => [...prev, { id, content, duration }]); | ||
| }, []); | ||
|
|
||
| const removeToast = useCallback((id: string) => { | ||
| setToasts((prev) => prev.filter((t) => t.id !== id)); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (toasts.length >= 4) { | ||
| const oldestId = toasts[0].id; | ||
| removeToast(oldestId); | ||
| } | ||
| }, [toasts, removeToast]); | ||
|
|
||
| return ( | ||
| <ToastContext.Provider value={{ addToast, removeToast }}> | ||
| {children} | ||
| <ToastContainer toasts={toasts} onRemove={removeToast} /> | ||
| </ToastContext.Provider> | ||
| ); | ||
| }; |
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,28 @@ | ||
| import styled from 'styled-components'; | ||
| import { useToast } from '../../../hooks/useToast'; | ||
|
|
||
| const TestButton = styled.button` | ||
| margin-left: 16px; | ||
| padding: 8px 12px; | ||
| background-color: ${({ theme }) => theme.color.primary}; | ||
| color: #fff; | ||
| border: none; | ||
| border-radius: 4px; | ||
| font-size: 0.9rem; | ||
| cursor: pointer; | ||
| &:hover { | ||
| opacity: 0.9; | ||
| } | ||
| `; | ||
|
|
||
| const ToastTestButton = () => { | ||
| const { showToast } = useToast(); | ||
|
|
||
| const handleClick = () => { | ||
| showToast('🛎️ 이건 테스트 토스트 메시지입니다!', 4000); | ||
| }; | ||
|
|
||
| return <TestButton onClick={handleClick}>토스트 확인</TestButton>; | ||
| }; | ||
|
|
||
| export default ToastTestButton; |
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.
🛠️ Refactor suggestion
새 함수
testLiveAlarm의 목적을 명확히 해주세요이 함수의 목적이 테스트인지 실제 기능인지가 명확하지 않습니다. 함수명이 "test"로 시작하는 것은 테스트 코드임을 암시하지만, 실제 기능으로 사용될 예정이라면 더 적절한 이름이 필요합니다.
또한 다른 함수들과 에러 처리 방식이 일관되지 않습니다:
getAlarmList는 에러를 다시 throw하지만 이 함수는 에러를 로깅만 합니다console.log를 사용합니다export const testLiveAlarm = async () => { try { const response = await httpClient.get<ApiAlarmList>( `/user/send-alarm?alarmFilter=0` ); return response; } catch (e) { - console.log(e); + console.error('라이브 알람 요청 에러:', e); + throw e; } };📝 Committable suggestion