Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💻 Notebook toolbar always on but not functional #262

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions packages/jupyter/src/ConnectionStatusTray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ThebeEventData, ThebeEventType } from 'thebe-core';
import { selectAreExecutionScopesBuilding, useExecutionScope } from './execute/index.js';

export function ConnectionStatusTray({ waitForSessions }: { waitForSessions?: boolean }) {
const { options } = useThebeOptions();
const thebe = useThebeOptions();
const { connecting, ready: serverReady, error: serverError, events } = useThebeServer();
const { slug, ready: scopeReady, state } = useExecutionScope();
const [show, setShow] = useState(false);
Expand All @@ -26,7 +26,7 @@ export function ConnectionStatusTray({ waitForSessions }: { waitForSessions?: bo
}, [events]);

useEffect(() => {
if (!options) return;
if (!thebe?.options) return;
if (busy || error) {
setShow(true);
} else if (ready) {
Expand All @@ -36,11 +36,11 @@ export function ConnectionStatusTray({ waitForSessions }: { waitForSessions?: bo
setUnsub(undefined);
}, 1000);
}
}, [options, busy, ready, error]);
}, [thebe, busy, ready, error]);

const host = options?.useBinder
const host = thebe?.options?.useBinder
? 'Binder'
: options?.useJupyterLite
: thebe?.options?.useJupyterLite
? 'JupyterLite'
: 'Local Server';

Expand All @@ -63,7 +63,7 @@ export function ConnectionStatusTray({ waitForSessions }: { waitForSessions?: bo
);
}

if (show && options?.useJupyterLite) {
if (show && thebe?.options?.useJupyterLite) {
return (
<div className="fixed p-3 z-[11] text-sm text-gray-700 bg-white border rounded shadow-lg bottom-2 sm:right-2 max-w-[90%] md:max-w-[300px] min-w-0">
<div className="mb-1 font-semibold text-center">⚡️ Connecting to {host} ⚡️</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyter/src/execute/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function ExecuteScopeProvider({
children,
contents,
}: React.PropsWithChildren<{ contents: ArticleContents }>) {
const canCompute = useCanCompute(contents);
const canCompute = useCanCompute();

// compute incoming for first render
const computables: Computable[] = listComputables(contents.mdast);
Expand Down
6 changes: 3 additions & 3 deletions packages/jupyter/src/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ThebeOptionsContextType = {
binderBadgeUrl?: string;
};

const ThebeOptionsContext = React.createContext<ThebeOptionsContextType>({});
const ThebeOptionsContext = React.createContext<ThebeOptionsContextType | undefined>(undefined);

export function ConfiguredThebeServerProvider({
siteManifest,
Expand Down Expand Up @@ -77,9 +77,9 @@ export function ConfiguredThebeServerProvider({
);
}

export function useCanCompute(article: { frontmatter: { thebe?: boolean | Record<string, any> } }) {
export function useCanCompute() {
const thebe = useContext(ThebeOptionsContext);
return !!thebe && (article.frontmatter as any)?.thebe !== false;
return !!thebe?.options;
}

export function useThebeOptions() {
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/pages/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const ArticlePage = React.memo(function ({
showAbstract?: boolean;
hideKeywords?: boolean;
}) {
const canCompute = useCanCompute(article);
const canCompute = useCanCompute();

const { hide_title_block, hide_footer_links } = (article.frontmatter as any)?.design ?? {};

const tree = copyNode(article.mdast);
Expand Down
30 changes: 14 additions & 16 deletions themes/article/app/routes/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ import {
Abstract,
Keywords,
} from '@myst-theme/site';
import {
ErrorTray,
LaunchBinder,
NotebookToolbar,
useCanCompute,
useThebeOptions,
} from '@myst-theme/jupyter';
import { ErrorTray, LaunchBinder, NotebookToolbar, useCanCompute } from '@myst-theme/jupyter';
import { FrontmatterBlock } from '@myst-theme/frontmatter';
import { ArrowLeftIcon } from '@heroicons/react/24/outline';
import { DocumentArrowDownIcon } from '@heroicons/react/24/outline';
Expand Down Expand Up @@ -140,9 +134,8 @@ export function Article({
const tree = copyNode(article.mdast);
const abstract = extractPart(tree, 'abstract');
const { title, subtitle } = article.frontmatter;
const canCompute = useCanCompute();

const thebe = useThebeOptions();
const canCompute = !!thebe && (article.frontmatter as any)?.thebe !== false;
// TODO in lieu of extended frontmatter or theme options
const enable_notebook_toolbar = false;
return (
Expand Down Expand Up @@ -182,6 +175,7 @@ export function ArticlePage({ article }: { article: PageLoader }) {
ArticleTemplateOptions;
const Link = useLinkProvider();
const baseurl = useBaseurl();
const canCompute = useCanCompute();
const project = projects?.[0];
const isIndex = article.slug === project?.index;

Expand All @@ -195,11 +189,13 @@ export function ArticlePage({ article }: { article: PageLoader }) {
<ArticleHeader frontmatter={project as any}>
<div className="pt-5 md:self-center h-fit lg:pt-0 col-body lg:col-margin-right-inset">
<Downloads />
<div className="col-margin mt-3 mx-5 lg:mt-2 lg:mx-0 lg:w-[300px]">
<div className="flex flex-wrap gap-2 lg:flex-col w-[147px] pl-[1px] lg:mx-auto">
<LaunchBinder style="link" location={article.location} />
{canCompute && (
<div className="col-margin mt-3 mx-5 lg:mt-2 lg:mx-0 lg:w-[300px]">
<div className="flex flex-wrap gap-2 lg:flex-col w-[147px] pl-[1px] lg:mx-auto">
<LaunchBinder style="link" location={article.location} />
</div>
</div>
</div>
)}
</div>
</ArticleHeader>
<main
Expand All @@ -222,9 +218,11 @@ export function ArticlePage({ article }: { article: PageLoader }) {
<span>Back to Article</span>
</Link>
<div className="flex-grow text-center">{article.frontmatter.title}</div>
<div className="mr-2">
<LaunchBinder style="button" location={article.location} />
</div>
{canCompute && (
<div className="mr-2">
<LaunchBinder style="button" location={article.location} />
</div>
)}
<a
href={article.frontmatter?.exports?.[0]?.url}
className="flex gap-1 px-2 py-1 font-normal no-underline border rounded bg-slate-200 border-slate-600 hover:bg-slate-800 hover:text-white hover:border-transparent"
Expand Down
Loading