refactor new file download functions to new file

This commit is contained in:
spencerwooo
2021-12-17 21:21:25 +08:00
parent 9c5a6e6211
commit 93376e071e
13 changed files with 247 additions and 223 deletions
+2 -2
View File
@@ -2,13 +2,13 @@ import { useEffect, FunctionComponent } from 'react'
import Prism from 'prismjs'
import { getExtension } from '../../utils/getFileIcon'
import { useStaleSWR } from '../../utils/tools'
import { useStaleSWR } from '../../utils/fetchWithSWR'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadBtn from '../DownloadBtn'
const CodePreview: FunctionComponent<{ file: any }> = ({ file }) => {
const { data, error } = useStaleSWR(file['@microsoft.graph.downloadUrl'])
const { data, error } = useStaleSWR({ url: file['@microsoft.graph.downloadUrl'] })
useEffect(() => {
if (typeof window !== 'undefined') {
+2 -2
View File
@@ -11,14 +11,14 @@ import 'katex/dist/katex.min.css'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadBtn from '../DownloadBtn'
import { useStaleSWR } from '../../utils/tools'
import { useStaleSWR } from '../../utils/fetchWithSWR'
const MarkdownPreview: FunctionComponent<{ file: any; path: string; standalone?: boolean }> = ({
file,
path,
standalone = true,
}) => {
const { data, error } = useStaleSWR(file['@microsoft.graph.downloadUrl'])
const { data, error } = useStaleSWR({ url: file['@microsoft.graph.downloadUrl'] })
// The parent folder of the markdown file, which is also the relative image folder
const parentPath = path.substring(0, path.lastIndexOf('/'))
+2 -2
View File
@@ -3,10 +3,10 @@ import { FunctionComponent } from 'react'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadBtn from '../DownloadBtn'
import { useStaleSWR } from '../../utils/tools'
import { useStaleSWR } from '../../utils/fetchWithSWR'
const TextPreview: FunctionComponent<{ file: any }> = ({ file }) => {
const { data, error } = useStaleSWR(file['@microsoft.graph.downloadUrl'])
const { data, error } = useStaleSWR({ url: file['@microsoft.graph.downloadUrl'] })
if (error) {
return (
<div className="dark:bg-gray-900 p-3 bg-white rounded">
+1 -1
View File
@@ -6,7 +6,7 @@ import { useClipboard } from 'use-clipboard-copy'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import toast, { Toaster } from 'react-hot-toast'
import { getBaseUrl } from '../../utils/tools'
import { getBaseUrl } from "../../utils/getBaseUrl"
export const VideoPreview: FunctionComponent<{ file: any }> = ({ file }) => {
const { asPath } = useRouter()