From fb9eaa18671842aa2686246b10387e1546cf9492 Mon Sep 17 00:00:00 2001 From: Haziq Khairi Date: Wed, 10 Jan 2024 18:44:22 +0800 Subject: [PATCH] feat: add routing, useable navbar and art description page --- src/App.jsx | 20 ++++- src/components/Navbar.jsx | 137 +++++++++++++++++++---------------- src/pages/ArtDescription.jsx | 51 +++++++++++++ 3 files changed, 142 insertions(+), 66 deletions(-) create mode 100644 src/pages/ArtDescription.jsx diff --git a/src/App.jsx b/src/App.jsx index bcfd2ea..7eb6932 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,26 +1,38 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import Navbar from './components/Navbar'; -import Home from './pages/Home'; import Footer from './components/Footer'; -import ErrorPage from './pages/Error'; + +import Home from './pages/Home'; import TopPicks from './pages/TopPicks'; +import ArtDescription from './pages/ArtDescription'; +import ErrorPage from './pages/Error'; function App() { return (
+ {/* Navigation Bar */} + {/* Route Definitions */} + {/* Home Page */} } /> + + {/* Top Picks Page */} } /> - {/* */} + + {/* Art Description Page */} + } /> + + {/* Fallback Error Page for Unmatched Routes */} } /> + + {/* Footer */}
); } - export default App; diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 8723242..864c33b 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -11,73 +11,86 @@ import { Autocomplete, AutocompleteItem, } from '@nextui-org/react'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import { FaSearch } from 'react-icons/fa'; import { allLists } from '../data/list'; -const SearchAutocomplete = ({ allLists }) => ( - } - radius="full" - variant="bordered" - > - {(item) => ( - -
-
- -
- {item.name} - {item.artist} +const SearchAutocomplete = ({ allLists }) => { + const navigate = useNavigate(); + + const handleSelectionChange = (id) => { + if (id) { + navigate(`/artistry-hub/art/${id}`); + } + }; + return ( + } + radius="full" + variant="bordered" + onSelectionChange={(key) => handleSelectionChange(key)} + itemToString={(item) => item?.name} + > + {(item) => ( + +
+
+ +
+ {item.name} + + {item.artist} + +
-
- - )} - -); + + )} + + ); +}; const UserProfileDropdown = () => ( diff --git a/src/pages/ArtDescription.jsx b/src/pages/ArtDescription.jsx new file mode 100644 index 0000000..63faa50 --- /dev/null +++ b/src/pages/ArtDescription.jsx @@ -0,0 +1,51 @@ +import { useParams } from 'react-router-dom'; +import { allLists } from '../data/list'; +import { Card, CardHeader, CardBody, Image } from '@nextui-org/react'; + +const ArtDescription = () => { + let { id } = useParams(); + let artItem = null; + + // Iterate over each list in allLists to find the art item + for (const listKey in allLists) { + if (Object.prototype.hasOwnProperty.call(allLists, listKey)) { + artItem = allLists[listKey].find((item) => item.id.toString() === id); + if (artItem) break; + } + } + + // if (!artItem) { + // return
Artwork not found
; + // } + + return ( +
+
+ {artItem.name} +
+
+ + +

{artItem.name}

+

by {artItem.artist}

+
+ +

{artItem.description}

+

Year: {artItem.date}

+

Style: {artItem.style}

+

Dimensions: {artItem.dimensions}

+

Location: {artItem.location}

+
+
+
+
+ ); +}; + +export default ArtDescription;