-
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: 리워드 내역 페이지 UI 구현 #214
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1e6c1c
🔥 remove: 불필요한 파일 제거
KKYHH ce6dff5
♻️ refactor: JSX를 사용하지 않는 파일 확장자명 변경
KKYHH e0cc990
✨ feat: 리워드 페이지 구현
KKYHH 555b9c4
Merge remote-tracking branch 'upstream/dev' into feat/RewardPage
KKYHH d60e4e9
✨ feat: 자동 임시 저장
KKYHH 96253b4
♻️ refactor: 월별 리워드 내역 수정
KKYHH b4df613
💄 design: 리워드 페이지 모바일 UI
KKYHH 89b4843
♻️ refactor: 코드 오타 수정
KKYHH 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { END_POINT } from '@constants/api'; | ||
import { CONSOLE_ERROR } from '@constants/message'; | ||
import API from '@services/index'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useUser } from '@state/user/useUser'; | ||
import { AxiosError } from 'axios'; | ||
|
||
export const useRewardHistory = () => { | ||
const memberId = useUser(); | ||
|
||
const fetchUseRewardHistory = async (): Promise<RewardHistory[]> => { | ||
const res = await API.get(END_POINT.reward_history(memberId)); | ||
return res.data; | ||
}; | ||
|
||
const { | ||
data: history, | ||
isError, | ||
error, | ||
} = useQuery< | ||
RewardHistory[], | ||
AxiosError, | ||
RewardHistory[], | ||
[string, number | undefined] | ||
>({ | ||
queryKey: ['rewardHistory', memberId], | ||
queryFn: fetchUseRewardHistory, | ||
enabled: !!memberId, | ||
}); | ||
|
||
if (isError) console.error(CONSOLE_ERROR.reward.get + error.message); | ||
|
||
return { history }; | ||
}; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
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.
요 slice()는 혹시 어떤 목적인가요!? 범위 설정이 따로 없어서 궁금하네용
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.
리워드 내역 데이터를
map
으로 뿌려주는데 마지막에 들어가는 데이터가 아래로 쌓여서 최신순으로 보여주기 위해reverse()
를 사용해 배열을 뒤집었습니다!그런데
reverse()
는 원본 배열을 변형시키는 파괴적 메서드라고 해서 비파괴 구조인slice()
를 사용해서 배열을 복사했습니다!slice()
안에 인자 없이 사용하면 단순히 배열을 복사 해준다고 합니다.어차피 뒤집힌 데이터를 보여줄 거라 복사를 안 하고 사용해도 문제는 없을 거 같은데 🤔 원본 데이터가 유지된 채 사용하는 게 혹시 모를 에러를 방지하지 않을까 했습니다.
스프레드 연산자랑 같은 역할을 합니다
[...group.records].reverse()
Javascript - 비파괴적 / 파괴적 메서드
파괴적 처리와 비파괴적 처리(destructive and non-destructive)
[javascript] 배열 원소 뒤집기 reverse()
[혼공] 혼자 공부하는 자바스크립트
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.
오호!!! 단순 복사를 위해서였구나 reverse()도 원본 배열 변형시키는 거였군요 ㅎㅎ 감사합니다 😊