Skip to content

Commit

Permalink
fix: safari pdf (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterIceZ authored Jan 17, 2025
1 parent 4f89e1a commit 9530748
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions src/components/Task/Tabs/Statement.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use client'
// TODO Convert to Server Component

import { useEffect, useState } from 'react'

import Link from 'next/link'

import { Task } from '@prisma/client'
import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote'
import useSWR from 'swr'
Expand All @@ -14,14 +18,32 @@ const StatementTab = ({ task }: { task: Task }) => {
fetcher
)

const [enablePDF, setEnablePDF] = useState<boolean>(true)

useEffect(() => {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
const isMobile = /Mobi/.test(navigator.userAgent)

if (isSafari && isMobile) {
setEnablePDF(false)
}
}, [])

if (task.statement === 'PDF') {
return (
<article className="h-screen">
<embed
src={`/api/tasks/${task.id}/statement`}
width="100%"
height="100%"
/>
{!enablePDF ? (
<p>
This browser does not support inline PDFs. Please view the PDF by
clicking <Link href={`/api/tasks/${task.id}/statement`}>here</Link>.
</p>
) : (
<embed
src={`/api/tasks/${task.id}/statement`}
width="100%"
height="100%"
/>
)}
</article>
)
} else if (task.statement === 'MARKDOWN' && mdStatement) {
Expand Down

0 comments on commit 9530748

Please sign in to comment.