import { useLocation, useParams } from 'react-router-dom'; import { ChangeEvent, TargetedEvent } from 'preact/compat'; import { useEffect, useRef, useState } from 'preact/hooks'; import './index.css'; import Lightbox from 'yet-another-react-lightbox'; import useCallbackState from '../../types/state-callback'; import { EmptyLocationDetailResponse, LocationDetailResponse, LocationResponse, emptyLocationResponse } from './types'; import { useAutosizeTextArea } from '../../utils'; import { getImagesByLocationService, getLocationService } from "../../services"; import { DefaultSeparator, SeparatorWithAnchor } from '../../components'; function LocationDetail() { const [locationDetail, setLocationDetail] = useCallbackState(EmptyLocationDetailResponse) const [locationImages, setLocationImages] = useState(emptyLocationResponse()) const [lightboxOpen, setLightboxOpen] = useState(false) const [pageState, setPageState] = useState({ critic_filter_name: 'highest rated', critic_filter_type: 0, show_sort: false }) const [reviewValue, setReviewValue] = useState({ review_textArea: '', score_input: '', }) const [isLoading, setIsLoading] = useState(true) const textAreaRef = useRef(null); useAutosizeTextArea(textAreaRef.current, reviewValue.review_textArea); const { state } = useLocation(); const { id } = useParams() const SORT_TYPE = [ 'highest rated', 'lowest rated', 'newest', 'oldest' ] async function getLocationDetail(): Promise { try { const res = await getLocationService(Number(id)) setLocationDetail(res.data, (val) => { getImage(val.detail.thumbnail.String.toString()) }) } catch (err) { console.log(err) } } async function getImage(thumbnail?: String): Promise { try { const res = await getImagesByLocationService({ page: 1, page_size: 15, location_id: Number(id) }) res.data.images.push({ src: thumbnail }) setLocationImages(res.data) } catch (error) { console.log(error) } setIsLoading(false) } function handleTextAreaChange(e: ChangeEvent): void { const val = e.target as HTMLTextAreaElement; setReviewValue({ ...reviewValue, review_textArea: val.value }) } function handleScoreInputChange(e: ChangeEvent): void { const val = e.target as HTMLInputElement; setReviewValue({ ...reviewValue, score_input: val.value }) } function onChangeCriticsSort(e: TargetedEvent, sort_name: string, sort_type: number): void { e.preventDefault() setPageState({ show_sort: false, critic_filter_name: sort_name, critic_filter_type: sort_type }) } useEffect(() => { getLocationDetail() }, []) return ( <>

{locationDetail?.detail.name}

{isLoading ?
: }
CRITICS SCORE
{state.critic_count !== 0 ? state.critic_score : "NR"}
{state.critic_count !== 0 &&
Based on {state.critic_count} reviews
}
USERS SCORE
{state.user_count !== 0 ? state.user_score : "NR"}
{state.user_count !== 0 &&
Based on {state.user_count} reviews
}
address: {locationDetail.detail.address} {locationDetail.detail.regency_name}
average cost: IDR 25.0000
Tags:
{locationDetail.tags.map(x => (
{x}
)) }
{/*
SIGN IN TO REVIEW
*/}
/ score