import { SeparatorWithAnchor } from '../../components'; import news from '../../datas/recent_news_event.json'; import popular from '../../datas/popular.json'; import critics_users_pick from '../../datas/critics_users_best_pick.json'; import popular_user_review from '../../datas/popular_user_reviews.json'; import './style.css'; import { useEffect, useState } from 'preact/hooks'; import { getListRecentLocationsRatingsService } from '../../services'; import { useNavigate } from 'react-router-dom'; type NewPlaces = { id: Number, name: string, thumbnail: NullValueRes<'String', string>, regency_name: String, province_name: String, critic_score: Number, critic_count: Number, user_score: Number, user_count: Number } type News = { header: string, thumbnail: string, link: string, comments_count: Number likes_count: Number } function Home() { const [recentLocations, setRecentLocations] = useState>([]) // const [isLoading, setIsLoading] = useState(true) const navigate = useNavigate() async function getRecentLocations() { try { const locations = await getListRecentLocationsRatingsService(12) setRecentLocations(locations.data) // setIsLoading(false) } catch(error) { console.log(error) } } function onNavigateToDetail( id: Number, critic_count: Number, critic_score: Number, user_count: Number, user_score: Number, ) { navigate(`/location/${id}`, { state: { user_score: user_score, user_count: user_count, critic_score: critic_score, critic_count: critic_count } }) } useEffect(() => { getRecentLocations() },[]) return ( <>
{/* RECENTLY ADDED SECTION */}
{recentLocations.map((x) => (
onNavigateToDetail(x.id, x.critic_count, x.critic_score, x.user_count, x.user_score)}>
{x.name}

{x.name}

{x.regency_name}, {x.province_name}

{ x.critic_count !== 0 &&

{x.critic_score}

critic score ({x.critic_count})

} { x.user_score !== 0 &&

{x.user_score}

user score ({x.user_count})

}
))}
{/* END RECENTLY ADDED SECTION */} {/* START RECENT NEWS / EVENT SECTION */} {/* USE OPEN GRAPH PARSER TO READ OG DATA FROM HTML */} {/* https://github.com/dyatlov/go-opengraph */}
{news.data.map((x: News) => (
{x.link.split("/")[2].replace(/www\./, '')}

{x.header}

{x.likes_count}

{x.comments_count}

)) }
{/* END RECENT NEWS / EVENT SECTION */} {/* LOCATION CRITICS BEST AND USERS BEST SECTION */}
{popular_user_review.data.map((x) => (

{x.place_name}

{x.location}

{x.username}

{x.rating}

{x.message} read more
)) }
{/* START LOCATION CRITICS BEST AND USERS BEST SECTION */}
{popular.data.map((x) => (

{x.name}

{x.location}

))}
{critics_users_pick.critics.map((x) => (

{x.name}

{x.location}

{x.critic_rating}

)) }
{critics_users_pick.users.map((x) => (

{x.name}

{x.location}

{x.user_rating}

)) }
) } export default Home;