From 9c4fc6ddcd9a45e0a3adfc940545c96e278405a4 Mon Sep 17 00:00:00 2001 From: NCanggoro Date: Thu, 28 Sep 2023 10:38:08 +0700 Subject: [PATCH] update page after submit review --- src/pages/LocationDetail/index.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/LocationDetail/index.tsx b/src/pages/LocationDetail/index.tsx index 9c15187..c67529f 100644 --- a/src/pages/LocationDetail/index.tsx +++ b/src/pages/LocationDetail/index.tsx @@ -31,6 +31,7 @@ function LocationDetail() { const [locationImages, setLocationImages] = useState(emptyLocationResponse()) const [currentUserReview, setCurrentUserReview] = useState() const [lightboxOpen, setLightboxOpen] = useState(false) + const[updatePage, setUpdatePage] = useState(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 { 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,8 +187,13 @@ function LocationDetail() { useEffect(() => { getCurrentUserLocationReview() - getLocationDetail() }, []) + + useEffect(() => { + if(updatePage) { + getLocationDetail() + } + }, [updatePage]) return ( <>