diff --git a/client/src/routes/offers.tsx b/client/src/routes/offers.tsx new file mode 100644 index 0000000..3c556ea --- /dev/null +++ b/client/src/routes/offers.tsx @@ -0,0 +1,41 @@ +import { h } from 'preact'; +import { useState, useEffect } from 'preact/hooks'; +import { route } from 'preact-router'; +import { useSelector, useDispatch } from 'react-redux' + +import http from './../http'; +import { State, offersState } from './../store'; + +import Offer from './../components/offer'; + +function Home() { + const dispatch = useDispatch() + const offers = useSelector((state: State) => state.offers); + + useEffect(() => { + async function getOffers() { + const [error, offers] = await http.getOffers(); + if (error) return console.error(error); + dispatch(offersState.actions.set(offers)); + if (offers.length === 0) route('/search'); + } + getOffers(); + }, []); + + if (!offers.length) { + return ( +