Refetch active queries on account switch
This commit is contained in:
		
							parent
							
								
									1845db2da3
								
							
						
					
					
						commit
						25d5bb53bb
					
				@ -4,7 +4,7 @@ import cookie from 'cookie'
 | 
				
			|||||||
import { useMe } from './me'
 | 
					import { useMe } from './me'
 | 
				
			||||||
import { ANON_USER_ID, SSR } from '../lib/constants'
 | 
					import { ANON_USER_ID, SSR } from '../lib/constants'
 | 
				
			||||||
import { USER } from '../fragments/users'
 | 
					import { USER } from '../fragments/users'
 | 
				
			||||||
import { useQuery } from '@apollo/client'
 | 
					import { useApolloClient, useQuery } from '@apollo/client'
 | 
				
			||||||
import { UserListRow } from './user-list'
 | 
					import { UserListRow } from './user-list'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const AccountContext = createContext()
 | 
					const AccountContext = createContext()
 | 
				
			||||||
@ -73,6 +73,7 @@ const AccountListRow = ({ account, ...props }) => {
 | 
				
			|||||||
  const { me, refreshMe } = useMe()
 | 
					  const { me, refreshMe } = useMe()
 | 
				
			||||||
  const anonRow = account.id === ANON_USER_ID
 | 
					  const anonRow = account.id === ANON_USER_ID
 | 
				
			||||||
  const selected = (isAnon && anonRow) || Number(me?.id) === Number(account.id)
 | 
					  const selected = (isAnon && anonRow) || Number(me?.id) === Number(account.id)
 | 
				
			||||||
 | 
					  const client = useApolloClient()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fetch updated names and photo ids since they might have changed since we were issued the JWTs
 | 
					  // fetch updated names and photo ids since they might have changed since we were issued the JWTs
 | 
				
			||||||
  const [name, setName] = useState(account.name)
 | 
					  const [name, setName] = useState(account.name)
 | 
				
			||||||
@ -100,6 +101,7 @@ const AccountListRow = ({ account, ...props }) => {
 | 
				
			|||||||
      // order is important to prevent flashes of inconsistent data in switch account dialog
 | 
					      // order is important to prevent flashes of inconsistent data in switch account dialog
 | 
				
			||||||
      setIsAnon(account.id === ANON_USER_ID)
 | 
					      setIsAnon(account.id === ANON_USER_ID)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    await client.refetchQueries({ include: 'active' })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user