Skip to content

Commit 9a4b68f

Browse files
authored
add an input for the URL in hyparquet demo (#46)
* add an input for the URL in hyparquet demo * move constant outside of component
1 parent c66973c commit 9a4b68f

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

hyparquet/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default function App(): ReactNode {
5555
onError={(e) => { setError(e) }}
5656
onFileDrop={onFileDrop}
5757
onUrlDrop={onUrlDrop}>
58-
{pageProps ? <Page {...pageProps} /> : <Welcome />}
58+
{pageProps ? <Page {...pageProps} /> : <Welcome setUrl={onUrlDrop} />}
5959
</Dropzone>
6060
</Layout>
6161
}

hyparquet/src/Welcome.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
import { ReactNode, useRef } from 'react'
1+
import { type FormEvent, ReactNode, useCallback, useRef } from 'react'
22
import audioSvg from './assets/audio.svg'
33
import hyparquetMp3 from './assets/hyparquet.mp3'
44

5-
export default function Welcome(): ReactNode {
5+
const exampleUrl = 'https://hyperparam-public.s3.amazonaws.com/wiki-en-00000-of-00041.parquet'
6+
7+
interface Props {
8+
setUrl: (url: string) => void
9+
}
10+
11+
export default function Welcome({ setUrl }: Props): ReactNode {
612
const audio = useRef<HTMLAudioElement>(null)
13+
const urlRef = useRef<HTMLInputElement>(null)
714

815
function playAudio() {
916
audio.current?.play().catch(() => {
1017
console.warn('Failed to play audio')
1118
})
1219
}
1320

21+
const onSubmit = useCallback((e: FormEvent<HTMLFormElement>) => {
22+
e.preventDefault()
23+
const value = urlRef.current?.value ?? ''
24+
const url = value === '' ? exampleUrl : value
25+
setUrl(url)
26+
}, [setUrl])
27+
1428
return <div id="welcome">
1529
<div>
1630
<h1>hyparquet</h1>
@@ -25,9 +39,13 @@ export default function Welcome(): ReactNode {
2539
Online demo of <a href="https://github.com/hyparam/hyparquet">hyparquet</a>: a parser for apache parquet files.
2640
Uses <a href="https://github.com/hyparam/hightable">hightable</a> for high performance windowed table viewing.
2741
</p>
28-
<p>
29-
Drag and drop a parquet file (or url) to see your parquet data. 👀
30-
</p>
42+
<form onSubmit={onSubmit}>
43+
<label htmlFor="url">Drag and drop a parquet file (or url) to see your parquet data. 👀</label>
44+
<div className="inputGroup">
45+
<input id="url" type="url" ref={urlRef} required={false} placeholder={exampleUrl} />
46+
<button>Load</button>
47+
</div>
48+
</form>
3149
<p>
3250
Example files:
3351
</p>

hyparquet/src/index.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ h2 {
1717
margin-top: 10px;
1818
font-size: 12pt;
1919
}
20+
label {
21+
margin: 15px 0;
22+
display: block;
23+
}
2024
p {
2125
margin: 15px 0;
2226
}
@@ -35,6 +39,22 @@ sub img {
3539
cursor: pointer;
3640
}
3741

42+
input {
43+
height: 32px;
44+
}
45+
input,
46+
textarea {
47+
border: 2px solid #999;
48+
border-radius: 8px;
49+
padding: 4px 8px;
50+
transition: border 0.3s;
51+
}
52+
input:focus,
53+
textarea:focus {
54+
outline: none;
55+
border: 2px solid #99e;
56+
}
57+
3858
/* dropzone */
3959
.dropzone {
4060
display: flex;
@@ -200,6 +220,13 @@ main {
200220
margin: auto;
201221
max-width: 640px;
202222
}
223+
.inputGroup {
224+
display: flex;
225+
gap: 10px;
226+
}
227+
.inputGroup > input {
228+
flex: 1;
229+
}
203230
/* quick link buttons */
204231
.quick-links {
205232
display: flex;

icebird/src/Welcome.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function Welcome({ setTableUrl }: Props): ReactNode {
1414
const url = urlRef.current?.value ?? ''
1515
const tableUrl = url === '' ? exampleUrl : url
1616
setTableUrl(tableUrl)
17-
}, [setTableUrl, urlRef])
17+
}, [setTableUrl])
1818

1919
return <div id="welcome">
2020
<div>

0 commit comments

Comments
 (0)