-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathViewer.tsx
More file actions
38 lines (35 loc) · 1.43 KB
/
Viewer.tsx
File metadata and controls
38 lines (35 loc) · 1.43 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
37
38
import { FileSource } from '../../lib/sources/types.js'
import { imageTypes } from '../../lib/utils.js'
import AvroView from '../AvroView/AvroView.js'
import ImageView from '../ImageView/ImageView.js'
import JsonView from '../JsonView/JsonView.js'
import MarkdownView from '../MarkdownView/MarkdownView.js'
import TableView from '../TableView/TableView.js'
import TextView from '../TextView/TextView.js'
interface ViewerProps {
source: FileSource
setError: (error: unknown) => void
setProgress: (progress: number | undefined) => void
}
/**
* Get a viewer for a file.
* Chooses viewer based on content type.
*/
export default function Viewer({ source, setError, setProgress }: ViewerProps) {
const { fileName } = source
if (fileName.endsWith('.md')) {
return <MarkdownView source={source} setError={setError} />
} else if (fileName.endsWith('.parquet') || fileName.endsWith('.csv') || fileName.endsWith('.jsonl')) {
return <TableView source={source} setError={setError} setProgress={setProgress} />
} else if (fileName.endsWith('.json')) {
return <JsonView source={source} setError={setError} />
} else if (fileName.endsWith('.avro')) {
return <AvroView source={source} setError={setError} />
} else if (imageTypes.some((type) => fileName.endsWith(type))) {
return <ImageView source={source} setError={setError} />
}
// Default to text viewer
return (
<TextView source={source} setError={setError} />
)
}