Refetch active queries on account switch

This commit is contained in:
ekzyis 2023-12-21 15:24:06 +01:00
parent 1845db2da3
commit 25d5bb53bb
1 changed files with 3 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import cookie from 'cookie'
import { useMe } from './me'
import { ANON_USER_ID, SSR } from '../lib/constants'
import { USER } from '../fragments/users'
import { useQuery } from '@apollo/client'
import { useApolloClient, useQuery } from '@apollo/client'
import { UserListRow } from './user-list'
const AccountContext = createContext()
@ -73,6 +73,7 @@ const AccountListRow = ({ account, ...props }) => {
const { me, refreshMe } = useMe()
const anonRow = account.id === ANON_USER_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
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
setIsAnon(account.id === ANON_USER_ID)
}
await client.refetchQueries({ include: 'active' })
}
return (