diff --git a/src/App.tsx b/src/App.tsx index c410b9f..f932378 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,15 +1,17 @@ import { useEffect, useState } from "react"; import { useFetch } from "./hooks/useFetch"; import { useHero } from "./hooks/useHero"; -import { v4 as uuid } from "uuid"; import "./App.css"; +import { header } from "./components/header"; +import { heroSection } from "./components/heroSection"; +import { tripsSection } from "./components/tripsSection"; function App() { const [trips, setTrips] = useState(0); - const [nav, setNav] = useState([]); - const [boughtIt, setBoughtIt] = useState(false); - const { data, isLoading, error } = useFetch(); - const { heroics, waitAMo, fail } = useHero(); + const [, setNav] = useState([]); + const [, setBoughtIt] = useState(false); + const { data, isLoading } = useFetch(); + const { heroics, waitAMo } = useHero(); useEffect(() => { setNav(() => { @@ -18,137 +20,13 @@ function App() { if (heroics) if (data) setTrips(data.length); }, [data, heroics]); - const handleClick = (e: React.MouseEvent) => { - setBoughtIt(true); - if (e.currentTarget.value) { - const stuff = e.currentTarget.value.split("/"); - const experience = stuff[0]; - const cost = parseInt(stuff[1]); - alert( - `Okie dokie, so you've bought the '${experience}' excursion, at a cost of ${ - cost && - cost.toLocaleString("en-GB", { style: "currency", currency: "GBP" }) - }\rNice one 🚀` - ); - } - }; - - const renderReviewScore = (score: number) => { - const scoreRepresentationUsingACuteLilPlanetEmoji = []; - for (let i = 0; i < score; i++) { - scoreRepresentationUsingACuteLilPlanetEmoji.push( - 🪐 - ); - } - return scoreRepresentationUsingACuteLilPlanetEmoji; - }; - return ( <> -
-
- - eefe spaceship logo - -

Extraterrestrial Excursions for Earthlings

-
-
    - {nav.map((place) => { - return ( -
  • - {place} -
  • - ); - })} -
-
- + {header} {waitAMo &&

...getting heroics...

} - {heroics && ( -
-

We've been helping humanity traverse the universe for aeons.

-

- Now it's your turn to marvel at the wonders of the universe! But don't just take our word for it; check out - these smashing reviews from customers just like you! -

-
    - {heroics.testimonials.map(({ name, rating, spiel, social }) => { - return ( -
  • -

    {name}

    - {social} -

    {spiel}

    -

    Score / 5: {renderReviewScore(rating)}

    -
  • - ); - })} -
-
- )} - + {heroics && heroSection(heroics)} {isLoading &&

Loading...

} - {data && ( -
-

We found {trips} trips for you!

{" "} -
    - {data.map( - ({ - id, - tripName, - description, - imageUrl, - cost, - lengthInDays, - isBookable, - }) => { - return ( -
  • -

    {tripName}

    -

    - {description} -

    - {`representation -

    - Duration: {lengthInDays} day - {lengthInDays > 1 && "s"} -

    -

    - Price:{" "} - {cost.toLocaleString("en-GB", { - style: "currency", - currency: "GBP", - })} -

    - -
  • - ); - } - )} -
-
- )} + {data && trips && tripsSection(trips, data, setBoughtIt)} ); } diff --git a/src/components/header.tsx b/src/components/header.tsx new file mode 100644 index 0000000..a36a343 --- /dev/null +++ b/src/components/header.tsx @@ -0,0 +1,25 @@ +import React from 'react'; + +export const header = (nav : string[]) => ( +
+
+ + eefe spaceship logo + +

Extraterrestrial Excursions for Earthlings

+
+
    + {nav.map((place) => { + return ( +
  • + {place} +
  • + ); + })} +
+
+ ); \ No newline at end of file diff --git a/src/components/heroSection.tsx b/src/components/heroSection.tsx new file mode 100644 index 0000000..68b73ed --- /dev/null +++ b/src/components/heroSection.tsx @@ -0,0 +1,41 @@ +import { HeroDeets } from '../hooks/useHero'; +import { v4 as uuid } from "uuid"; + +export const heroSection = (heroics : HeroDeets) => ( +
+

We've been helping humanity traverse the universe for aeons.

+

+ Now it's your turn to marvel at the wonders of the universe! But don't just take our word for it; check out + these smashing reviews from customers just like you! +

+
    + {heroics.testimonials.map(({ name, rating, spiel, social }) => { + return ( +
  • +

    {name}

    + {social} +

    {spiel}

    +

    Score / 5: {renderReviewScore(rating)}

    +
  • + ); + })} +
+
+ ); + + const renderReviewScore = (score: number) => { + const icons = []; + for (let i = 0; i < score; i++) { + icons.push( + 🪐 + ); + } + return icons; + }; \ No newline at end of file diff --git a/src/components/tripsSection.tsx b/src/components/tripsSection.tsx new file mode 100644 index 0000000..a5bb14b --- /dev/null +++ b/src/components/tripsSection.tsx @@ -0,0 +1,67 @@ +import { TripDatum } from "../hooks/useFetch"; + +export const tripsSection = (trips:number, data : TripDatum[], setBoughtIt : React.Dispatch>) => ( +
+

We found {trips} trips for you!

{" "} +
    + {data.map( + ({ + id, + tripName, + description, + imageUrl, + cost, + lengthInDays, + isBookable, + }) => { + return ( +
  • +

    {tripName}

    +

    + {description} +

    + {`representation +

    + Duration: {lengthInDays} day + {lengthInDays > 1 && "s"} +

    +

    + Price:{" "} + {cost.toLocaleString("en-GB", { + style: "currency", + currency: "GBP", + })} +

    + +
  • + ); + } + )} +
+
); + +const handleClick = (e: React.MouseEvent, setBoughtIt : React.Dispatch>) => { + setBoughtIt(true); + if (e.currentTarget.value) { + const stuff = e.currentTarget.value.split("/"); + const experience = stuff[0]; + const cost = parseInt(stuff[1]); + alert( + `Okie dokie, so you've bought the '${experience}' excursion, at a cost of ${ + cost && + cost.toLocaleString("en-GB", { style: "currency", currency: "GBP" }) + }\rNice one 🚀` + ); + } +}; \ No newline at end of file diff --git a/src/hooks/useFetch.ts b/src/hooks/useFetch.ts index 220539b..f2208f7 100644 --- a/src/hooks/useFetch.ts +++ b/src/hooks/useFetch.ts @@ -16,7 +16,7 @@ export const useFetch = () => { return { data, isLoading, error }; }; -interface TripDatum { +export interface TripDatum { id: string; tripName: string; description: string; diff --git a/src/hooks/useHero.ts b/src/hooks/useHero.ts index 40604a5..e949e2b 100644 --- a/src/hooks/useHero.ts +++ b/src/hooks/useHero.ts @@ -16,7 +16,7 @@ export const useHero = () => { return { heroics, waitAMo, fail }; }; -interface HeroDeets { +export interface HeroDeets { image: "https://images.unsplash.com/photo-1444703686981-a3abbc4d4fe3?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80"; testimonials: Array; }