-
Notifications
You must be signed in to change notification settings - Fork 0
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(bingo) bingo 부분에 reactQuery 추가 #34
Open
mksoo
wants to merge
5
commits into
main
Choose a base branch
from
feature/react-query
base: main
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
5 commits
Select commit
Hold shift + click to select a range
11985fa
feat(common) react query 추가
mksoo 2884476
feat(bingo): mutation(데이터를 create/delete/update 하는) 관련 api 코드 약간 수정
mksoo e134e57
feat(bingo) hook 추가
mksoo abab1c3
feat(bingo) BingoContainer 코드 reactQuery 추가한걸로 수정
mksoo 5febd71
임시) API_URL 명시적으로 변경
mksoo 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
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,27 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { createBingoBoard } from "../../../api/bingo_api"; | ||
import QueryKeyGenerator from "../../common/QueryKeyGenerator"; | ||
|
||
export const useCreateBingoBoardMutation = async (sendUserId: string) => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationFn: (args: { | ||
userId: string, | ||
boardData: { | ||
[key: string]: { value: string; status: number; selected: number }; | ||
}, | ||
}) => { | ||
const { userId, boardData } = args; | ||
return createBingoBoard( | ||
{ | ||
userId, | ||
boardData, | ||
} | ||
); | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: QueryKeyGenerator.bingoBoard(sendUserId) }); | ||
queryClient.invalidateQueries({ queryKey: QueryKeyGenerator.userLatestInteraction(sendUserId) }); | ||
} | ||
}); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/hooks/bingo/mutations/useCreateUserBingoInteractionMutation.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,29 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { createUserBingoInteraction } from "../../../api/bingo_api"; | ||
import QueryKeyGenerator from "../../common/QueryKeyGenerator"; | ||
|
||
export const useCreateUserBingoInteractionMutation = async (sendUserId: string) => { | ||
const queryClient = useQueryClient(); | ||
// 새로운 interaction을 생성하는 mutation입니다. | ||
return useMutation({ | ||
mutationFn: (args: { | ||
word_id_list: string | null, | ||
send_user_id: number, | ||
receive_user_id: number | ||
}) => { | ||
const { word_id_list, send_user_id, receive_user_id } = args; | ||
return createUserBingoInteraction( | ||
{ | ||
word_id_list, | ||
send_user_id, | ||
receive_user_id | ||
} | ||
); | ||
}, | ||
onSuccess: () => { | ||
// 새로운 interaction이 생성되면, 해당 유저의 bingo board와 latest interaction을 업데이트합니다. | ||
queryClient.invalidateQueries({ queryKey: QueryKeyGenerator.bingoBoard(sendUserId) }); | ||
queryClient.invalidateQueries({ queryKey: QueryKeyGenerator.userLatestInteraction(sendUserId) }); | ||
} | ||
}); | ||
}; |
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,16 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import QueryKeyGenerator from "../common/QueryKeyGenerator"; | ||
import { getBingoBoard } from "../../api/bingo_api"; | ||
|
||
export const useBingoBoardByUserId = (userId: string) => { | ||
return useQuery({ | ||
queryKey: QueryKeyGenerator.bingoBoard(userId), // 쿼리 키를 통해서 쿼리들을 구분합니다. 나중에 쿼리키를 활용해서 해당 쿼리들을 reset 할 수 있습니다. | ||
queryFn: () => { // 쿼리 함수 | ||
const data = getBingoBoard(userId) | ||
if (!data) { | ||
throw new Error("Bingo board not found"); | ||
} | ||
return data; | ||
} | ||
}); | ||
} |
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,16 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import QueryKeyGenerator from "../common/QueryKeyGenerator"; | ||
import { getUserLatestInteraction } from "../../api/bingo_api"; | ||
|
||
export const useUserLatestInteractionByUserId = (userId: string) => { | ||
return useQuery({ | ||
queryKey: QueryKeyGenerator.userLatestInteraction(userId), | ||
queryFn: () => { | ||
const data = getUserLatestInteraction(userId) | ||
if (!data) { | ||
throw new Error("User latest interaction not found"); | ||
} | ||
return data; | ||
} | ||
}); | ||
} |
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 default { | ||
user: (username: string) => ['user', username], | ||
bingoBoard: (userId: string) => ['bingoBoard', userId], | ||
userLatestInteraction: (userId: string) => ['userLatestInteraction', userId], | ||
} |
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,16 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { getUser as getUserByUsername } from "../../api/bingo_api"; | ||
import QueryKeyGenerator from "../common/QueryKeyGenerator"; | ||
|
||
export const useUserByUsername = (username: string) => { | ||
return useQuery({ | ||
queryKey: QueryKeyGenerator.user(username), queryFn: () => { | ||
const data = getUserByUsername(username) | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export const useUserByUsername = async (username: string) => {
return useQuery({
queryKey: QueryKeyGenerator.user(username), queryFn: () => {
const data = await getUserByUsername(username) 와 같이 하면 정상적으로 데이터가 가져와집니다. |
||
if (!data) { | ||
throw new Error("User not found"); | ||
} | ||
return data; | ||
} | ||
}); | ||
}; |
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.
❓혹시 이부분 광수님 환경에서는 잘 호출되실까요? 동작 테스트 해보려고 하는데 수정된 부분이 호출되지 않는것 같아서요
temp_0722.mov
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.
아하 이 부분은 호출은 됐는데, 저 같은 경우는 CORS나 bingo backend api 부분에서 발생한 이슈 때문에 안되는 것 같더라구요! 저도 좀 더 살펴보고 말씀드릴게요!
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.
아!? 호출이 되는걸 확인하셨군요! 저도 잘못 설정한게 없는지 한번 더 확인해보겠습니다!
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.
네네! 감사합니당 저도 좀 더 봐볼게욥