aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Zelent <marcin@zelent.net>2021-01-26 19:00:23 +0100
committerMarcin Zelent <marcin@zelent.net>2021-01-26 19:00:23 +0100
commit57c86ec5516df31172d79e10726a9699e09ad9c9 (patch)
treee37d5d01722b9093751f93d3c4224a3f1c934db7 /pages/index.tsx
parent8612b1de30edbb261108c132fa6550bb3cadd536 (diff)
Added hash with the current trip's name to the URL
Diffstat (limited to 'pages/index.tsx')
-rw-r--r--pages/index.tsx15
1 files changed, 14 insertions, 1 deletions
diff --git a/pages/index.tsx b/pages/index.tsx
index e422069..f9b365b 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,7 +1,7 @@
import { GetStaticProps } from 'next';
import Head from 'next/head';
import dynamic from 'next/dynamic';
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import { Trip } from 'models';
import getTripsData from 'lib/trips';
@@ -20,6 +20,19 @@ export default function Home({ allTripsData }: Props): JSX.Element {
const [currentPhoto, setCurrentPhoto] = useState(null);
const [asideOpen, setAsideOpen] = useState(false);
+ useEffect(() => {
+ if (window.location.hash.length === 0) {
+ window.location.hash = currentTrip.name;
+ } else {
+ const index = allTripsData.findIndex((t) => t.name === window.location.hash.substr(1));
+ if (index > -1) setCurrentTrip(allTripsData[index]);
+ }
+ }, []);
+
+ useEffect(() => {
+ window.location.hash = currentTrip.name;
+ }, [currentTrip]);
+
function handleMarkerClick(photo: string) {
const index = currentTrip.photos.findIndex((p) => p.name === photo);
setCurrentPhoto(index);