|
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,66 @@ 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 ? 'primary' : 'default'} |
| 73 | + onClick={() => toggleKernel(false)} |
| 74 | + sx={{ |
| 75 | + fontWeight: !hasKernel ? 'bold' : 'normal', |
| 76 | + backgroundColor: !hasKernel ? '#0969da' : 'transparent', |
| 77 | + color: !hasKernel ? 'white' : 'inherit', |
| 78 | + '&:hover': { |
| 79 | + backgroundColor: !hasKernel ? '#0860ca' : '#f3f4f6', |
| 80 | + }, |
| 81 | + }} |
| 82 | + > |
| 83 | + No Runtime |
| 84 | + </Button> |
| 85 | + <Button |
| 86 | + variant={hasKernel ? 'primary' : 'default'} |
| 87 | + onClick={() => toggleKernel(true)} |
| 88 | + sx={{ |
| 89 | + fontWeight: hasKernel ? 'bold' : 'normal', |
| 90 | + backgroundColor: hasKernel ? '#0969da' : 'transparent', |
| 91 | + color: hasKernel ? 'white' : 'inherit', |
| 92 | + '&:hover': { |
| 93 | + backgroundColor: hasKernel ? '#0860ca' : '#f3f4f6', |
| 94 | + }, |
| 95 | + }} |
| 96 | + > |
| 97 | + With Runtime |
| 98 | + </Button> |
| 99 | + </ButtonGroup> |
| 100 | + <p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}> |
| 101 | + Current mode:{' '} |
| 102 | + <strong>{hasKernel ? 'Runtime Connected' : 'No Runtime'}</strong> |
| 103 | + </p> |
49 | 104 | </div> |
50 | | - <Jupyter startDefaultKernel> |
| 105 | + <Jupyter startDefaultKernel={hasKernel}> |
51 | 106 | <LexicalProvider> |
52 | 107 | <LexicalEditor /> |
53 | 108 | </LexicalProvider> |
|
0 commit comments