[web] convert file-list to typescript (#24354)

* [web] convert file-list to typescript

* [web] add type annotation for clsiServerId without providing default

Co-authored-by: David Powell <david.powell@overleaf.com>

---------

Co-authored-by: David Powell <david.powell@overleaf.com>
GitOrigin-RevId: 5ecb79c2540a3e46e296c6bf7f8573fb65febc3f
This commit is contained in:
Jakob Ackermann
2025-03-18 14:13:03 +00:00
committed by Copybot
parent 1117ea1b3e
commit 54f5c3115c
5 changed files with 54 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ const { NotFoundError } = require('./Errors')
const logger = require('@overleaf/logger')
// NOTE: Updating this list requires a corresponding change in
// * services/web/frontend/js/features/pdf-preview/util/file-list.js
// * services/web/frontend/js/features/pdf-preview/util/file-list.ts
const ignoreFiles = ['output.fls', 'output.fdb_latexmk']
function getContentDir(projectId, userId) {

View File

@@ -1,15 +1,19 @@
import {
CompileOutputFile,
CompileResponseData,
} from '../../../../../types/compile'
import { PdfFileDataList } from '@/features/pdf-preview/util/types'
const topFileTypes = ['bbl', 'gls', 'ind']
// NOTE: Updating this list requires a corresponding change in
// * services/clsi/app/js/OutputFileArchiveManager.js
const ignoreFiles = ['output.fls', 'output.fdb_latexmk']
export const buildFileList = (
outputFiles,
clsiServerId,
compileGroup,
outputFilesArchive
) => {
const files = { top: [], other: [] }
export function buildFileList(
outputFiles: Map<string, CompileOutputFile>,
{ clsiServerId, compileGroup, outputFilesArchive }: CompileResponseData
): PdfFileDataList {
const files: PdfFileDataList = { top: [], other: [] }
if (outputFiles) {
const params = new URLSearchParams()

View File

@@ -1,4 +1,5 @@
import React from 'react'
import { CompileOutputFile } from '../../../../../types/compile'
export type LogEntry = {
raw: string
@@ -31,8 +32,8 @@ export type SourceLocation = {
column?: number
}
export type PdfFileData = { path: string; url: string }
type PdfFileArchiveData = { path: string; url: string; fileCount: number }
export type PdfFileData = CompileOutputFile
type PdfFileArchiveData = CompileOutputFile & { fileCount: number }
export type PdfFileDataList = {
top: PdfFileData[]

View File

@@ -38,6 +38,7 @@ import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-
import { useUserSettingsContext } from '@/shared/context/user-settings-context'
import { useFeatureFlag } from '@/shared/context/split-test-context'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
import { CompileResponseData } from '../../../../types/compile'
import {
PdfScrollPosition,
usePdfScrollPosition,
@@ -167,10 +168,10 @@ export const LocalCompileProvider: FC = ({ children }) => {
useState(false)
// the id of the CLSI server which ran the compile
const [clsiServerId, setClsiServerId] = useState()
const [clsiServerId, setClsiServerId] = useState<string>()
// data received in response to a compile request
const [data, setData] = useState<Record<string, any>>()
const [data, setData] = useState<CompileResponseData>()
// the rootDocId used in the most recent compile request, which may not be the
// same as the project rootDocId. This is used to calculate correct paths when
@@ -392,14 +393,7 @@ export const LocalCompileProvider: FC = ({ children }) => {
setPdfFile(handleOutputFiles(outputFiles, projectId, data))
}
setFileList(
buildFileList(
outputFiles,
data.clsiServerId,
data.compileGroup,
data.outputFilesArchive
)
)
setFileList(buildFileList(outputFiles, data))
// handle log files
// asynchronous (TODO: cancel on new compile?)

View File

@@ -0,0 +1,35 @@
export type CompileOutputFile = {
path: string
url: string
type: string
build: string
ranges?: {
start: number
end: number
hash: string
objectId: string
}[]
contentId?: string
size?: number
// assigned by buildFileList in frontend
main?: boolean
}
export type CompileResponseData = {
fromCache?: boolean
status: string
outputFiles: CompileOutputFile[]
compileGroup?: string
clsiServerId?: string
pdfDownloadDomain?: string
pdfCachingMinChunkSize: number
validationProblems: any
stats: any
timings: any
outputFilesArchive?: CompileOutputFile
// assigned on response body by DocumentCompiler in frontend
rootDocId?: string
options: any
}