diff --git a/components/FileListing.tsx b/components/FileListing.tsx
index 7886732..4b0b89b 100644
--- a/components/FileListing.tsx
+++ b/components/FileListing.tsx
@@ -18,6 +18,7 @@ import { AudioPreview } from './previews/AudioPreview'
import FourOhFour from './FourOhFour'
import TextPreview from './previews/TextPreview'
import MarkdownPreview from './previews/MarkdownPreview'
+import CodePreview from './previews/CodePreview'
// Disabling SSR for some previews (image gallery view, and PDF view)
const ReactViewer = dynamic(() => import('react-viewer'), { ssr: false })
@@ -198,7 +199,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =
return
case preview.code:
- return
code
+ return
case preview.markdown:
return
diff --git a/components/previews/CodePreview.tsx b/components/previews/CodePreview.tsx
new file mode 100644
index 0000000..37a2a1f
--- /dev/null
+++ b/components/previews/CodePreview.tsx
@@ -0,0 +1,50 @@
+import { useEffect, FunctionComponent } from 'react'
+import useSWR from 'swr'
+import axios from 'axios'
+import Prism from 'prismjs'
+
+import { getExtension } from '../../utils/getFileIcon'
+import FourOhFour from '../FourOhFour'
+import Loading from '../Loading'
+import DownloadBtn from '../DownloadBtn'
+
+const fetcher = (url: string) => axios.get(url).then(res => res.data)
+
+const CodePreview: FunctionComponent<{ file: any }> = ({ file }) => {
+ const { data, error } = useSWR(file['@microsoft.graph.downloadUrl'], fetcher)
+ useEffect(() => {
+ if (typeof window !== 'undefined') {
+ Prism.highlightAll()
+ }
+ }, [data])
+
+ if (error) {
+ return (
+
+
+
+ )
+ }
+ if (!data) {
+ return (
+
+
+
+ )
+ }
+
+ return (
+ <>
+
+
+
+
+ >
+ )
+}
+
+export default CodePreview