import { TargetedEvent } from "preact/compat"; import { useEffect, useState } from "preact/hooks"; import { getListTopLocationsService } from "../../services"; import { DefaultSeparator } from "../../components"; import './style.css'; import { useClick, useFloating, useInteractions } from "@floating-ui/react"; import { Link } from "react-router-dom"; interface TopLocation { row_number: Number, id: Number, name: String, thumbnail: string | null, address: String, google_maps_link: string, regency_name: string, critic_score: Number, critic_count: Number, user_score: Number, user_count: Number, critic_bayes: Number, user_bayes: Number, avg_bayes: Number, } const REGIONS = [ 'All', 'Sumatera', 'Jawa', 'Kalimantan', 'Nusa Tenggara', 'Maluku', 'Papua', 'Sulawesi', ]; const REVIEWERS_TYPE = [ 'All', 'Critics', 'Users' ] const MIN_REVIEWS = [ 2, 5, 7, 11 ] function BestLocation() { const [page, _setPage] = useState(1); const [topLocations, setTopLocations] = useState>([]) const [pageState, setPageState] = useState({ filterScoreType: 'all', filterScoreTypeidx: 1, filterRegionTypeName: 'All', filterRegionType: 0, }) async function getTopLocations() { try { const res = await getListTopLocationsService({ page: page, page_size: 20, order_by: pageState.filterScoreTypeidx, region_type: pageState.filterRegionType }) setTopLocations(res.data) } catch (err) { console.log(err) } } function onChangeReviewType(e: TargetedEvent, reviewer_type: string, i: number) { e.preventDefault() setPageState({ ...pageState, filterScoreType: reviewer_type, filterScoreTypeidx: i }) } function onChangeRegionType(e: TargetedEvent, region_name: string, type: number) { e.preventDefault(); setPageState({ ...pageState, filterRegionTypeName: region_name, filterRegionType: type }) } useEffect(() => { getTopLocations() }, [pageState]) return (

Top Locations

Min. Reviews

All

{MIN_REVIEWS.map(x => ( {x} ))}

Tags

All

{/* {REGIONS.map(x => ( {x} ))} */}
{topLocations.map(x => ( <> {/* UNCOMMENT....IF THERES A PURPOSE FOR RIGHT THREE DOTS */} {/* */}
{x.row_number}.{x.name}
{x.regency_name}
{x.address}
$$$ (IDR 1000-12000)
Maps Location
CRITICS SCORE

{x.critic_score !== 0 ? Number(x.critic_score) / Number(x.critic_count) * 10 : "N/A"}

{x.critic_count} reviews

USERS SCORE

{x.user_score !== 0 ? x.user_score : "N/A"}

{x.user_count} reviews

))}
) } export default BestLocation;