|
|
@@ -8,6 +8,7 @@ import {
|
|
|
} from 'react'
|
|
|
import PropTypes from 'prop-types'
|
|
|
import useScopeValue from '../hooks/use-scope-value'
|
|
|
+import useScopeValueSetterOnly from '../hooks/use-scope-value-setter-only'
|
|
|
import usePersistedState from '../hooks/use-persisted-state'
|
|
|
import useAbortController from '../hooks/use-abort-controller'
|
|
|
import DocumentCompiler from '../../features/pdf-preview/util/compiler'
|
|
|
@@ -37,10 +38,8 @@ CompileContext.Provider.propTypes = {
|
|
|
error: PropTypes.string,
|
|
|
fileList: PropTypes.object,
|
|
|
hasChanges: PropTypes.bool.isRequired,
|
|
|
- hasLintingError: PropTypes.bool,
|
|
|
highlights: PropTypes.arrayOf(PropTypes.object),
|
|
|
logEntries: PropTypes.object,
|
|
|
- logEntryAnnotations: PropTypes.object,
|
|
|
pdfDownloadUrl: PropTypes.string,
|
|
|
pdfUrl: PropTypes.string,
|
|
|
pdfViewer: PropTypes.string,
|
|
|
@@ -75,21 +74,21 @@ export function CompileProvider({ children }) {
|
|
|
const [compiling, setCompiling] = useState(false)
|
|
|
|
|
|
// the log entries parsed from the compile output log
|
|
|
- const [logEntries, setLogEntries] = useScopeValue('pdf.logEntries')
|
|
|
+ const [logEntries, setLogEntries] = useScopeValueSetterOnly('pdf.logEntries')
|
|
|
|
|
|
// annotations for display in the editor, built from the log entries
|
|
|
- const [logEntryAnnotations, setLogEntryAnnotations] = useScopeValue(
|
|
|
- 'pdf.logEntryAnnotations'
|
|
|
- )
|
|
|
+ const [, setLogEntryAnnotations] = useScopeValue('pdf.logEntryAnnotations')
|
|
|
|
|
|
// the PDF viewer
|
|
|
const [pdfViewer] = useScopeValue('settings.pdfViewer')
|
|
|
|
|
|
// the URL for downloading the PDF
|
|
|
- const [pdfDownloadUrl, setPdfDownloadUrl] = useScopeValue('pdf.downloadUrl')
|
|
|
+ const [pdfDownloadUrl, setPdfDownloadUrl] = useScopeValueSetterOnly(
|
|
|
+ 'pdf.downloadUrl'
|
|
|
+ )
|
|
|
|
|
|
// the URL for loading the PDF in the preview pane
|
|
|
- const [pdfUrl, setPdfUrl] = useScopeValue('pdf.url')
|
|
|
+ const [pdfUrl, setPdfUrl] = useScopeValueSetterOnly('pdf.url')
|
|
|
|
|
|
// the project is considered to be "uncompiled" if a doc has changed since the last compile started
|
|
|
const [uncompiled, setUncompiled] = useScopeValue('pdf.uncompiled')
|
|
|
@@ -161,6 +160,13 @@ export function CompileProvider({ children }) {
|
|
|
|
|
|
const { signal } = useAbortController()
|
|
|
|
|
|
+ const cleanupCompileResult = useCallback(() => {
|
|
|
+ setPdfUrl(null)
|
|
|
+ setPdfDownloadUrl(null)
|
|
|
+ setLogEntries(null)
|
|
|
+ setLogEntryAnnotations({})
|
|
|
+ }, [setPdfUrl, setPdfDownloadUrl, setLogEntries, setLogEntryAnnotations])
|
|
|
+
|
|
|
// the document compiler
|
|
|
const [compiler] = useState(() => {
|
|
|
return new DocumentCompiler({
|
|
|
@@ -170,6 +176,7 @@ export function CompileProvider({ children }) {
|
|
|
setData,
|
|
|
setFirstRenderDone,
|
|
|
setError,
|
|
|
+ cleanupCompileResult,
|
|
|
signal,
|
|
|
})
|
|
|
})
|
|
|
@@ -215,11 +222,6 @@ export function CompileProvider({ children }) {
|
|
|
if (data) {
|
|
|
if (data.clsiServerId) {
|
|
|
setClsiServerId(data.clsiServerId) // set in scope, for PdfSynctexController
|
|
|
- compiler.clsiServerId = data.clsiServerId
|
|
|
- }
|
|
|
-
|
|
|
- if (data.compileGroup) {
|
|
|
- compiler.compileGroup = data.compileGroup
|
|
|
}
|
|
|
|
|
|
if (data.outputFiles) {
|
|
|
@@ -304,7 +306,6 @@ export function CompileProvider({ children }) {
|
|
|
}
|
|
|
}
|
|
|
}, [
|
|
|
- compiler,
|
|
|
data,
|
|
|
ide,
|
|
|
hasPremiumCompile,
|
|
|
@@ -422,10 +423,8 @@ export function CompileProvider({ children }) {
|
|
|
error,
|
|
|
fileList,
|
|
|
hasChanges,
|
|
|
- hasLintingError,
|
|
|
highlights,
|
|
|
logEntries,
|
|
|
- logEntryAnnotations,
|
|
|
pdfDownloadUrl,
|
|
|
pdfUrl,
|
|
|
pdfViewer,
|
|
|
@@ -433,7 +432,6 @@ export function CompileProvider({ children }) {
|
|
|
rawLog,
|
|
|
recompileFromScratch,
|
|
|
setAutoCompile,
|
|
|
- setClearingCache,
|
|
|
setCompiling,
|
|
|
setDraft,
|
|
|
setError,
|
|
|
@@ -461,10 +459,8 @@ export function CompileProvider({ children }) {
|
|
|
error,
|
|
|
fileList,
|
|
|
hasChanges,
|
|
|
- hasLintingError,
|
|
|
highlights,
|
|
|
logEntries,
|
|
|
- logEntryAnnotations,
|
|
|
position,
|
|
|
pdfDownloadUrl,
|
|
|
pdfUrl,
|
|
|
@@ -474,7 +470,7 @@ export function CompileProvider({ children }) {
|
|
|
setAutoCompile,
|
|
|
setDraft,
|
|
|
setError,
|
|
|
- setHasLintingError,
|
|
|
+ setHasLintingError, // only for stories
|
|
|
setHighlights,
|
|
|
setPosition,
|
|
|
setStopOnValidationError,
|