mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-19 16:15:25 +00:00
Merge pull request #24196 from overleaf/ae-fetch-data-access
Avoid fetching unavailable project data GitOrigin-RevId: 58fd58f098af5e3eb000e31f22b403d3e28ef691
This commit is contained in:
parent
a11266471c
commit
ecc2f1f544
3 changed files with 18 additions and 4 deletions
|
@ -12,12 +12,14 @@ import { debugConsole } from '@/utils/debugging'
|
|||
import { useCallback } from 'react'
|
||||
import { PublicAccessLevel } from '../../../../../types/public-access-level'
|
||||
import { useLocation } from '@/shared/hooks/use-location'
|
||||
import { useEditorContext } from '@/shared/context/editor-context'
|
||||
|
||||
function useSocketListeners() {
|
||||
const { t } = useTranslation()
|
||||
const { socket } = useConnectionContext()
|
||||
const { projectId } = useIdeReactContext()
|
||||
const { showGenericMessageModal } = useModalsContext()
|
||||
const { permissionsLevel } = useEditorContext()
|
||||
const [, setPublicAccessLevel] = useScopeValue('project.publicAccesLevel')
|
||||
const [, setProjectMembers] = useScopeValue('project.members')
|
||||
const [, setProjectInvites] = useScopeValue('project.invites')
|
||||
|
@ -91,7 +93,7 @@ function useSocketListeners() {
|
|||
})
|
||||
}
|
||||
|
||||
if (data.invites) {
|
||||
if (data.invites && permissionsLevel === 'owner') {
|
||||
listProjectInvites(projectId)
|
||||
.then(({ invites }) => {
|
||||
if (invites) {
|
||||
|
@ -103,7 +105,7 @@ function useSocketListeners() {
|
|||
})
|
||||
}
|
||||
},
|
||||
[projectId, setProjectInvites, setProjectMembers]
|
||||
[projectId, setProjectInvites, setProjectMembers, permissionsLevel]
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
import { getJSON } from '@/infrastructure/fetch-json'
|
||||
import { useProjectContext } from '@/shared/context/project-context'
|
||||
import { UserId } from '../../../../../types/user'
|
||||
import { useEditorContext } from '@/shared/context/editor-context'
|
||||
|
||||
export type ChangesUser = {
|
||||
id: UserId
|
||||
|
@ -25,14 +26,19 @@ export const ChangesUsersContext = createContext<ChangesUsers | undefined>(
|
|||
|
||||
export const ChangesUsersProvider: FC = ({ children }) => {
|
||||
const { _id: projectId, members, owner } = useProjectContext()
|
||||
const { isRestrictedTokenMember } = useEditorContext()
|
||||
|
||||
const [changesUsers, setChangesUsers] = useState<ChangesUsers>()
|
||||
|
||||
useEffect(() => {
|
||||
if (isRestrictedTokenMember) {
|
||||
return
|
||||
}
|
||||
|
||||
getJSON<ChangesUser[]>(`/project/${projectId}/changes/users`).then(data =>
|
||||
setChangesUsers(new Map(data.map(item => [item.id, item])))
|
||||
)
|
||||
}, [projectId])
|
||||
}, [projectId, isRestrictedTokenMember])
|
||||
|
||||
// add the project owner and members to the changes users data
|
||||
const value = useMemo(() => {
|
||||
|
|
|
@ -21,6 +21,7 @@ import { deleteJSON, getJSON, postJSON } from '@/infrastructure/fetch-json'
|
|||
import RangesTracker from '@overleaf/ranges-tracker'
|
||||
import { CommentOperation } from '../../../../../types/change'
|
||||
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
|
||||
import { useEditorContext } from '@/shared/context/editor-context'
|
||||
|
||||
export type Threads = Record<ThreadId, ReviewPanelCommentThread>
|
||||
|
||||
|
@ -48,12 +49,17 @@ const ThreadsActionsContext = createContext<ThreadsActions | undefined>(
|
|||
export const ThreadsProvider: FC = ({ children }) => {
|
||||
const { _id: projectId } = useProjectContext()
|
||||
const { currentDocument } = useEditorManagerContext()
|
||||
const { isRestrictedTokenMember } = useEditorContext()
|
||||
|
||||
// const [error, setError] = useState<Error>()
|
||||
const [data, setData] = useState<Threads>()
|
||||
|
||||
// load the initial threads data
|
||||
useEffect(() => {
|
||||
if (isRestrictedTokenMember) {
|
||||
return
|
||||
}
|
||||
|
||||
const abortController = new AbortController()
|
||||
|
||||
getJSON(`/project/${projectId}/threads`, {
|
||||
|
@ -64,7 +70,7 @@ export const ThreadsProvider: FC = ({ children }) => {
|
|||
// .catch(error => {
|
||||
// setError(error)
|
||||
// })
|
||||
}, [projectId])
|
||||
}, [projectId, isRestrictedTokenMember])
|
||||
|
||||
const { socket } = useConnectionContext()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue