mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #16010 from overleaf/ae-socket-listeners-usecallback
[ide-react] Wrap socket listeners in useCallback GitOrigin-RevId: 09692ac0026b6f94626eece4583ae320039a4ee9
This commit is contained in:
parent
3f98752986
commit
df472b607e
1 changed files with 56 additions and 36 deletions
|
@ -9,6 +9,8 @@ import { useConnectionContext } from '@/features/ide-react/context/connection-co
|
||||||
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
||||||
import { useModalsContext } from '@/features/ide-react/context/modals-context'
|
import { useModalsContext } from '@/features/ide-react/context/modals-context'
|
||||||
import { debugConsole } from '@/utils/debugging'
|
import { debugConsole } from '@/utils/debugging'
|
||||||
|
import { useCallback } from 'react'
|
||||||
|
import { PublicAccessLevel } from '../../../../../types/public-access-level'
|
||||||
|
|
||||||
function useSocketListeners() {
|
function useSocketListeners() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
@ -19,22 +21,37 @@ function useSocketListeners() {
|
||||||
const [, setProjectMembers] = useScopeValue('project.members')
|
const [, setProjectMembers] = useScopeValue('project.members')
|
||||||
const [, setProjectInvites] = useScopeValue('project.invites')
|
const [, setProjectInvites] = useScopeValue('project.invites')
|
||||||
|
|
||||||
useSocketListener(socket, 'project:access:revoked', () => {
|
useSocketListener(
|
||||||
|
socket,
|
||||||
|
'project:access:revoked',
|
||||||
|
useCallback(() => {
|
||||||
showGenericMessageModal(
|
showGenericMessageModal(
|
||||||
t('removed_from_project'),
|
t('removed_from_project'),
|
||||||
t(
|
t(
|
||||||
'you_have_been_removed_from_this_project_and_will_be_redirected_to_project_dashboard'
|
'you_have_been_removed_from_this_project_and_will_be_redirected_to_project_dashboard'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
}, [showGenericMessageModal, t])
|
||||||
|
)
|
||||||
|
|
||||||
useSocketListener(socket, 'project:publicAccessLevel:changed', data => {
|
useSocketListener(
|
||||||
|
socket,
|
||||||
|
'project:publicAccessLevel:changed',
|
||||||
|
useCallback(
|
||||||
|
(data: { newAccessLevel?: PublicAccessLevel }) => {
|
||||||
if (data.newAccessLevel) {
|
if (data.newAccessLevel) {
|
||||||
setPublicAccessLevel(data.newAccessLevel)
|
setPublicAccessLevel(data.newAccessLevel)
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
[setPublicAccessLevel]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
useSocketListener(socket, 'project:membership:changed', data => {
|
useSocketListener(
|
||||||
|
socket,
|
||||||
|
'project:membership:changed',
|
||||||
|
useCallback(
|
||||||
|
(data: { members?: boolean; invites?: boolean }) => {
|
||||||
if (data.members) {
|
if (data.members) {
|
||||||
listProjectMembers(projectId)
|
listProjectMembers(projectId)
|
||||||
.then(({ members }) => {
|
.then(({ members }) => {
|
||||||
|
@ -58,7 +75,10 @@ function useSocketListeners() {
|
||||||
debugConsole.error('Error fetching invites for project', err)
|
debugConsole.error('Error fetching invites for project', err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
[projectId, setProjectInvites, setProjectMembers]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useSocketListeners
|
export default useSocketListeners
|
||||||
|
|
Loading…
Reference in a new issue