feat: change defaultViewMode when location change
parent
236c119f8a
commit
5d05395ab7
|
@ -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 (
|
||||||
|
|
19
src/main.tsx
19
src/main.tsx
|
@ -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");
|
|
||||||
|
|
Loading…
Reference in New Issue