Added users rating in announcement details

This commit is contained in:
2023-08-07 14:08:51 +03:00
parent b93ab9794d
commit d2a3393a11
11 changed files with 231 additions and 5 deletions

View File

@@ -9,3 +9,5 @@ export { default as useSignIn } from './useSignIn'
export { default as useSignUp } from './useSignUp'
export { default as usePoetry } from './usePoetry'
export { default as useDispose } from './useDispose'
export { default as useSendRate } from './useSendRate'
export { default as useUserRating } from './useUserRating'

View File

@@ -0,0 +1,33 @@
import { useSend } from '..'
import { composeSendRateURL, processSendRate } from '../../api/sendRate'
import { isSendRateResponse } from '../../api/sendRate/types'
function useSendRate() {
const { doSend, ...rest } = useSend(
composeSendRateURL(),
'POST',
true,
isSendRateResponse,
processSendRate,
)
const doSendRate = (rate: number) => (
doSend({}, {
body: JSON.stringify({
rate,
}),
headers: {
'Content-Type': 'application/json',
},
})
)
return {
doSendRate,
...rest,
}
}
export default useSendRate

View File

@@ -0,0 +1,30 @@
import { composeUserRatingURL, initialUserRating, processUserRating } from '../../api/userRating'
import { UserRating, isUserRatingResponse } from '../../api/userRating/types'
import useFetch, { UseFetchReturn } from '../useFetch'
const useUserRating = (userId: number): UseFetchReturn<UserRating> => (
// useFetch(
// composeUserRatingURL(userId),
// 'GET',
// false,
// isUserRatingResponse,
// processUserRating,
// initialUserRating
// )
{
data: 3,
loading: false,
error: null,
refetch: () => { return },
}
// {
// data: undefined,
// loading: true,
// error: null,
// refetch: () => { return },
// }
)
export default useUserRating