-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
36 lines (32 loc) · 1.42 KB
/
App.tsx
File metadata and controls
36 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { useMemo } from 'react'
import { Config, ConfigProvider } from '../../hooks/useConfig.js'
import { getGitHubSource } from '../../lib/sources/gitHubSource.js'
import { getHttpSource } from '../../lib/sources/httpSource.js'
import { getHuggingFaceSource } from '../../lib/sources/huggingFaceSource.js'
import { getHyperparamSource } from '../../lib/sources/hyperparamSource.js'
import Page from '../Page/Page.js'
export default function App() {
const search = new URLSearchParams(location.search)
const sourceId = search.get('key') ?? ''
const row = search.get('row') === null ? undefined : Number(search.get('row'))
const col = search.get('col') === null ? undefined : Number(search.get('col'))
const source = getHuggingFaceSource(sourceId) ??
getGitHubSource(sourceId) ??
getHttpSource(sourceId) ??
getHyperparamSource(sourceId, { endpoint: location.origin })
// Memoize the config to avoid creating a new object on each render
const config: Config = useMemo(() => ({
routes: {
getSourceRouteUrl: ({ sourceId }) => `/files?key=${sourceId}`,
getCellRouteUrl: ({ sourceId, col, row }) => `/files?key=${sourceId}&col=${col}&row=${row}`,
},
}), [])
if (!source) {
return <div>Could not load a data source. You have to pass a valid source in the url.</div>
}
return (
<ConfigProvider value={config}>
<Page source={source} navigation={{ row, col }} />
</ConfigProvider>
)
}