Fetch nym and photoId
This commit is contained in:
parent
c610f20773
commit
369328da15
|
@ -66,8 +66,9 @@ export default {
|
|||
|
||||
return await models.user.findUnique({ where: { id: me.id } })
|
||||
},
|
||||
user: async (parent, { name }, { models }) => {
|
||||
return await models.user.findUnique({ where: { name } })
|
||||
user: async (parent, { id, name }, { models }) => {
|
||||
if (id) id = Number(id)
|
||||
return await models.user.findUnique({ where: { id, name } })
|
||||
},
|
||||
users: async (parent, args, { models }) =>
|
||||
await models.user.findMany(),
|
||||
|
|
|
@ -4,7 +4,7 @@ export default gql`
|
|||
extend type Query {
|
||||
me: User
|
||||
settings: User
|
||||
user(name: String!): User
|
||||
user(id: ID, name: String): User
|
||||
users: [User!]
|
||||
nameAvailable(name: String!): Boolean!
|
||||
topUsers(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Users
|
||||
|
|
|
@ -6,6 +6,8 @@ import { useMe, useMeRefresh } from './me'
|
|||
import Image from 'react-bootstrap/Image'
|
||||
import Link from 'next/link'
|
||||
import { SSR } from '../lib/constants'
|
||||
import { USER } from '../fragments/users'
|
||||
import { useQuery } from '@apollo/client'
|
||||
|
||||
const AccountContext = createContext()
|
||||
|
||||
|
@ -73,9 +75,22 @@ const AnonAccount = ({ selected, onClick }) => {
|
|||
|
||||
const Account = ({ account, className }) => {
|
||||
const me = useMe()
|
||||
const [name, setName] = useState(account.name)
|
||||
const [src, setSrc] = useState(account.photoId || '/dorian400.jpg')
|
||||
const refreshMe = useMeRefresh()
|
||||
const { setIsAnon } = useAccounts()
|
||||
const src = account.photoId ? `https://${process.env.NEXT_PUBLIC_MEDIA_DOMAIN}/${account.photoId}` : '/dorian400.jpg'
|
||||
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)
|
||||
}
|
||||
}
|
||||
)
|
||||
return (
|
||||
<div
|
||||
className='d-flex flex-column me-2 my-1 text-center'
|
||||
|
@ -88,7 +103,7 @@ const Account = ({ account, className }) => {
|
|||
setIsAnon(false)
|
||||
}}
|
||||
/>
|
||||
<Link href={`/${account.name}`}>@{account.name}</Link>
|
||||
<Link href={`/${account.name}`}>@{name}</Link>
|
||||
{Number(me?.id) === Number(account.id) && <div className='text-muted fst-italic'>selected</div>}
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -235,8 +235,8 @@ export const USER_FULL = gql`
|
|||
|
||||
export const USER = gql`
|
||||
${USER_FIELDS}
|
||||
query User($name: String!) {
|
||||
user(name: $name) {
|
||||
query User($id: ID, $name: String) {
|
||||
user(id: $id, name: $name) {
|
||||
...UserFields
|
||||
}
|
||||
}`
|
||||
|
|
Loading…
Reference in New Issue