-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle project comments fetching and posting
- Added `useCommentsQuery` hook to fetch project's questions and comments, updating the implementation to match the states from the new hook. - Replaced the existing implementation for posting comments with the `useMutation` hook, eliminating the use of the `useAsync` hook. - Implemented UI components to display loading and error network states for questions and comments. - Renamed the function from updateComments to refetchComments for clarity and consistency.
- Loading branch information
1 parent
fe2353c
commit 67705db
Showing
4 changed files
with
83 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import api from './apiClient'; | ||
|
||
export const useCommentsQuery = (projectId, page) => { | ||
const token = useSelector((state) => state.auth.token); | ||
const locale = useSelector((state) => state.preferences['locale']); | ||
|
||
const getComments = ({ signal }) => { | ||
return api(token, locale).get(`projects/${projectId}/comments/`, { | ||
signal, | ||
params: { | ||
perPage: 5, | ||
page, | ||
}, | ||
}); | ||
}; | ||
|
||
return useQuery({ | ||
queryKey: ['questions-and-comments', projectId, page], | ||
queryFn: getComments, | ||
select: (data) => data.data, | ||
}); | ||
}; | ||
|
||
export const postComment = (projectId, comment, token, locale = 'en') => { | ||
return api(token, locale).post(`projects/${projectId}/comments/`, { message: comment }); | ||
}; |
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