mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #29028 from overleaf/mj-read-only-referencing
[web] Stop indexing references locally for read-only users GitOrigin-RevId: ab29fb155de4223d585356d94068c082d89179bb
This commit is contained in:
committed by
Copybot
parent
e3a24037fb
commit
fe3ace423c
@@ -42,7 +42,8 @@ export const ReferencesProvider: FC<React.PropsWithChildren> = ({
|
|||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
const { fileTreeData } = useFileTreeData()
|
const { fileTreeData } = useFileTreeData()
|
||||||
const { eventEmitter, projectId } = useIdeReactContext()
|
const { eventEmitter, projectId, permissionsLevel, projectJoined } =
|
||||||
|
useIdeReactContext()
|
||||||
const { socket } = useConnectionContext()
|
const { socket } = useConnectionContext()
|
||||||
const { projectSnapshot } = useProjectContext()
|
const { projectSnapshot } = useProjectContext()
|
||||||
const { openDocs } = useEditorManagerContext()
|
const { openDocs } = useEditorManagerContext()
|
||||||
@@ -82,6 +83,10 @@ export const ReferencesProvider: FC<React.PropsWithChildren> = ({
|
|||||||
|
|
||||||
const indexAllReferencesLocally = useCallback(
|
const indexAllReferencesLocally = useCallback(
|
||||||
async (shouldBroadcast: boolean) => {
|
async (shouldBroadcast: boolean) => {
|
||||||
|
if (permissionsLevel === 'readOnly') {
|
||||||
|
// Not going to search the references, so let's not index them.
|
||||||
|
return
|
||||||
|
}
|
||||||
sendMBOnce('client-side-references-index')
|
sendMBOnce('client-side-references-index')
|
||||||
abortControllerRef.current?.abort()
|
abortControllerRef.current?.abort()
|
||||||
|
|
||||||
@@ -115,7 +120,7 @@ export const ReferencesProvider: FC<React.PropsWithChildren> = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[projectSnapshot, openDocs, projectId]
|
[projectSnapshot, openDocs, projectId, permissionsLevel]
|
||||||
)
|
)
|
||||||
|
|
||||||
const indexAllReferences = clientSideReferences
|
const indexAllReferences = clientSideReferences
|
||||||
@@ -175,6 +180,16 @@ export const ReferencesProvider: FC<React.PropsWithChildren> = ({
|
|||||||
}, [indexAllReferences])
|
}, [indexAllReferences])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const doneInitialIndex = useRef(false)
|
||||||
|
useEffect(() => {
|
||||||
|
// We wait for projectJoined to ensure that the correct permission level
|
||||||
|
// has been received and stored on the client.
|
||||||
|
if (projectJoined && !doneInitialIndex.current) {
|
||||||
|
doneInitialIndex.current = true
|
||||||
|
indexAllReferences(false)
|
||||||
|
}
|
||||||
|
}, [projectJoined, indexAllReferences])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleProjectJoined = () => {
|
const handleProjectJoined = () => {
|
||||||
// We only need to grab the references when the editor first loads,
|
// We only need to grab the references when the editor first loads,
|
||||||
@@ -192,7 +207,6 @@ export const ReferencesProvider: FC<React.PropsWithChildren> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
indexAllReferences(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eventEmitter.once('project:joined', handleProjectJoined)
|
eventEmitter.once('project:joined', handleProjectJoined)
|
||||||
|
|||||||
Reference in New Issue
Block a user