Merge pull request #3564 from overleaf/ta-file-auto-select-fix

[ReactFileTree] Restrict Entities Auto-Select

GitOrigin-RevId: ec82dcf1390b006f454db6589c04ca8922f3fe35
This commit is contained in:
Alf Eaton 2021-01-18 15:34:43 +00:00 committed by Copybot
parent 3144aac53f
commit 2e42a27331
2 changed files with 17 additions and 9 deletions

View file

@ -23,9 +23,13 @@ export function useFileTreeSocketListener() {
const socket = window._ide && window._ide.socket
const selectEntityIfCreatedByUser = useCallback(
(entityId, userId) => {
// hack to automatically re-open refreshed linked files
(entityId, entityName, userId) => {
if (window.user && window.user.id && window.user.id === userId) {
select(entityId)
if (window.expectingLinkedFileRefreshedSocketFor === entityName) {
select(entityId)
window.expectingLinkedFileRefreshedSocketFor = null
}
}
},
[select]
@ -86,36 +90,36 @@ export function useFileTreeSocketListener() {
useEffect(() => {
function handleDispatchCreateFolder(parentFolderId, folder, userId) {
dispatchCreateFolder(parentFolderId, folder)
selectEntityIfCreatedByUser(folder._id, userId)
}
if (socket) socket.on('reciveNewFolder', handleDispatchCreateFolder)
return () => {
if (socket)
socket.removeListener('reciveNewFolder', handleDispatchCreateFolder)
}
}, [socket, dispatchCreateFolder, selectEntityIfCreatedByUser])
}, [socket, dispatchCreateFolder])
useEffect(() => {
function handleDispatchCreateDoc(parentFolderId, doc, _source, userId) {
dispatchCreateDoc(parentFolderId, doc)
selectEntityIfCreatedByUser(doc._id, userId)
}
if (socket) socket.on('reciveNewDoc', handleDispatchCreateDoc)
return () => {
if (socket) socket.removeListener('reciveNewDoc', handleDispatchCreateDoc)
}
}, [socket, dispatchCreateDoc, selectEntityIfCreatedByUser])
}, [socket, dispatchCreateDoc])
useEffect(() => {
function handleDispatchCreateFile(
parentFolderId,
file,
_source,
_linkedFileData,
linkedFileData,
userId
) {
dispatchCreateFile(parentFolderId, file)
selectEntityIfCreatedByUser(file._id, userId)
if (linkedFileData) {
selectEntityIfCreatedByUser(file._id, file.name, userId)
}
}
if (socket) socket.on('reciveNewFile', handleDispatchCreateFile)
return () => {

View file

@ -89,6 +89,7 @@ export default App.controller('BinaryFileController', function(
$scope.refreshFile = function(file) {
$scope.refreshing = true
$scope.refreshError = null
window.expectingLinkedFileRefreshedSocketFor = file.name
ide.fileTreeManager
.refreshLinkedFile(file)
.then(function(response) {
@ -97,7 +98,10 @@ export default App.controller('BinaryFileController', function(
$timeout(
() =>
waitFor(() => ide.fileTreeManager.findEntityById(newFileId), 5000)
.then(newFile => ide.binaryFilesManager.openFile(newFile))
.then(newFile => {
ide.binaryFilesManager.openFile(newFile)
window.expectingLinkedFileRefreshedSocketFor = null
})
.catch(err => console.warn(err)),
0