Skip to content

Commit

Permalink
Feature/embed (#474)
Browse files Browse the repository at this point in the history
* fix the html loader result

* add type

* embed path

* make sure the loading overlay shows

* style title

* remove extra color

* remove log

* remove unused code
  • Loading branch information
meganrm authored Mar 12, 2024
1 parent 50a8c6f commit 1980c09
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 23 deletions.
19 changes: 19 additions & 0 deletions src/components/EmbedOverlay/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";

import styles from "./style.css";

interface ViewerOverlayTargetProps {
title: string;
}

const EmbedOverlay = ({
title,
}: ViewerOverlayTargetProps): JSX.Element | null => {
return (
<div className={styles.container}>
<h4>{title}</h4>
</div>
);
};

export default EmbedOverlay;
13 changes: 13 additions & 0 deletions src/components/EmbedOverlay/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.container{
position: absolute;
height: 100%;
width: 100%;
z-index: 300;
display: flex;
pointer-events: none;
}

.container h4 {
color: var(--dark-theme-text-color);
margin: 0 auto;
}
5 changes: 3 additions & 2 deletions src/components/SideBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface SiderProps {
type: string;
onCollapse: (open: boolean) => void;
children?: React.ReactNode;
isEmbedded?: boolean;
}

interface SiderState {
Expand All @@ -36,12 +37,12 @@ export default class SideBar extends React.Component<SiderProps, SiderState> {
};

public render(): JSX.Element {
const { type, children } = this.props;

const { type, children, isEmbedded } = this.props;
// Ex) class="style__sider--30dA5 style__left--1KLfS"
const siderClass: string = classNames({
[styles.sider]: true,
[styles[type]]: true,
[styles.embed]: isEmbedded,
});

// Ex) class="style__trigger--30dA5 style__left--1KLfS style__collapsed--ncLRy"
Expand Down
3 changes: 3 additions & 0 deletions src/components/SideBar/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
background-color: var(--dark-theme-sidebar-bg);
padding: 0 10px 0 0;
}
.sider.embed {
height: 100vh;
}

.sider.right {
right: 0;
Expand Down
61 changes: 45 additions & 16 deletions src/containers/Simularium/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import {
const { Content } = Layout;

import styles from "./style.css";
import classNames from "classnames";
import { EMBED_PATHNAME } from "../../routes";
import EmbedOverlay from "../../components/EmbedOverlay";

interface AppProps {
onSidePanelCollapse: (number: number) => void;
Expand Down Expand Up @@ -194,32 +197,54 @@ class App extends React.Component<AppProps, AppState> {
}
}

public render(): JSX.Element {
public renderOverlay(isEmbedded: boolean) {
const {
simulariumController,
changeToLocalSimulariumFile,
simulariumFile,
resetDragOverViewer,
changeToLocalSimulariumFile,
viewerStatus,
fileIsDraggedOverViewer,
setViewerStatus,
clearSimulariumFile,
setError,
} = this.props;
if (isEmbedded) {
return <EmbedOverlay title={simulariumFile.name} />;
} else {
return (
<ViewerOverlayTarget
key="drop"
clearSimulariumFile={clearSimulariumFile}
loadLocalFile={changeToLocalSimulariumFile}
isLoading={viewerStatus === VIEWER_LOADING}
resetDragOverViewer={resetDragOverViewer}
fileIsDraggedOver={fileIsDraggedOverViewer}
setViewerStatus={setViewerStatus}
setError={setError}
/>
);
}
}

public render(): JSX.Element {
const { simulariumController, changeToLocalSimulariumFile } =
this.props;
const isEmbedded = location.pathname === EMBED_PATHNAME;
return (
<Layout className={styles.container}>
<Layout
className={classNames([
styles.container,
{ [styles.embed]: isEmbedded },
])}
>
<div ref={this.interactiveContent}>
<Layout className={styles.content}>
<ViewerOverlayTarget
key="drop"
clearSimulariumFile={clearSimulariumFile}
loadLocalFile={changeToLocalSimulariumFile}
isLoading={viewerStatus === VIEWER_LOADING}
resetDragOverViewer={resetDragOverViewer}
fileIsDraggedOver={fileIsDraggedOverViewer}
setViewerStatus={setViewerStatus}
setError={setError}
/>
<SideBar onCollapse={this.onPanelCollapse} type="left">
{this.renderOverlay(isEmbedded)}
<SideBar
onCollapse={this.onPanelCollapse}
isEmbedded={isEmbedded}
type="left"
>
<ModelPanel />
</SideBar>
<Content>
Expand All @@ -230,7 +255,11 @@ class App extends React.Component<AppProps, AppState> {
/>
)}
</Content>
<SideBar onCollapse={this.onPanelCollapse} type="right">
<SideBar
onCollapse={this.onPanelCollapse}
isEmbedded={isEmbedded}
type="right"
>
<ResultsPanel />
</SideBar>
</Layout>
Expand Down
6 changes: 6 additions & 0 deletions src/containers/Simularium/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
background: var(--dark-theme-body-bg);
}

.container.embed :global(.ant-layout-content) {
height: 100vh;
/* Prevents a light gray background from flashing upon collapsing the right sidebar */
background: var(--dark-theme-body-bg);
}

.content {
position: relative;
height: 100%;
Expand Down
15 changes: 10 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BrowserRouter, Switch, Route, useLocation } from "react-router-dom";
import { APP_ID } from "./constants";

import { createReduxStore } from "./state";
import routes, { VIEWER_PATHNAME } from "./routes";
import routes, { EMBED_PATHNAME, VIEWER_PATHNAME } from "./routes";
import ScrollToTop from "./components/ScrollToTop";
import AppHeader from "./containers/AppHeader";

Expand All @@ -32,7 +32,10 @@ function useLocationChange() {
const dispatch = useDispatch();

React.useEffect(() => {
if (location.pathname !== VIEWER_PATHNAME) {
if (
location.pathname !== VIEWER_PATHNAME &&
location.pathname !== EMBED_PATHNAME
) {
batch(() => {
// if we're navigating away from the viewer, stop playing and reset state
dispatch(setIsPlaying(false));
Expand Down Expand Up @@ -76,9 +79,11 @@ const App = () => {
}
>
<ScrollToTop />
<Header>
<AppHeader />
</Header>
{location.pathname !== EMBED_PATHNAME && (
<Header>
<AppHeader />
</Header>
)}
<RouterSwitch />
</BrowserRouter>
</Layout>
Expand Down
6 changes: 6 additions & 0 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Simularium from "../containers/Simularium";

export const VIEWER_PATHNAME = "/viewer";
export const TUTORIAL_PATHNAME = "/tutorial";
export const EMBED_PATHNAME = "/embed";

export default [
{
Expand All @@ -21,4 +22,9 @@ export default [
component: Simularium,
path: VIEWER_PATHNAME,
},
{
name: "Embed",
component: Simularium,
path: EMBED_PATHNAME,
},
];

0 comments on commit 1980c09

Please sign in to comment.