import { Filter, kinds, nip19 } from 'nostr-tools' import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { A11y, Navigation, Pagination, Autoplay } from 'swiper/modules' import { Swiper, SwiperSlide } from 'swiper/react' import { BlogCard } from '../components/BlogCard' import { GameCard } from '../components/GameCard' import { ModCard } from '../components/ModCard' import { LANDING_PAGE_DATA } from '../constants' import { RelayController } from '../controllers' import { useDidMount } from '../hooks' import { appRoutes, getModPageRoute } from '../routes' import { ModDetails } from '../types' import { extractModData, fetchMods, handleModImageError, log, LogType } from '../utils' import '../styles/cardLists.css' import '../styles/SimpleSlider.css' import '../styles/styles.css' // Import Swiper styles import 'swiper/css' import 'swiper/css/navigation' import 'swiper/css/pagination' export const HomePage = () => { const navigate = useNavigate() return (
{LANDING_PAGE_DATA.featuredSlider.map((naddr) => ( ))}

Cool Games

{LANDING_PAGE_DATA.featuredGames.map((game) => ( ))}
navigate(appRoutes.games)} > View All

Awesome Mods

{LANDING_PAGE_DATA.awesomeMods.map((naddr) => ( ))}
navigate(appRoutes.mods)} > View All

Blog Posts (WIP)

) } type SlideContentProps = { naddr: string } const SlideContent = ({ naddr }: SlideContentProps) => { const navigate = useNavigate() const [mod, setMod] = useState() useDidMount(() => { const decoded = nip19.decode<'naddr'>(naddr as `naddr1${string}`) const { identifier, kind, pubkey, relays = [] } = decoded.data const filter: Filter = { '#a': [identifier], authors: [pubkey], kinds: [kind] } RelayController.getInstance() .fetchEvent(filter, relays) .then((event) => { if (event) { const extracted = extractModData(event) setMod(extracted) } }) .catch((err) => { log( true, LogType.Error, 'An error occurred in fetching mod details from relays', err ) }) }) if (!mod) return return ( <>

{mod.title}

{mod.summary}

{mod.game}

navigate(getModPageRoute(naddr))} > Check it out
) } type DisplayModProps = { naddr: string } const DisplayMod = ({ naddr }: DisplayModProps) => { const navigate = useNavigate() const [mod, setMod] = useState() useDidMount(() => { const decoded = nip19.decode<'naddr'>(naddr as `naddr1${string}`) const { identifier, kind, pubkey, relays = [] } = decoded.data const filter: Filter = { '#a': [identifier], authors: [pubkey], kinds: [kind] } RelayController.getInstance() .fetchEvent(filter, relays) .then((event) => { if (event) { const extracted = extractModData(event) setMod(extracted) } }) .catch((err) => { log( true, LogType.Error, 'An error occurred in fetching mod details from relays', err ) }) }) if (!mod) return const route = getModPageRoute(naddr) return ( navigate(route)} /> ) } const DisplayLatestMods = () => { const navigate = useNavigate() const [isFetchingLatestMods, setIsFetchingLatestMods] = useState(true) const [latestMods, setLatestMods] = useState([]) useDidMount(() => { fetchMods({ source: window.location.host }) .then((res) => { const mods = res .sort((a, b) => b.published_at - a.published_at) .slice(0, 4) setLatestMods(mods) }) .finally(() => { setIsFetchingLatestMods(false) }) }) return (

Latest Mods

{isFetchingLatestMods ? ( ) : ( latestMods.map((mod) => { const route = getModPageRoute( nip19.naddrEncode({ identifier: mod.aTag, pubkey: mod.author, kind: kinds.ClassifiedListing }) ) return ( navigate(route)} /> ) }) )}
) } const Spinner = () => { return (
) }