Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import { Provider, useDispatch, batch } from "react-redux";
import { Layout } from "antd";
import { BrowserRouter, Switch, Route, useLocation } from "react-router-dom";

import { APP_ID } from "./constants";

import { createReduxStore } from "./state";
import routes, { EMBED_PATHNAME, VIEWER_PATHNAME } from "./routes";
import ScrollToTop from "./components/ScrollToTop";
import AppHeader from "./containers/AppHeader";
import { APP_ID, URL_PARAM_KEY_FILE_NAME } from "./constants";
import TRAJECTORIES from "./constants/networked-trajectories";
import { createReduxStore } from "./state";
import { setIsPlaying } from "./state/viewer/actions";
import {
changeToNetworkedFile,
clearSimulariumFile,
} from "./state/trajectory/actions";
import { getUrlParamValue } from "./util/userUrlHandling";
Comment on lines +14 to +22
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a touch of organizing


const { Header } = Layout;

import "./style.css";
import { setIsPlaying } from "./state/viewer/actions";
import { clearSimulariumFile } from "./state/trajectory/actions";

export const store = createReduxStore();
interface LocationWithState extends Location {
Expand All @@ -42,6 +46,40 @@ function useLocationChange() {
});
}
}, [location]);

React.useEffect(() => {
const handlePopState = () => {
if (window.location.pathname === VIEWER_PATHNAME) {
const trajectoryId = getUrlParamValue(
window.location.href,
URL_PARAM_KEY_FILE_NAME
Comment on lines +53 to +55
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already getting the right URL into the address bar, just not loading/clearing.

);
if (trajectoryId) {
const trajectory = TRAJECTORIES.find(
(t) => t.id === trajectoryId
);
if (trajectory) {
batch(() => {
dispatch(setIsPlaying(false));
dispatch(
changeToNetworkedFile({
name: trajectory.id,
title: trajectory.title,
})
);
});
}
} else {
dispatch(clearSimulariumFile({ newFile: false }));
}
}
};

window.addEventListener("popstate", handlePopState);
return () => {
window.removeEventListener("popstate", handlePopState);
};
}, []);
}

const RouterSwitch = () => {
Expand Down
Loading