-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: lazy-load top-level pages, reduce initial page load (#1295)
* refactor: lazy-load top-level pages, reduce initial page load * styles
- Loading branch information
Showing
24 changed files
with
489 additions
and
311 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
|
||
import { WebSocketState } from "@/core/websocket/types"; | ||
import { cn } from "@/utils/cn"; | ||
import React, { PropsWithChildren } from "react"; | ||
import { StatusOverlay } from "./header/status"; | ||
import { AppConfig } from "@/core/config/config-schema"; | ||
|
||
interface Props { | ||
connectionState: WebSocketState; | ||
isRunning: boolean; | ||
width: AppConfig["width"]; | ||
} | ||
|
||
export const AppContainer: React.FC<PropsWithChildren<Props>> = ({ | ||
width, | ||
connectionState, | ||
isRunning, | ||
children, | ||
}) => { | ||
return ( | ||
<> | ||
<StatusOverlay state={connectionState} isRunning={isRunning} /> | ||
<div | ||
id="App" | ||
className={cn( | ||
connectionState === WebSocketState.CLOSED && "disconnected", | ||
"bg-background w-full h-full text-textColor", | ||
"flex flex-col overflow-y-auto overflow-x-hidden", | ||
width === "full" && "config-width-full", | ||
)} | ||
> | ||
{children} | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { ConnectionStatus, WebSocketState } from "@/core/websocket/types"; | ||
import React, { PropsWithChildren } from "react"; | ||
import { Disconnected } from "../Disconnected"; | ||
|
||
interface Props { | ||
className?: string; | ||
connection: ConnectionStatus; | ||
} | ||
|
||
export const AppHeader: React.FC<PropsWithChildren<Props>> = ({ | ||
connection, | ||
className, | ||
children, | ||
}) => { | ||
return ( | ||
<div className={className}> | ||
{children} | ||
{connection.state === WebSocketState.CLOSED && ( | ||
<Disconnected reason={connection.reason} /> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { Tooltip } from "@/components/ui/tooltip"; | ||
import { notebookScrollToRunning } from "@/core/cells/actions"; | ||
import { WebSocketState } from "@/core/websocket/types"; | ||
import { UnlinkIcon, HourglassIcon } from "lucide-react"; | ||
import React from "react"; | ||
|
||
export const StatusOverlay: React.FC<{ | ||
state: WebSocketState; | ||
isRunning: boolean; | ||
}> = ({ state, isRunning }) => { | ||
return ( | ||
<> | ||
{state === WebSocketState.OPEN && isRunning && <RunningIcon />} | ||
{state === WebSocketState.CLOSED && <NoiseBackground />} | ||
{state === WebSocketState.CLOSED && <DisconnectedIcon />} | ||
</> | ||
); | ||
}; | ||
|
||
const topLeftStatus = | ||
"absolute top-3 left-4 m-0 flex items-center space-x-3 min-h-[28px] no-print pointer-events-auto z-30"; | ||
|
||
const DisconnectedIcon = () => ( | ||
<Tooltip content="App disconnected"> | ||
<div className={topLeftStatus}> | ||
<UnlinkIcon className="closed-app-icon" /> | ||
</div> | ||
</Tooltip> | ||
); | ||
|
||
const RunningIcon = () => ( | ||
<div | ||
className={topLeftStatus} | ||
data-testid="loading-indicator" | ||
title={"Marimo is busy computing. Hang tight!"} | ||
onClick={notebookScrollToRunning} | ||
> | ||
<HourglassIcon className="running-app-icon" size={30} strokeWidth={1} /> | ||
</div> | ||
); | ||
|
||
const NoiseBackground = () => ( | ||
<> | ||
<div className="noise" /> | ||
<div className="disconnected-gradient" /> | ||
</> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { EditApp } from "@/core/edit-app"; | ||
import { AppChrome } from "../editor/chrome/wrapper/app-chrome"; | ||
import { CommandPalette } from "../editor/controls/command-palette"; | ||
import { AppConfig, UserConfig } from "@/core/config/config-schema"; | ||
|
||
interface Props { | ||
userConfig: UserConfig; | ||
appConfig: AppConfig; | ||
} | ||
|
||
const EditPage = (props: Props) => { | ||
return ( | ||
<AppChrome> | ||
<EditApp {...props} /> | ||
<CommandPalette /> | ||
</AppChrome> | ||
); | ||
}; | ||
|
||
export default EditPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { AppConfig } from "@/core/config/config-schema"; | ||
import { RunApp } from "@/core/run-app"; | ||
import { StaticBanner } from "../static-html/static-banner"; | ||
|
||
interface Props { | ||
appConfig: AppConfig; | ||
} | ||
|
||
const RunPage = (props: Props) => { | ||
return ( | ||
<> | ||
<StaticBanner /> | ||
<RunApp appConfig={props.appConfig} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default RunPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
|
||
import { store } from "../state/jotai"; | ||
import { Objects } from "@/utils/objects"; | ||
import { EditorView } from "@codemirror/view"; | ||
import { getCellEditorView, notebookAtom } from "./cells"; | ||
|
||
/** | ||
* Scroll to the first cell that is currently in "running" state. | ||
*/ | ||
export function notebookScrollToRunning() { | ||
// find cell that is currently in "running" state | ||
const { cellRuntime } = store.get(notebookAtom); | ||
const cell = Objects.entries(cellRuntime).find( | ||
([cellid, runtimestate]) => runtimestate.status === "running", | ||
); | ||
if (!cell) { | ||
return; | ||
} | ||
const view = getCellEditorView(cell[0]); | ||
view?.dispatch({ | ||
selection: { anchor: 0 }, | ||
effects: [EditorView.scrollIntoView(0, { y: "center" })], | ||
}); | ||
} |
Oops, something went wrong.