Skip to content
Snippets Groups Projects
Commit f2d9d8a7 authored by Jure's avatar Jure
Browse files

fix: use polling in a dead-end tree location to prevent rerenders

parent 5a9a42f1
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import Menu from './Menu'
import { Spinner } from './shared'
import currentRolesVar from '../shared/currentRolesVar'
import RolesUpdater from './RolesUpdater'
const getParams = routerPath => {
const path = '/journal/versions/:version'
......@@ -79,10 +80,7 @@ const AdminPage = ({ children, history, match }) => {
const journal = useContext(JournalContext)
const [conversion] = useContext(XpubContext)
// Get the current user every 5 seconds (this includes authorization info)
const { loading, error, data } = useQuery(GET_CURRENT_USER, {
pollInterval: 5000,
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
// TODO: useCallback used because of bug: https://github.com/apollographql/apollo-client/issues/6301
onCompleted: useCallback(data => updateStuff(data), []),
......@@ -199,7 +197,7 @@ const AdminPage = ({ children, history, match }) => {
path="/journal/admin/manuscripts"
/>
</Switch>
{/* <Router history={history}>{children}</Router> */}
<RolesUpdater />
</Root>
)
}
......
import { useCallback } from 'react'
import { useQuery } from '@apollo/client'
import { GET_CURRENT_USER } from '../queries'
import currentRolesVar from '../shared/currentRolesVar'
const updateStuff = data => {
if (data?.currentUser) {
return currentRolesVar(data.currentUser._currentRoles)
}
}
const RolesUpdater = ({ children, history, match }) => {
// This updates the current roles app-wide using Apollo's makeVar
useQuery(GET_CURRENT_USER, {
pollInterval: 5000,
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
// TODO: useCallback used because of bug: https://github.com/apollographql/apollo-client/issues/6301
onCompleted: useCallback(data => updateStuff(data), []),
})
return null
}
export default RolesUpdater
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment