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