update page after submit review

This commit is contained in:
NCanggoro 2023-09-28 10:38:08 +07:00
parent 788610292e
commit 9c4fc6ddcd

View File

@ -31,6 +31,7 @@ function LocationDetail() {
const [locationImages, setLocationImages] = useState<LocationResponse>(emptyLocationResponse())
const [currentUserReview, setCurrentUserReview] = useState<CurrentUserLocationReviews>()
const [lightboxOpen, setLightboxOpen] = useState<boolean>(false)
const[updatePage, setUpdatePage] = useState<boolean>(true)
const [pageState, setPageState] = useState({
critic_filter_name: 'highest rated',
critic_filter_type: 0,
@ -74,13 +75,14 @@ function LocationDetail() {
const res = await getImagesByLocationService({ page: 1, page_size: 15, location_id: Number(id) })
res.data.images.push({ src: thumbnail })
setLocationImages(res.data)
setUpdatePage(false)
} catch (error) {
console.log(error)
}
setIsLoading(false)
}
async function getCurrentUserLocationReview() {
async function getCurrentUserLocationReview(): Promise<void> {
try {
const res = await getCurrentUserLocationReviewService(Number(id))
setCurrentUserReview(res.data)
@ -165,6 +167,7 @@ function LocationDetail() {
created_at: data.created_at,
updated_at: data.updated_at
})
setUpdatePage(true)
} catch (error) {
let err = error as AxiosError;
console.log(err)
@ -184,9 +187,14 @@ function LocationDetail() {
useEffect(() => {
getCurrentUserLocationReview()
getLocationDetail()
}, [])
useEffect(() => {
if(updatePage) {
getLocationDetail()
}
}, [updatePage])
return (
<>
<div className={'content main-content mt-3'}>