Skip to content

Commit

Permalink
Merge pull request #83 from flatironinstitute/remove-useRoute
Browse files Browse the repository at this point in the history
Remove existing router logic
  • Loading branch information
WardBrian authored Jun 26, 2024
2 parents fe7d9c5 + 521fd30 commit 45cd277
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 155 deletions.
14 changes: 2 additions & 12 deletions gui/src/app/MainWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@ import { useWindowDimensions } from "@fi-sci/misc";
import { FunctionComponent } from "react";
import StatusBar, { statusBarHeight } from "./StatusBar";
import HomePage from "./pages/HomePage/HomePage";
import useRoute from "./useRoute";

type Props = {
// none
}

const MainWindow: FunctionComponent<Props> = () => {
const {route} = useRoute()
const {width, height} = useWindowDimensions()
const H = height - statusBarHeight
return (
<div className="MainWindow" style={{position: 'absolute', width, height, overflow: 'hidden'}}>
<div className="MainWindowContent" style={{position: 'absolute', top: 0, width, height: H, overflow: 'hidden'}}>
{
route.page === 'home' ? (
<HomePage width={width} height={H} />
) : route.page === 'about' ? (
<HomePage width={width} height={H} />
) : (
<div>404</div>
)
}
<HomePage width={width} height={H} />
</div>
{
statusBarHeight && (
Expand All @@ -39,4 +29,4 @@ const MainWindow: FunctionComponent<Props> = () => {
)
}

export default MainWindow
export default MainWindow
2 changes: 0 additions & 2 deletions gui/src/app/SPAnalysis/SPAnalysisContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ type SPAnalysisContextType = {
}

type SPAnalysisContextProviderProps = {
// may be used in the future when we allow parameters to be passed through the string
sourceDataUri: string
}

export const SPAnalysisContext = createContext<SPAnalysisContextType>({
Expand Down
31 changes: 8 additions & 23 deletions gui/src/app/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SPAnalysisContextProvider, { SPAnalysisContext } from '../../SPAnalysis/S
import { SPAnalysisKnownFiles } from "../../SPAnalysis/SPAnalysisDataModel";
import { SamplingOpts } from "../../StanSampler/StanSampler";
import useStanSampler, { useSamplerStatus } from "../../StanSampler/useStanSampler";
import useRoute from "../../useRoute";
import LeftPanel from "./LeftPanel";
import TopBar from "./TopBar";

Expand All @@ -19,31 +18,23 @@ type Props = {
}

const HomePage: FunctionComponent<Props> = ({ width, height }) => {
const { route } = useRoute()
if (route.page !== 'home') {
throw Error('Unexpected route')
}

// NOTE: We should probably move the SPAnalysisContextProvider up to the App or MainWindow
// component; however this will wait on routing refactor since I don't want to add the `route`
// item in those contexts in this PR
return (
<SPAnalysisContextProvider
key={route.sourceDataUri || ''} // force complete re-render when sourceDataUri changes
sourceDataUri={route.sourceDataUri}
>
<SPAnalysisContextProvider>
<HomePageChild width={width} height={height} />
</SPAnalysisContextProvider>
)
}

const HomePageChild: FunctionComponent<Props> = ({ width, height }) => {
const { route, setRoute } = useRoute()
if (route.page !== 'home') {
throw Error('Unexpected route')
}


const { data, update } = useContext(SPAnalysisContext)
const setSamplingOpts = useCallback((opts: SamplingOpts) => {
update({type: 'setSamplingOpts', opts})
update({ type: 'setSamplingOpts', opts })
}, [update])

const [compiledMainJsUrl, setCompiledMainJsUrl] = useState<string>('')
Expand All @@ -52,20 +43,14 @@ const HomePageChild: FunctionComponent<Props> = ({ width, height }) => {
const topBarHeight = 25

useEffect(() => {
// update the title in the route
const newRoute = { ...route, title: data.meta.title }
setRoute(newRoute, true)
}, [data.meta.title, route, setRoute])

useEffect(() => {
// update the document title based on the route
document.title = route?.title ?? 'stan-playground'
}, [route.title])
document.title = "Stan Playground - " + data.meta.title;
}, [data.meta.title])

return (
<div style={{ position: 'absolute', width, height, overflow: 'hidden' }}>
<div className="top-bar" style={{ position: 'absolute', left: 0, top: 0, width, height: topBarHeight, overflow: 'hidden' }}>
<TopBar
title = {data.meta.title}
width={width}
height={topBarHeight}
/>
Expand Down
26 changes: 12 additions & 14 deletions gui/src/app/pages/HomePage/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@ import { FunctionComponent } from "react";
import CompilationServerConnectionControl from "../../CompilationServerConnectionControl/CompilationServerConnectionControl";
import { SmallIconButton } from "@fi-sci/misc";
import { QuestionMark } from "@mui/icons-material";
import useRoute from "../../useRoute";
import { Toolbar } from "@mui/material";


type TopBarProps = {
title: string
width: number
height: number
}

const TopBar: FunctionComponent<TopBarProps> = () => {
const { route, setRoute } = useRoute()
if (route.page !== 'home') {
throw Error('Unexpected route')
}
const TopBar: FunctionComponent<TopBarProps> = ({title}) => {
return (
<div>
<Toolbar style={{minHeight: 20}}>
Stan Playground - {route.title}
<span style={{marginLeft: 'auto'}} />
<Toolbar style={{ minHeight: 20 }}>
Stan Playground - {title}
<span style={{ marginLeft: 'auto' }} />
<CompilationServerConnectionControl />
<span>
<SmallIconButton
icon={<QuestionMark />}
onClick={() => setRoute({page: 'about'})}
title={`About Stan Playground`}
/>
<SmallIconButton
icon={<QuestionMark />}
onClick={() => {
window.open("https://github.com/flatironinstitute/stan-playground", "_blank")
}}
title={`About Stan Playground`}
/>
</span>
</Toolbar>
</div>
Expand Down
104 changes: 0 additions & 104 deletions gui/src/app/useRoute.ts

This file was deleted.

0 comments on commit 45cd277

Please sign in to comment.