feat: change defaultViewMode when location change

proto-module-actu-react
Jalil Arfaoui 2023-02-25 22:38:26 +01:00
parent 236c119f8a
commit 5d05395ab7
2 changed files with 12 additions and 15 deletions

View File

@ -13,11 +13,11 @@ import "./style/thumbs.css";
import "./style/row.css"; import "./style/row.css";
import "./photos"; import "./photos";
const defaultViewMode: ViewMode = location.href.includes("resistants") interface Props {
? "photos" defaultViewMode: ViewMode;
: "map"; }
export const App = () => { export const App = ({ defaultViewMode }: Props) => {
const [viewMode, setViewMode] = React.useState<ViewMode>(defaultViewMode); const [viewMode, setViewMode] = React.useState<ViewMode>(defaultViewMode);
return ( return (

View File

@ -1,24 +1,21 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import { App } from "./App"; import { App } from "./App";
import { ViewMode } from "./routes/ViewMode";
console.log("Starting app"); const renderResistants = (defaultViewMode: ViewMode) => {
const renderResistants = () => {
console.log("Rendering app");
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode> <React.StrictMode>
<App /> <App defaultViewMode={defaultViewMode} />
</React.StrictMode> </React.StrictMode>
); );
}; };
// @ts-ignore // @ts-ignore
window.Squarespace.onInitialize(Y, function () { window.Squarespace.onInitialize(Y, function () {
console.log("re-rendering"); const defaultViewMode: ViewMode = location.href.includes("resistants")
renderResistants(); ? "photos"
: "map";
renderResistants(defaultViewMode);
}); });
// renderResistants();
console.log("done");