Skip to content

Commit

Permalink
Merge pull request #80 from BacPacNet/userprofile
Browse files Browse the repository at this point in the history
fix hook
  • Loading branch information
bacpactech authored Aug 6, 2024
2 parents bda98d6 + 474a8d0 commit 3bfbbf4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/services/community-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ export const useUpdateUserPost = () => {
export function useGetUserPosts() {
const [cookieValue] = useCookie('uni_user_token')

const { isLoading, data, error } = useQuery({
const state = useQuery({
queryKey: ['userPosts'],
queryFn: () => getAllUserPosts(cookieValue),
})

let errorMessage = null
if (axios.isAxiosError(error) && error.response) {
errorMessage = error.response.data
if (axios.isAxiosError(state.error) && state.error.response) {
errorMessage = state.error.response.data
}

return { isLoading, data, error: errorMessage }
return { ...state, error: errorMessage }
}

export const useCreateUserPost = () => {
Expand All @@ -152,17 +152,17 @@ export const useCreateUserPost = () => {
export function useGetTimelinePosts() {
const [cookieValue] = useCookie('uni_user_token')

const { isLoading, data, error } = useQuery({
const state = useQuery({
queryKey: ['timelinePosts'],
queryFn: () => getAllTimelinePosts(cookieValue),
})

let errorMessage = null
if (axios.isAxiosError(error) && error.response) {
errorMessage = error.response.data
if (axios.isAxiosError(state.error) && state.error.response) {
errorMessage = state.error.response.data
}

return { isLoading, data, error: errorMessage }
return { ...state, error: errorMessage }
}

export const useLikeUnlikeTimelinePost = () => {
Expand Down

0 comments on commit 3bfbbf4

Please sign in to comment.