From 628632ff5092f1e3cf6c968d9bdfbd9a24f59541 Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Fri, 8 Jan 2021 19:47:37 +0100 Subject: Initial commit --- pages/_app.tsx | 7 +++++ pages/index.tsx | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 pages/_app.tsx create mode 100644 pages/index.tsx (limited to 'pages') diff --git a/pages/_app.tsx b/pages/_app.tsx new file mode 100644 index 0000000..1cfd2cb --- /dev/null +++ b/pages/_app.tsx @@ -0,0 +1,7 @@ +import '../styles/globals.css'; +import { AppProps } from 'next/app'; + +export default function App({ Component, pageProps }: AppProps): JSX.Element { + // eslint-disable-next-line react/jsx-props-no-spreading + return ; +} diff --git a/pages/index.tsx b/pages/index.tsx new file mode 100644 index 0000000..e422069 --- /dev/null +++ b/pages/index.tsx @@ -0,0 +1,80 @@ +import { GetStaticProps } from 'next'; +import Head from 'next/head'; +import dynamic from 'next/dynamic'; +import { useState } from 'react'; + +import { Trip } from 'models'; +import getTripsData from 'lib/trips'; +import Sidebar from 'components/Sidebar/Sidebar'; +import Gallery from 'components/Gallery/Gallery'; +import styles from 'styles/Home.module.css'; + +interface Props { + allTripsData: Trip[]; +} + +const Map = dynamic(() => import('components/Map/Map'), { ssr: false }); + +export default function Home({ allTripsData }: Props): JSX.Element { + const [currentTrip, setCurrentTrip] = useState(allTripsData[0]); + const [currentPhoto, setCurrentPhoto] = useState(null); + const [asideOpen, setAsideOpen] = useState(false); + + function handleMarkerClick(photo: string) { + const index = currentTrip.photos.findIndex((p) => p.name === photo); + setCurrentPhoto(index); + } + + function handlePhotoChange(direction: boolean): void { + if (direction) { + if (currentTrip.photos.length > currentPhoto + 1) { + setCurrentPhoto(currentPhoto + 1); + } + } else if (currentPhoto - 1 >= 0) { + setCurrentPhoto(currentPhoto - 1); + } + } + + return ( +
+ + Trip Share + + + + {currentPhoto !== null && ( + setCurrentPhoto(null)} + handlePhotoChange={handlePhotoChange} + /> + )} + + setAsideOpen(false)} + setCurrentTrip={setCurrentTrip} + /> + + + +
+ +
+
+ ); +} + +export const getStaticProps: GetStaticProps = async () => { + const allTripsData = getTripsData(); + + return { + props: { + allTripsData, + }, + }; +}; -- cgit v1.2.3