From 5d05395ab75543f15f95879dc3b326ae078df648 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Sat, 25 Feb 2023 22:38:26 +0100 Subject: [PATCH] feat: change defaultViewMode when location change --- src/App.tsx | 8 ++++---- src/main.tsx | 19 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 77d4597..e1c4c98 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,11 +13,11 @@ import "./style/thumbs.css"; import "./style/row.css"; import "./photos"; -const defaultViewMode: ViewMode = location.href.includes("resistants") - ? "photos" - : "map"; +interface Props { + defaultViewMode: ViewMode; +} -export const App = () => { +export const App = ({ defaultViewMode }: Props) => { const [viewMode, setViewMode] = React.useState(defaultViewMode); return ( diff --git a/src/main.tsx b/src/main.tsx index e4d1540..0071506 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,24 +1,21 @@ import React from "react"; import ReactDOM from "react-dom/client"; import { App } from "./App"; +import { ViewMode } from "./routes/ViewMode"; -console.log("Starting app"); - -const renderResistants = () => { - console.log("Rendering app"); +const renderResistants = (defaultViewMode: ViewMode) => { ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - + ); }; // @ts-ignore window.Squarespace.onInitialize(Y, function () { - console.log("re-rendering"); - renderResistants(); + const defaultViewMode: ViewMode = location.href.includes("resistants") + ? "photos" + : "map"; + + renderResistants(defaultViewMode); }); - -// renderResistants(); - -console.log("done");