Fetch nym and photoId

This commit is contained in:
ekzyis 2023-11-21 02:35:10 +01:00
parent c610f20773
commit 369328da15
4 changed files with 23 additions and 7 deletions

View File

@ -66,8 +66,9 @@ export default {
return await models.user.findUnique({ where: { id: me.id } }) return await models.user.findUnique({ where: { id: me.id } })
}, },
user: async (parent, { name }, { models }) => { user: async (parent, { id, name }, { models }) => {
return await models.user.findUnique({ where: { name } }) if (id) id = Number(id)
return await models.user.findUnique({ where: { id, name } })
}, },
users: async (parent, args, { models }) => users: async (parent, args, { models }) =>
await models.user.findMany(), await models.user.findMany(),

View File

@ -4,7 +4,7 @@ export default gql`
extend type Query { extend type Query {
me: User me: User
settings: User settings: User
user(name: String!): User user(id: ID, name: String): User
users: [User!] users: [User!]
nameAvailable(name: String!): Boolean! nameAvailable(name: String!): Boolean!
topUsers(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Users topUsers(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Users

View File

@ -6,6 +6,8 @@ import { useMe, useMeRefresh } from './me'
import Image from 'react-bootstrap/Image' import Image from 'react-bootstrap/Image'
import Link from 'next/link' import Link from 'next/link'
import { SSR } from '../lib/constants' import { SSR } from '../lib/constants'
import { USER } from '../fragments/users'
import { useQuery } from '@apollo/client'
const AccountContext = createContext() const AccountContext = createContext()
@ -73,9 +75,22 @@ const AnonAccount = ({ selected, onClick }) => {
const Account = ({ account, className }) => { const Account = ({ account, className }) => {
const me = useMe() const me = useMe()
const [name, setName] = useState(account.name)
const [src, setSrc] = useState(account.photoId || '/dorian400.jpg')
const refreshMe = useMeRefresh() const refreshMe = useMeRefresh()
const { setIsAnon } = useAccounts() 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 ( return (
<div <div
className='d-flex flex-column me-2 my-1 text-center' className='d-flex flex-column me-2 my-1 text-center'
@ -88,7 +103,7 @@ const Account = ({ account, className }) => {
setIsAnon(false) 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>} {Number(me?.id) === Number(account.id) && <div className='text-muted fst-italic'>selected</div>}
</div> </div>
) )

View File

@ -235,8 +235,8 @@ export const USER_FULL = gql`
export const USER = gql` export const USER = gql`
${USER_FIELDS} ${USER_FIELDS}
query User($name: String!) { query User($id: ID, $name: String) {
user(name: $name) { user(id: $id, name: $name) {
...UserFields ...UserFields
} }
}` }`