Simplify PDF embed

This commit is contained in:
Ahmed Al-Taiar
2024-10-09 20:32:39 -04:00
parent 74db2e1034
commit 82313bef46
5 changed files with 27 additions and 40 deletions

View File

@ -0,0 +1,19 @@
interface PDFProps {
url: string
form?: boolean
}
const PDF = ({ url, form = false }: PDFProps) => (
<embed
src={url}
title="PDF"
type="application/pdf"
style={{
width: 'calc(100vw - 1rem)',
height: `calc(100vh - ${form ? '8.5rem' : '6rem'})`,
}}
className="rounded-xl"
/>
)
export default PDF

View File

@ -102,7 +102,7 @@ const PortraitForm = ({ portrait }: PortraitFormProps) => {
return ( return (
<div className="mx-auto w-fit space-y-2"> <div className="mx-auto w-fit space-y-2">
<img <img
className="aspect-portrait max-w-2xl rounded-xl object-cover" className="aspect-portrait max-w-80 sm:max-w-sm md:max-w-md lg:max-w-lg xl:max-w-xl 2xl:max-w-2xl rounded-xl object-cover"
src={portrait?.fileId} src={portrait?.fileId}
alt={`${process.env.FIRST_NAME} Portrait`} alt={`${process.env.FIRST_NAME} Portrait`}
/> />

View File

@ -1,26 +1,11 @@
import { useState } from 'react'
import { Resume as ResumeType } from 'types/graphql' import { Resume as ResumeType } from 'types/graphql'
import PDF from 'src/components/PDF/PDF'
interface ResumeProps { interface ResumeProps {
resume?: ResumeType resume?: ResumeType
} }
const Resume = ({ resume }: ResumeProps) => { const Resume = ({ resume }: ResumeProps) => <PDF url={resume?.fileId} />
const [fileId] = useState<string>(resume?.fileId)
return (
<object
data={fileId}
type="application/pdf"
aria-label="Resume PDF"
style={{
width: 'calc(100vw - 1rem)',
height: 'calc(100vh - 6rem)',
}}
className="rounded-xl"
/>
)
}
export default Resume export default Resume

View File

@ -14,6 +14,7 @@ import type {
import { TypedDocumentNode, useMutation } from '@redwoodjs/web' import { TypedDocumentNode, useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast' import { toast } from '@redwoodjs/web/toast'
import PDF from 'src/components/PDF/PDF'
import Uploader from 'src/components/Uploader/Uploader' import Uploader from 'src/components/Uploader/Uploader'
import { deleteFile, handleBeforeUnload } from 'src/lib/tus' import { deleteFile, handleBeforeUnload } from 'src/lib/tus'
@ -100,16 +101,7 @@ const ResumeForm = ({ resume }: ResumeFormProps) => {
if (resume?.fileId) if (resume?.fileId)
return ( return (
<div className="mx-auto w-fit space-y-2"> <div className="mx-auto w-fit space-y-2">
<object <PDF form url={resume?.fileId} />
data={resume?.fileId}
type="application/pdf"
aria-label="Resume PDF"
style={{
width: 'calc(100vw - 1rem)',
height: 'calc(100vh - 10rem)',
}}
className="rounded-xl"
/>
<div className="flex justify-center"> <div className="flex justify-center">
<button <button
type="button" type="button"
@ -143,16 +135,7 @@ const ResumeForm = ({ resume }: ResumeFormProps) => {
/> />
</> </>
) : ( ) : (
<object <PDF form url={fileId} />
data={fileId}
type="application/pdf"
aria-label="Resume PDF"
style={{
width: 'calc(100vw - 1rem)',
height: 'calc(100vh - 10rem)',
}}
className="rounded-xl"
/>
)} )}
{fileId && ( {fileId && (
<div className="flex justify-center space-x-2"> <div className="flex justify-center space-x-2">

View File

@ -97,7 +97,7 @@ const TitlesForm = ({ titles }: TitlesFormProps) => {
<nav className="my-2 flex justify-center space-x-2"> <nav className="my-2 flex justify-center space-x-2">
<button <button
type="button" type="button"
className="btn btn-sm" className="btn btn-sm uppercase"
onClick={() => setPreview(!preview)} onClick={() => setPreview(!preview)}
> >
{preview ? 'Hide' : 'Show'} Preview {preview ? 'Hide' : 'Show'} Preview