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 "./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<ViewMode>(defaultViewMode);
return (

View File

@ -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(
<React.StrictMode>
<App />
<App defaultViewMode={defaultViewMode} />
</React.StrictMode>
);
};
// @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");