Skip to content

Commit

Permalink
Built out HostVanDetail 'vans' routes, sub-navigation and correspondi…
Browse files Browse the repository at this point in the history
…ng sub-sections
  • Loading branch information
chrisnajman committed Jun 12, 2024
1 parent 9042519 commit f391854
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 11 deletions.
18 changes: 17 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import Income from "./pages/host/Income"
import Reviews from "./pages/host/Reviews"
import HostVans from "./pages/host/HostVans"
import HostVanDetail from "./pages/host/HostVanDetail"
import HostVanInfo from "./pages/host/hostVanDetailSections/HostVanInfo"
import HostVanPricing from "./pages/host/hostVanDetailSections/HostVanPricing"
import HostVanPhotos from "./pages/host/hostVanDetailSections/HostVanPhotos"

function App() {
return (
Expand Down Expand Up @@ -52,7 +55,20 @@ function App() {
<Route
path="host-vans/:id"
element={<HostVanDetail />}
/>
>
<Route
index
element={<HostVanInfo />}
/>
<Route
path="pricing"
element={<HostVanPricing />}
/>
<Route
path="photos"
element={<HostVanPhotos />}
/>
</Route>
<Route
path="reviews"
element={<Reviews />}
Expand Down
39 changes: 39 additions & 0 deletions src/components/HostVanDetailNav.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NavLink } from "react-router-dom"

function HostVanDetailNav() {
return (
<>
<nav className="site-navigation hosts-nav">
<ul>
<li>
<NavLink
to="."
aria-current="page"
end
>
DetailsInfo
</NavLink>
</li>
<li>
<NavLink
to="pricing"
aria-current="page"
>
Pricing
</NavLink>
</li>
<li>
<NavLink
to="photos"
aria-current="page"
>
Photos
</NavLink>
</li>
</ul>
</nav>
</>
)
}

export default HostVanDetailNav
2 changes: 1 addition & 1 deletion src/components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Nav() {
<ul>
<li>
<NavLink
to="/"
to="."
aria-current="page"
end
>
Expand Down
4 changes: 1 addition & 3 deletions src/layout/LayoutHost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function LayoutHost() {
<ul>
<li>
<NavLink
to="/host"
to="."
aria-current="page"
end
>
Expand All @@ -18,7 +18,6 @@ function LayoutHost() {
<NavLink
to="income"
aria-current="page"
end
>
Income
</NavLink>
Expand All @@ -35,7 +34,6 @@ function LayoutHost() {
<NavLink
to="reviews"
aria-current="page"
end
>
Reviews
</NavLink>
Expand Down
62 changes: 60 additions & 2 deletions src/pages/host/HostVanDetail.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
import { useState, useEffect } from "react"
import { useParams, Link, Outlet } from "react-router-dom"
import HostVanDetailNav from "../../components/HostVanDetailNav"

function HostVanDetail() {
const params = useParams()

const [van, setVan] = useState(null)

useEffect(() => {
async function getVan() {
try {
const res = await fetch(`/api/vans/${params.id}`)
const vanData = await res.json()
setVan(vanData.vans)
} catch (error) {
console.log(error)
}
}
getVan()
}, [params.id])
return (
<div className="hosts-container content-container host-van-detail">
<h1>Your Listed Van Details</h1>
<div className="hosts-container content-container host-van-detail van-detail-container">
<Link
className="back-link link-button"
to=".."
relative="path"
>
Back to Host Vans list
</Link>
{van ? (
<>
<div className="top-wrap">
<div>
<picture>
<source
srcSet={van.imageUrlWebp}
type="image/webp"
/>
<img
className="van-image"
src={van.imageUrlPng}
alt={`The ${van.name} van`}
loading="lazy"
width="881"
height="881"
/>
</picture>
</div>
<div>
<p>{van.type}</p>
<h1>{van.name}</h1>
<p>&pound;{van.price}/day</p>
</div>

<HostVanDetailNav />
</div>
{<Outlet context={{ van }} />}
</>
) : (
<p>Loading ...</p>
)}
</div>
)
}
Expand Down
66 changes: 65 additions & 1 deletion src/pages/host/HostVans.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,71 @@
import { useState, useEffect } from "react"
import { Link } from "react-router-dom"
import { FaCircleArrowRight } from "react-icons/fa6"

function HostVans() {
const [vans, setVans] = useState([])

useEffect(() => {
async function getVans() {
try {
const res = await fetch("/api/vans")
const vansData = await res.json()
setVans(vansData.vans)
} catch (error) {
console.log(error)
}
}
getVans()
}, [])

// hostId 123 or 456 or 789
const hostVanId = "123"
const vanList = vans
.filter((van) => van.hostId === hostVanId)
.map((van) => {
return (
<li key={van.id}>
<Link
className="link-button"
to={van.id}
aria-label={`View details for ${van.name},
priced at £${van.price} per day`}
>
<p>{van.name}</p>
<picture>
<source
srcSet={van.imageUrlWebp}
type="image/webp"
/>
<img
className="van-image"
src={van.imageUrlPng}
alt={`The ${van.name} van`}
loading="lazy"
width="881"
height="881"
/>
</picture>

<ul className="van-footer">
<li>Price: £{van.price}/day</li>
{/* <li>
Type: <span className="van-type">{van.type}</span>
</li> */}
</ul>
<FaCircleArrowRight aria-hidden="true" />
</Link>
</li>
)
})
return (
<div className="hosts-container content-container host-vans">
<div className="hosts-container content-container host-vans vans-container">
<h1>Your Listed Vans</h1>
{vans.length > 0 ? (
<ul className="van-list">{vanList}</ul>
) : (
<h2>Loading ...</h2>
)}
</div>
)
}
Expand Down
15 changes: 15 additions & 0 deletions src/pages/host/hostVanDetailSections/HostVanInfo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useOutletContext } from "react-router-dom"

function HostVanInfo() {
const { van } = useOutletContext()
return (
<section className="host-vans-section">
<div>Name: {van.name}</div>
<div>Category: {van.type}</div>
<div>Description: {van.description}</div>
<div>Visibility: Public</div>
</section>
)
}

export default HostVanInfo
25 changes: 25 additions & 0 deletions src/pages/host/hostVanDetailSections/HostVanPhotos.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useOutletContext } from "react-router-dom"

function HostVanPhotos() {
const { van } = useOutletContext()
return (
<section className="host-vans-section">
<picture>
<source
srcSet={van.imageUrlWebp}
type="image/webp"
/>
<img
className="van-image"
src={van.imageUrlPng}
alt={`The ${van.name} van`}
loading="lazy"
width="881"
height="881"
/>
</picture>
</section>
)
}

export default HostVanPhotos
8 changes: 8 additions & 0 deletions src/pages/host/hostVanDetailSections/HostVanPricing.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useOutletContext } from "react-router-dom"

function HostVanPricing() {
const { van } = useOutletContext()
return <section className="host-vans-section">&pound;{van.price}/day</section>
}

export default HostVanPricing
4 changes: 2 additions & 2 deletions src/pages/vans/VanDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ function VanDetail() {
<div className="van-detail-container content-container">
<Link
className="back-link link-button"
to="/vans"
to=".."
relative="path"
>
{" "}
Back to Vans list
</Link>
{van ? (
Expand Down
6 changes: 5 additions & 1 deletion src/pages/vans/Vans.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ function Vans() {
return (
<div className="vans-container content-container">
<h1>Explore our van options</h1>
{vans ? <ul className="van-list">{vanList}</ul> : "Loading ..."}
{vans.length > 0 ? (
<ul className="van-list">{vanList}</ul>
) : (
<h2>Loading ...</h2>
)}
</div>
)
}
Expand Down
Loading

0 comments on commit f391854

Please sign in to comment.