mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Standardise naming of openDocId as openDocWithId or currentDocumentId (#23307)
GitOrigin-RevId: d71b6d878188c7b916f02a3749976ecd96d648a3
This commit is contained in:
@@ -51,10 +51,10 @@ export type EditorManager = {
|
||||
currentDocument: DocumentContainer
|
||||
currentDocumentId: DocId | null
|
||||
getCurrentDocValue: () => string | null
|
||||
getCurrentDocId: () => DocId | null
|
||||
getCurrentDocumentId: () => DocId | null
|
||||
startIgnoringExternalUpdates: () => void
|
||||
stopIgnoringExternalUpdates: () => void
|
||||
openDocId: (docId: string, options?: OpenDocOptions) => void
|
||||
openDocWithId: (docId: string, options?: OpenDocOptions) => void
|
||||
openDoc: (document: Doc, options?: OpenDocOptions) => void
|
||||
openDocs: OpenDocuments
|
||||
openInitialDoc: (docId: string) => void
|
||||
@@ -109,7 +109,7 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
const [showVisual] = useScopeValue<boolean>('editor.showVisual')
|
||||
const [currentDocument, setCurrentDocument] =
|
||||
useScopeValue<DocumentContainer>('editor.sharejs_doc')
|
||||
const [openDocId, setOpenDocId] = useScopeValue<DocId | null>(
|
||||
const [currentDocumentId, setCurrentDocumentId] = useScopeValue<DocId | null>(
|
||||
'editor.open_doc_id'
|
||||
)
|
||||
const [, setOpenDocName] = useScopeValue<string | null>(
|
||||
@@ -191,14 +191,14 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
)
|
||||
)
|
||||
|
||||
const openDocIdStorageKey = `doc.open_id.${projectId}`
|
||||
const currentDocumentIdStorageKey = `doc.open_id.${projectId}`
|
||||
|
||||
// Persist the open document ID to local storage
|
||||
useEffect(() => {
|
||||
if (openDocId) {
|
||||
customLocalStorage.setItem(openDocIdStorageKey, openDocId)
|
||||
if (currentDocumentId) {
|
||||
customLocalStorage.setItem(currentDocumentIdStorageKey, currentDocumentId)
|
||||
}
|
||||
}, [openDocId, openDocIdStorageKey])
|
||||
}, [currentDocumentId, currentDocumentIdStorageKey])
|
||||
|
||||
const editorOpenDocEpochRef = useRef(0)
|
||||
|
||||
@@ -230,7 +230,10 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
return currentDocument?.getSnapshot() ?? null
|
||||
}, [currentDocument])
|
||||
|
||||
const getCurrentDocId = useCallback(() => openDocId, [openDocId])
|
||||
const getCurrentDocumentId = useCallback(
|
||||
() => currentDocumentId,
|
||||
[currentDocumentId]
|
||||
)
|
||||
|
||||
const startIgnoringExternalUpdates = useCallback(
|
||||
() => setIgnoringExternalUpdates(true),
|
||||
@@ -379,9 +382,9 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
// between leaving and joining the same document
|
||||
// - when the current one has pending ops that need flushing, to avoid
|
||||
// race conditions from cleanup
|
||||
const currentDocId = currentDocument?.doc_id
|
||||
const currentDocumentId = currentDocument?.doc_id
|
||||
const hasBufferedOps = currentDocument?.hasBufferedOps()
|
||||
const changingDoc = currentDocument && currentDocId !== doc._id
|
||||
const changingDoc = currentDocument && currentDocumentId !== doc._id
|
||||
if (changingDoc || hasBufferedOps) {
|
||||
debugConsole.log('[openNewDocument] Leaving existing open doc...')
|
||||
|
||||
@@ -401,7 +404,7 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
await currentDocument.leaveAndCleanUpPromise()
|
||||
} catch (error) {
|
||||
debugConsole.log(
|
||||
`[openNewDocument] error leaving doc ${currentDocId}`,
|
||||
`[openNewDocument] error leaving doc ${currentDocumentId}`,
|
||||
error
|
||||
)
|
||||
throw error
|
||||
@@ -419,10 +422,10 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
[attachErrorHandlerToDocument, doOpenNewDocument, currentDocument]
|
||||
)
|
||||
|
||||
const openDocIdRef = useRef(openDocId)
|
||||
const currentDocumentIdRef = useRef(currentDocumentId)
|
||||
useEffect(() => {
|
||||
openDocIdRef.current = openDocId
|
||||
}, [openDocId])
|
||||
currentDocumentIdRef.current = currentDocumentId
|
||||
}, [currentDocumentId])
|
||||
|
||||
const openDoc = useCallback(
|
||||
async (doc: Doc, options: OpenDocOptions = {}) => {
|
||||
@@ -468,14 +471,14 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
// If we already have the document open, or are opening the document, we can return at this point.
|
||||
// Note: only use forceReopen:true to override this when the document is
|
||||
// out of sync and needs to be reloaded from the server.
|
||||
if (doc._id === openDocIdRef.current && !options.forceReopen) {
|
||||
if (doc._id === currentDocumentIdRef.current && !options.forceReopen) {
|
||||
done(false)
|
||||
return
|
||||
}
|
||||
|
||||
// We're now either opening a new document or reloading a broken one.
|
||||
openDocIdRef.current = doc._id as DocId
|
||||
setOpenDocId(doc._id as DocId)
|
||||
currentDocumentIdRef.current = doc._id as DocId
|
||||
setCurrentDocumentId(doc._id as DocId)
|
||||
setOpenDocName(doc.name)
|
||||
setOpening(true)
|
||||
|
||||
@@ -507,7 +510,7 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
jumpToLine,
|
||||
openNewDocument,
|
||||
setCurrentDocument,
|
||||
setOpenDocId,
|
||||
setCurrentDocumentId,
|
||||
setOpenDocName,
|
||||
setOpening,
|
||||
setView,
|
||||
@@ -532,12 +535,12 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
const openInitialDoc = useCallback(
|
||||
(fallbackDocId: string) => {
|
||||
const docId =
|
||||
customLocalStorage.getItem(openDocIdStorageKey) || fallbackDocId
|
||||
customLocalStorage.getItem(currentDocumentIdStorageKey) || fallbackDocId
|
||||
if (docId) {
|
||||
openDocWithId(docId)
|
||||
}
|
||||
},
|
||||
[openDocIdStorageKey, openDocWithId]
|
||||
[currentDocumentIdStorageKey, openDocWithId]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -662,12 +665,12 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
getEditorType,
|
||||
showSymbolPalette,
|
||||
currentDocument,
|
||||
currentDocumentId: openDocId,
|
||||
currentDocumentId,
|
||||
getCurrentDocValue,
|
||||
getCurrentDocId,
|
||||
getCurrentDocumentId,
|
||||
startIgnoringExternalUpdates,
|
||||
stopIgnoringExternalUpdates,
|
||||
openDocId: openDocWithId,
|
||||
openDocWithId,
|
||||
openDoc,
|
||||
openDocs,
|
||||
openInitialDoc,
|
||||
@@ -680,9 +683,9 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||
getEditorType,
|
||||
showSymbolPalette,
|
||||
currentDocument,
|
||||
openDocId,
|
||||
currentDocumentId,
|
||||
getCurrentDocValue,
|
||||
getCurrentDocId,
|
||||
getCurrentDocumentId,
|
||||
startIgnoringExternalUpdates,
|
||||
stopIgnoringExternalUpdates,
|
||||
openDocWithId,
|
||||
|
||||
@@ -39,11 +39,8 @@ const FileTreeOpenContext = createContext<
|
||||
export const FileTreeOpenProvider: FC = ({ children }) => {
|
||||
const { rootDocId, owner } = useProjectContext()
|
||||
const { eventEmitter, projectJoined } = useIdeReactContext()
|
||||
const {
|
||||
openDocId: openDocWithId,
|
||||
currentDocumentId: openDocId,
|
||||
openInitialDoc,
|
||||
} = useEditorManagerContext()
|
||||
const { openDocWithId, currentDocumentId, openInitialDoc } =
|
||||
useEditorManagerContext()
|
||||
const { selectEntity } = useSelectFileTreeEntity()
|
||||
const [, setOpenFile] = useScopeValue<BinaryFile | null>('openFile')
|
||||
const [openEntity, setOpenEntity] = useState<
|
||||
@@ -107,14 +104,14 @@ export const FileTreeOpenProvider: FC = ({ children }) => {
|
||||
(entity: FileTreeFindResult) => {
|
||||
eventEmitter.emit('entity:deleted', entity)
|
||||
// Select the root document if the current document was deleted
|
||||
if (entity.entity._id === openDocId) {
|
||||
if (entity.entity._id === currentDocumentId) {
|
||||
openDocWithId(rootDocId!)
|
||||
}
|
||||
},
|
||||
[eventEmitter, openDocId, openDocWithId, rootDocId]
|
||||
[eventEmitter, currentDocumentId, openDocWithId, rootDocId]
|
||||
)
|
||||
|
||||
// Synchronize the file tree when openDoc or openDocId is called on the editor
|
||||
// Synchronize the file tree when openDoc or openDocWithId is called on the editor
|
||||
// manager context from elsewhere. If the file tree does change, it will
|
||||
// trigger the onSelect handler in this component, which will update the local
|
||||
// state.
|
||||
|
||||
@@ -76,7 +76,7 @@ const OnlineUsersContext = createContext<OnlineUsersContextValue | undefined>(
|
||||
export const OnlineUsersProvider: FC = ({ children }) => {
|
||||
const { eventEmitter } = useIdeReactContext()
|
||||
const { socket } = useConnectionContext()
|
||||
const [openDocId] = useScopeValue<string | null>('editor.open_doc_id')
|
||||
const [currentDocumentId] = useScopeValue<string | null>('editor.open_doc_id')
|
||||
const { fileTreeData } = useFileTreeData()
|
||||
|
||||
const [onlineUsers, setOnlineUsers] =
|
||||
@@ -235,14 +235,14 @@ export const OnlineUsersProvider: FC = ({ children }) => {
|
||||
socket.emit('clientTracking.updatePosition', {
|
||||
row: currentPosition?.row,
|
||||
column: currentPosition?.column,
|
||||
doc_id: openDocId,
|
||||
doc_id: currentDocumentId,
|
||||
})
|
||||
}, cursorUpdateInterval)
|
||||
|
||||
return () => {
|
||||
window.clearTimeout(timer)
|
||||
}
|
||||
}, [currentPosition, cursorUpdateInterval, openDocId, socket])
|
||||
}, [currentPosition, cursorUpdateInterval, currentDocumentId, socket])
|
||||
|
||||
const handleClientUpdated = useCallback(
|
||||
(client: OnlineUser) => {
|
||||
|
||||
+3
-3
@@ -138,7 +138,7 @@ function useReviewPanelState(): ReviewPanel.ReviewPanelState {
|
||||
} = project
|
||||
const { isRestrictedTokenMember } = useEditorContext()
|
||||
const {
|
||||
openDocId,
|
||||
openDocWithId,
|
||||
currentDocument,
|
||||
currentDocumentId,
|
||||
wantTrackChanges,
|
||||
@@ -845,9 +845,9 @@ function useReviewPanelState(): ReviewPanel.ReviewPanelState {
|
||||
|
||||
const gotoEntry = useCallback(
|
||||
(docId: DocId, entryOffset: number) => {
|
||||
openDocId(docId, { gotoOffset: entryOffset })
|
||||
openDocWithId(docId, { gotoOffset: entryOffset })
|
||||
},
|
||||
[openDocId]
|
||||
[openDocWithId]
|
||||
)
|
||||
|
||||
const view = reviewPanelOpen ? subView : 'mini'
|
||||
|
||||
Reference in New Issue
Block a user