Skip to content

Commit

Permalink
improve pdf behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Dec 19, 2023
1 parent ef74aa5 commit 7df4d62
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/** ShareLatex Component */
.sl-outer {
flex: 1;
overflow: hidden;
overflow: visible;
display: flex;
flex-direction: row;
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/share-latex/pdf-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { usePDFSlick } from "@pdfslick/solid"
import { createEffect } from "solid-js"

export default function PdfViewer(props: {
pdfUrl: string | undefined
pdfUrl: string
}) {
const {
viewerRef,
Expand All @@ -16,7 +16,9 @@ export default function PdfViewer(props: {
// This requires a patch to pdfjs (see patches folder)
// https://github.com/mozilla/pdf.js/pull/17445 (contributed upstream)
// This also reloads the worker every time, but no big deal due to caching
store.pdfSlick?.loadDocument(props.pdfUrl!)
if (store.url && store.url !== props.pdfUrl) {
store.pdfSlick?.loadDocument(props.pdfUrl)
}
});

return <div class="inset-0 pdfSlick h-full" >
Expand Down
4 changes: 1 addition & 3 deletions src/components/share-latex/share-latex/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function ShareLatexComponent(
<div class="sl-panel" classList={{
'w-half': props.view() === 'Both'
}}>
<PdfViewer pdfUrl={props.pdfUrl} />
{ props.pdfUrl ? <PdfViewer pdfUrl={props.pdfUrl} /> : <div></div> }
</div>
</Show>
<Show when={props.view() === 'Log'}>
Expand All @@ -98,7 +98,6 @@ export default function ShareLatexComponent(
fullWidth
multiline
rows={props.compilationLog.split('\n').length}
// minRows={1}
label="Compilation Log"
name="compilation-log"
type="text"
Expand All @@ -108,7 +107,6 @@ export default function ShareLatexComponent(
"white-space": "pre"
}
}}
// disabled={readOnly()} // disabled not working with multiline
value={props.compilationLog}
/>
</div>
Expand Down
12 changes: 4 additions & 8 deletions src/components/share-latex/share-latex/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,17 @@ export default function ShareLatex(props: {
// Check if PDF is generated
if (!res.pdf) {
alert('Failed to compile PDF file')
// setCompilationLog(res.log)
setCompilationLog(res.log)
return
}

const data: Uint8Array = res.pdf
const blob = new Blob([data], { type: 'application/pdf' })

// Replace PDF preview -> Open a new window for now.
// URL.revokeObjectURL(previewUrl()!);
// setPreviewUrl(URL.createObjectURL(blob))
const fileUrl = URL.createObjectURL(blob)
const oldUrl = pdfUrl()
if (oldUrl) {
URL.revokeObjectURL(oldUrl)
}
if (oldUrl) URL.revokeObjectURL(oldUrl)

const fileUrl = URL.createObjectURL(blob)
setPdfUrl(fileUrl)
}

Expand Down

0 comments on commit 7df4d62

Please sign in to comment.