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