|
4 | 4 | * MIT License |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { Button } from '@primer/react'; |
| 7 | +import { useState } from 'react'; |
| 8 | +import { Button, ButtonGroup } from '@primer/react'; |
8 | 9 | import { Box } from '@datalayer/primer-addons'; |
9 | 10 | import { ThreeBarsIcon } from '@primer/octicons-react'; |
10 | 11 | import { Jupyter } from '@datalayer/jupyter-react'; |
@@ -42,12 +43,50 @@ const LexicalEditor = () => { |
42 | 43 | }; |
43 | 44 |
|
44 | 45 | export const AppSimple = () => { |
| 46 | + // Get initial state from URL or localStorage |
| 47 | + const getInitialKernelState = () => { |
| 48 | + const urlParams = new URLSearchParams(window.location.search); |
| 49 | + const kernelParam = urlParams.get('kernel'); |
| 50 | + if (kernelParam !== null) { |
| 51 | + return kernelParam === 'true'; |
| 52 | + } |
| 53 | + const stored = localStorage.getItem('hasKernel'); |
| 54 | + return stored === 'true'; |
| 55 | + }; |
| 56 | + |
| 57 | + const [hasKernel] = useState(getInitialKernelState); |
| 58 | + |
| 59 | + const toggleKernel = (newValue: boolean) => { |
| 60 | + localStorage.setItem('hasKernel', String(newValue)); |
| 61 | + const url = new URL(window.location.href); |
| 62 | + url.searchParams.set('kernel', String(newValue)); |
| 63 | + window.location.href = url.toString(); |
| 64 | + }; |
| 65 | + |
45 | 66 | return ( |
46 | 67 | <> |
47 | 68 | <div className="App"> |
48 | 69 | <h1>Jupyter UI ❤️ Lexical</h1> |
| 70 | + <ButtonGroup> |
| 71 | + <Button |
| 72 | + variant={hasKernel ? 'default' : 'primary'} |
| 73 | + onClick={() => toggleKernel(false)} |
| 74 | + > |
| 75 | + No Runtime |
| 76 | + </Button> |
| 77 | + <Button |
| 78 | + variant={hasKernel ? 'primary' : 'default'} |
| 79 | + onClick={() => toggleKernel(true)} |
| 80 | + > |
| 81 | + With Runtime |
| 82 | + </Button> |
| 83 | + </ButtonGroup> |
| 84 | + <p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}> |
| 85 | + Current mode:{' '} |
| 86 | + <strong>{hasKernel ? 'Runtime Connected' : 'No Runtime'}</strong> |
| 87 | + </p> |
49 | 88 | </div> |
50 | | - <Jupyter startDefaultKernel> |
| 89 | + <Jupyter startDefaultKernel={hasKernel}> |
51 | 90 | <LexicalProvider> |
52 | 91 | <LexicalEditor /> |
53 | 92 | </LexicalProvider> |
|
0 commit comments