|
| 1 | +/** Stub `/sql` route. Echoes the `?url=...` query param so the demo can |
| 2 | + * prove `viewerActions` wires through end-to-end. A real consumer |
| 3 | + * would mount a DuckDB-WASM REPL here (see crashes' `SqlPage` for a |
| 4 | + * reference impl). */ |
| 5 | +import { useSearchParams } from 'react-router-dom' |
| 6 | + |
| 7 | +export function SqlStub() { |
| 8 | + const [params] = useSearchParams() |
| 9 | + const url = params.get('url') ?? '' |
| 10 | + return ( |
| 11 | + <div style={{ maxWidth: 900, margin: '0 auto', padding: '1.5em' }}> |
| 12 | + <h1 style={{ fontSize: '1.4em', margin: '0 0 0.3em' }}>SQL (stub)</h1> |
| 13 | + <p style={{ fontSize: '0.95em', opacity: 0.8, margin: '0 0 0.8em' }}> |
| 14 | + Placeholder route for the <code>viewerActions</code> demo. A real consumer would mount a |
| 15 | + DuckDB-WASM REPL here and run e.g. |
| 16 | + </p> |
| 17 | + {url ? ( |
| 18 | + <pre style={{ |
| 19 | + background: 'rgba(127,127,127,0.08)', |
| 20 | + padding: '0.6em 0.8em', |
| 21 | + borderRadius: 4, |
| 22 | + overflow: 'auto', |
| 23 | + fontSize: '0.85em', |
| 24 | + fontFamily: 'ui-monospace, monospace', |
| 25 | + whiteSpace: 'pre-wrap', |
| 26 | + }}>{`SELECT * FROM ${guessReader(url)}('${url}') LIMIT 100;`}</pre> |
| 27 | + ) : ( |
| 28 | + <p style={{ opacity: 0.7 }}>No <code>?url=...</code> provided.</p> |
| 29 | + )} |
| 30 | + <p style={{ fontSize: '0.85em', opacity: 0.65, marginTop: '1em' }}> |
| 31 | + Came from a file viewer? <a href={url} target="_blank" rel="noreferrer">open the raw file</a>. |
| 32 | + </p> |
| 33 | + </div> |
| 34 | + ) |
| 35 | +} |
| 36 | + |
| 37 | +function guessReader(url: string): string { |
| 38 | + if (/\.parquet$|\.pqt$/i.test(url)) return 'read_parquet' |
| 39 | + if (/\.csv$/i.test(url)) return 'read_csv' |
| 40 | + if (/\.tsv$/i.test(url)) return 'read_csv' |
| 41 | + return 'read_csv' |
| 42 | +} |
0 commit comments