-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: siren 아이콘 추가 * feat: 숨김 관리 저장소 Map 타입 수정 * feat: 신고 후 피드 숨기기 기능 * feat: 숨김 취소 버튼 padding 으로 스타일 수정 * feat: 신고 완료 후 토스트 메시지 렌더링 * feat: 피드 숨기기 및 취소 기능 동기식 처리 * feat: 피드 숨기기 취소 API 동기식 처리 * feat: 숨김 처리 onMutate에서 처리 * feat: 신고하기 체크박스 체크되어 있지 않은 상태로 반영 * feat: 피드 신고 중 에러 발생 시 에러 토스트 메시지 표시 * feat: useReportCategories -> useReportForm * feat: 신고 양식 유효성 검사 모델에서 진행 * feat: 신고하기 양식 body 생성 함수 생성 * feat: 피드 신고 양식 타입 분리 * feat: 피드 신고 실패 시 기존 상태 유지, 성공 시 상태 제거 * feat: 피드 신고 실패 시, 기존 상태 복구 Closes #65
- Loading branch information
Showing
21 changed files
with
251 additions
and
76 deletions.
There are no files selected for viewing
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
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
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,25 +1,33 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { addHiddenFeed } from '@/entitites/feed'; | ||
import { axiosInstance } from '@/shared/axios'; | ||
|
||
interface ReportBody { | ||
category: string; | ||
content: string; | ||
isBlind: boolean; | ||
} | ||
import { FeedReportForm } from '../consts'; | ||
import { removeFeedReportForm, saveFeedReportForm } from '../store'; | ||
|
||
async function requestFeedReports(feedId: number, body: ReportBody) { | ||
async function requestFeedReports(feedId: number, body: FeedReportForm) { | ||
const { data } = await axiosInstance.post(`feeds/${feedId}/reports`, body); | ||
|
||
return data; | ||
} | ||
|
||
export const useSubmitReports = (feedId: number) => { | ||
const { mutateAsync: reportFeedAsync, isPending } = useMutation({ | ||
mutationFn: (body: ReportBody) => requestFeedReports(feedId, body), | ||
onError: () => {}, | ||
onSuccess: () => {}, | ||
const { mutate: reportFeed, isPending } = useMutation({ | ||
mutationKey: ['feed-report'], | ||
mutationFn: (body: FeedReportForm) => requestFeedReports(feedId, body), | ||
onError: (_, body) => saveFeedReportForm(feedId, body), | ||
onSuccess: (_, body) => { | ||
const { isBlind } = body; | ||
|
||
// 숨김 처리 | ||
if (isBlind) { | ||
addHiddenFeed(feedId, 'siren'); | ||
} | ||
|
||
removeFeedReportForm(feedId); | ||
}, | ||
}); | ||
|
||
return { reportFeedAsync, isPending }; | ||
return { reportFeed, isPending }; | ||
}; |
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 +1,2 @@ | ||
export * from './reports'; | ||
export * from './type'; |
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,5 @@ | ||
export interface FeedReportForm { | ||
category: string; | ||
content: string; | ||
isBlind: boolean; | ||
} |
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 +1 @@ | ||
export * from './useReportCategories'; | ||
export * from './useReportForm'; |
This file was deleted.
Oops, something went wrong.
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 { useState } from 'react'; | ||
|
||
import { useInput, useToggle } from '@/shared/hooks'; | ||
|
||
import { REPORT_CATEGORIES, UNCLICKED_STATUS_ID } from '../consts'; | ||
import { getFeedReportForm } from '../store/report-store'; | ||
|
||
export const useReportForm = (feedId: number) => { | ||
const { | ||
clickedId: prevClickedId, | ||
content: prevContent, | ||
isBlind: prevIsBlind, | ||
} = getFeedReportForm(feedId); | ||
|
||
const [clickedId, setClickedId] = useState<number>(prevClickedId); | ||
const [content, handleInputContent] = useInput(prevContent); | ||
const [isBlind, toggleBlind] = useToggle(prevIsBlind); | ||
|
||
const isValidReportForm = clickedId !== UNCLICKED_STATUS_ID; | ||
const isDisabledReportForm = !isValidReportForm; | ||
|
||
const handleClickCategory = (id: number) => setClickedId(id); | ||
const createReportBody = () => ({ | ||
category: REPORT_CATEGORIES[clickedId], | ||
content, | ||
isBlind, | ||
}); | ||
|
||
return { | ||
clickedId, | ||
content, | ||
isBlind, | ||
isDisabledReportForm, | ||
handleClickCategory, | ||
handleInputContent, | ||
toggleBlind, | ||
createReportBody, | ||
}; | ||
}; |
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 @@ | ||
export * from './report-store'; |
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,71 @@ | ||
import { create } from 'zustand'; | ||
import { devtools } from 'zustand/middleware'; | ||
|
||
import { FeedReportForm, REPORT_CATEGORIES } from '../consts'; | ||
|
||
interface FeedReportFailState { | ||
[feedId: number]: FeedReportForm; | ||
} | ||
|
||
/** | ||
* 피드 신고 실패시, 사용자가 작성한 정보에 대한 상태를 관리하는 스토어입니다. | ||
*/ | ||
export const useFeedReportFailStore = create<FeedReportFailState>()( | ||
devtools((): FeedReportFailState => ({}), { name: 'feed-report-store' }), | ||
); | ||
|
||
/** | ||
* 피드 신고 실패시, 사용자가 작성한 정보를 저장합니다. | ||
* @param feedId 피드 아이디 | ||
*/ | ||
export function saveFeedReportForm(feedId: number, body: FeedReportForm) { | ||
useFeedReportFailStore.setState( | ||
(prev) => ({ | ||
...prev, | ||
[feedId]: body, | ||
}), | ||
false, | ||
'feed/saveFeedReportForm', | ||
); | ||
} | ||
|
||
/** | ||
* 피드 신고 성공시, 사용자가 작성한 정보를 삭제합니다. | ||
* @param feedId 피드 아이디 | ||
*/ | ||
export function removeFeedReportForm(feedId: number) { | ||
if (!useFeedReportFailStore.getState()[feedId]) return; | ||
|
||
useFeedReportFailStore.setState( | ||
(prev) => { | ||
const nextState = { ...prev }; | ||
delete nextState[feedId]; | ||
return nextState; | ||
}, | ||
false, | ||
'feed/removeFeedReportForm', | ||
); | ||
} | ||
|
||
/** | ||
* 사용자가 이전에 작성한 피드 신고 정보를 가져옵니다. | ||
* @if 만약 없다면, 초기 상태를 반환합니다. | ||
* @param feedId 피드 아이디 | ||
* @returns 피드 신고 양식 | ||
*/ | ||
export function getFeedReportForm(feedId: number) { | ||
const body = useFeedReportFailStore.getState()[feedId]; | ||
|
||
if (!body) { | ||
return { | ||
clickedId: -1, | ||
content: '', | ||
isBlind: false, | ||
}; | ||
} | ||
|
||
return { | ||
clickedId: REPORT_CATEGORIES.indexOf(body.category), | ||
...body, | ||
}; | ||
} |
Oops, something went wrong.