Skip to content

Commit

Permalink
🔧 updated demo apps
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Aug 21, 2023
1 parent a3225dc commit bb46706
Show file tree
Hide file tree
Showing 5 changed files with 1,423 additions and 12 deletions.
1,407 changes: 1,407 additions & 0 deletions apps/demo-react/public/path-test.ipynb

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions apps/demo-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { useMemo, useState } from 'react';
import { ThebeBundleLoaderProvider, ThebeServerProvider } from 'thebe-react';
import { NavLink, Outlet } from 'react-router-dom';
import { NavLink, Outlet, useLocation } from 'react-router-dom';
import './App.css';
import { Connect } from './Connect';
import { ServerMode, ServerModeType } from './ServerMode';
import { ThebeStatusTray } from './ThebeStatusTray';

function App() {
const [mode, setMode] = useState<ServerModeType>('local');
const location = useLocation();

const path = location.pathname.endsWith('path-test') ? '/notebooks' : '/';

const options = useMemo(
() => ({
kernelOptions: {
name: 'Python 3',
path,
kernelName: 'python',
},
binderOptions: {
repo: 'curvenote/binder-base',
Expand Down Expand Up @@ -55,7 +59,7 @@ function App() {
</ThebeServerProvider>
</ThebeBundleLoaderProvider>

<div className="fixed top-2 right-1 text-xs">
<div className="fixed text-xs top-2 right-1">
Server icon by Ralf Schmitzer from{' '}
<a
href="https://thenounproject.com/browse/icons/term/server/"
Expand Down
6 changes: 3 additions & 3 deletions apps/demo-react/src/NotebookPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ThebeSessionProvider, ThebeRenderMimeRegistryProvider, useThebeServer } from 'thebe-react';

export function NotebookPage({ name, children }: React.PropsWithChildren<{ name: string }>) {
const { ready } = useThebeServer();
export function NotebookPage({ children }: React.PropsWithChildren) {
const { ready, config } = useThebeServer();

if (!ready) return null;
return (
<ThebeRenderMimeRegistryProvider>
<ThebeSessionProvider start name={name}>
<ThebeSessionProvider start path={config?.kernels.path}>
{children}
</ThebeSessionProvider>
</ThebeRenderMimeRegistryProvider>
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const router = createBrowserRouter([
{
path: 'nb/:notebookName',
element: (
<NotebookPage name="widgets">
<NotebookPage>
<WidgetsPage />
</NotebookPage>
),
Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/ThebeSessionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useThebeServer } from './ThebeServerProvider';
import { useRenderMimeRegistry } from './ThebeRenderMimeRegistryProvider';

interface ThebeSessionContextData {
name: string;
path: string;
session?: ThebeSession;
starting: boolean;
ready: boolean;
Expand All @@ -19,12 +19,12 @@ export const ThebeSessionContext = React.createContext<ThebeSessionContextData |

export function ThebeSessionProvider({
start = true,
name = 'default',
path = '/thebe.ipynb',
shutdownOnUnmount = false,
children,
}: React.PropsWithChildren<{
start?: boolean;
name?: string;
path?: string;
shutdownOnUnmount?: boolean;
}>) {
const { config, server, ready: serverReady } = useThebeServer();
Expand All @@ -38,7 +38,7 @@ export function ThebeSessionProvider({
const startSession = () => {
setStarting(true);
server
?.startNewSession(rendermime, { ...config?.kernels, name, path: name })
?.startNewSession(rendermime, { ...config?.kernels, path })
.then((sesh: ThebeSession | null) => {
setStarting(false);
if (sesh == null) {
Expand Down Expand Up @@ -74,7 +74,7 @@ export function ThebeSessionProvider({
return (
<ThebeSessionContext.Provider
value={{
name,
path,
starting,
ready,
session,
Expand Down

0 comments on commit bb46706

Please sign in to comment.