diff --git a/components/header.js b/components/header.js
index a6460bdf..2aeb7adb 100644
--- a/components/header.js
+++ b/components/header.js
@@ -28,7 +28,7 @@ import { clearNotifications } from '../lib/badge'
import { useServiceWorker } from './serviceworker'
import SubSelect from './sub-select'
import { useShowModal } from './modal'
-import SwitchAccountDialog, { useAccounts } from './switch-account'
+import SwitchAccountList, { useAccounts } from './switch-account'
function WalletSummary ({ me }) {
if (!me) return null
@@ -128,7 +128,7 @@ function NavProfileMenu ({ me, dropNavKey }) {
- showModal(onClose => )}>switch account
+ showModal(onClose => )}>switch account {
const status = await multiAuthSignout()
@@ -209,7 +209,7 @@ function LurkerCorner ({ path }) {
- showModal(onClose => )}>switch account
+ showModal(onClose => )}>switch account
diff --git a/components/switch-account.js b/components/switch-account.js
index eb2afbe9..af8808f4 100644
--- a/components/switch-account.js
+++ b/components/switch-account.js
@@ -1,13 +1,11 @@
import { createContext, useCallback, useContext, useEffect, useState } from 'react'
-import AnonIcon from '../svgs/spy-fill.svg'
import { useRouter } from 'next/router'
import cookie from 'cookie'
import { useMe } from './me'
-import Image from 'react-bootstrap/Image'
-import Link from 'next/link'
-import { SSR } from '../lib/constants'
+import { ANON_USER_ID, SSR } from '../lib/constants'
import { USER } from '../fragments/users'
import { useQuery } from '@apollo/client'
+import { UserListRow } from './user-list'
const AccountContext = createContext()
@@ -62,92 +60,67 @@ export const AccountProvider = ({ children }) => {
export const useAccounts = () => useContext(AccountContext)
-const AnonAccount = ({ selected, onClick }) => {
+const AccountListRow = ({ account, ...props }) => {
const { isAnon, setIsAnon } = useAccounts()
- const { refreshMe } = useMe()
- return (
-
- {
- document.cookie = 'multi_auth.user-id=anonymous; Path=/; Secure'
- // order is important to prevent flashes of no session
- setIsAnon(true)
- await refreshMe()
- }}
- />
-
anonymous
- {isAnon &&
selected
}
-
- )
-}
+ const { me, refreshMe } = useMe()
+ const anonRow = account.id === ANON_USER_ID
+ const selected = (isAnon && anonRow) || Number(me?.id) === Number(account.id)
-const Account = ({ account, className }) => {
- const { me } = useMe()
+ // fetch updated names and photo ids since they might have changed since we were issued the JWTs
const [name, setName] = useState(account.name)
- const [src, setSrc] = useState(account.photoId || '/dorian400.jpg')
- const { refreshMe } = useMe()
- const { setIsAnon } = useAccounts()
+ const [photoId, setPhotoId] = useState(account.photoId)
useQuery(USER,
{
variables: { id: account.id },
onCompleted ({ user: { name, photoId } }) {
- if (photoId) {
- const src = `https://${process.env.NEXT_PUBLIC_MEDIA_DOMAIN}/${photoId}`
- setSrc(src)
- }
- setName(name)
+ if (photoId) setPhotoId(photoId)
+ if (name) setName(name)
}
}
)
+
+ const onClick = async () => {
+ document.cookie = `multi_auth.user-id=${anonRow ? 'anonymous' : account.id}; Path=/; Secure`
+ if (anonRow) {
+ // order is important to prevent flashes of no session
+ setIsAnon(true)
+ await refreshMe()
+ } else {
+ await refreshMe()
+ // order is important to prevent flashes of inconsistent data in switch account dialog
+ setIsAnon(account.id === ANON_USER_ID)
+ }
+ }
+ // can't show hat since we don't have access to the streak from the data available in the cookies
return (
-
- {
- document.cookie = `multi_auth.user-id=${account.id}; Path=/; Secure`
- await refreshMe()
- // order is important to prevent flashes of inconsistent data in switch account dialog
- setIsAnon(false)
- }}
- />
- @{name}
- {Number(me?.id) === Number(account.id) &&