top users
This commit is contained in:
parent
3e17eb1688
commit
a126d5fa94
@ -31,11 +31,6 @@ export default function Header () {
|
|||||||
const path = router.asPath.split('?')[0]
|
const path = router.asPath.split('?')[0]
|
||||||
const [fired, setFired] = useState()
|
const [fired, setFired] = useState()
|
||||||
const me = useMe()
|
const me = useMe()
|
||||||
const [within, setWithin] = useState()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setWithin(localStorage.getItem('topWithin'))
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const Corner = () => {
|
const Corner = () => {
|
||||||
if (me) {
|
if (me) {
|
||||||
@ -81,7 +76,7 @@ export default function Header () {
|
|||||||
<Link href='/recent' passHref>
|
<Link href='/recent' passHref>
|
||||||
<NavDropdown.Item>recent</NavDropdown.Item>
|
<NavDropdown.Item>recent</NavDropdown.Item>
|
||||||
</Link>
|
</Link>
|
||||||
<Link href={`/top${within ? `/${within}` : ''}`} passHref>
|
<Link href='/top/posts/week' passHref>
|
||||||
<NavDropdown.Item>top</NavDropdown.Item>
|
<NavDropdown.Item>top</NavDropdown.Item>
|
||||||
</Link>
|
</Link>
|
||||||
{me
|
{me
|
||||||
@ -151,7 +146,7 @@ export default function Header () {
|
|||||||
</Link>
|
</Link>
|
||||||
</Nav.Item>
|
</Nav.Item>
|
||||||
<Nav.Item className='d-md-flex d-none'>
|
<Nav.Item className='d-md-flex d-none'>
|
||||||
<Link href={`/top${within ? `/${within}` : ''}`} passHref>
|
<Link href='/top/posts/week' passHref>
|
||||||
<Nav.Link className={styles.navLink}>top</Nav.Link>
|
<Nav.Link className={styles.navLink}>top</Nav.Link>
|
||||||
</Link>
|
</Link>
|
||||||
</Nav.Item>
|
</Nav.Item>
|
||||||
|
@ -39,6 +39,18 @@ export const USER_FIELDS = gql`
|
|||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
export const TOP_USERS = gql`
|
||||||
|
query TopUsers($cursor: String, $within: String!) {
|
||||||
|
topUsers(cursor: $cursor, within: $within) {
|
||||||
|
users {
|
||||||
|
name
|
||||||
|
stacked
|
||||||
|
}
|
||||||
|
cursor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
export const USER_FULL = gql`
|
export const USER_FULL = gql`
|
||||||
${USER_FIELDS}
|
${USER_FIELDS}
|
||||||
${ITEM_WITH_COMMENTS}
|
${ITEM_WITH_COMMENTS}
|
||||||
|
@ -25,6 +25,19 @@ export default function getApolloClient () {
|
|||||||
typePolicies: {
|
typePolicies: {
|
||||||
Query: {
|
Query: {
|
||||||
fields: {
|
fields: {
|
||||||
|
topUsers: {
|
||||||
|
keyArgs: ['within'],
|
||||||
|
merge (existing, incoming) {
|
||||||
|
if (isFirstPage(incoming.cursor, existing?.users)) {
|
||||||
|
return incoming
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
cursor: incoming.cursor,
|
||||||
|
users: [...(existing?.users || []), ...incoming.users]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
moreItems: {
|
moreItems: {
|
||||||
keyArgs: ['sort', 'name', 'within'],
|
keyArgs: ['sort', 'name', 'within'],
|
||||||
merge (existing, incoming) {
|
merge (existing, incoming) {
|
||||||
|
@ -2,22 +2,50 @@ import Layout from '../../../components/layout'
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { getGetServerSideProps } from '../../../api/ssrApollo'
|
import { getGetServerSideProps } from '../../../api/ssrApollo'
|
||||||
import TopHeader from '../../../components/top-header'
|
import TopHeader from '../../../components/top-header'
|
||||||
import { MORE_FLAT_COMMENTS } from '../../../fragments/comments'
|
import { TOP_USERS } from '../../../fragments/users'
|
||||||
import CommentsFlat from '../../../components/comments-flat'
|
import { useQuery } from '@apollo/client'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import MoreFooter from '../../../components/more-footer'
|
||||||
|
|
||||||
export const getServerSideProps = getGetServerSideProps(MORE_FLAT_COMMENTS, { sort: 'top' })
|
export const getServerSideProps = getGetServerSideProps(TOP_USERS)
|
||||||
|
|
||||||
export default function Index ({ data: { moreFlatComments: { comments, cursor } } }) {
|
export default function Index ({ data: { topUsers: { users, cursor } } }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
const { data, fetchMore } = useQuery(TOP_USERS, {
|
||||||
|
variables: { within: router.query?.within }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
({ topUsers: { users, cursor } } = data)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<TopHeader cat='comments' />
|
<TopHeader cat='users' />
|
||||||
<CommentsFlat
|
{users.map(user => (
|
||||||
comments={comments} cursor={cursor}
|
<Link href={`/${user.name}`} key={user.name}>
|
||||||
variables={{ sort: 'top', within: router.query?.within }}
|
<div className='d-flex align-items-center pointer'>
|
||||||
includeParent noReply
|
<h3 className='mb-0'>@{user.name}</h3>
|
||||||
/>
|
<h2 className='ml-2 mb-0'><small className='text-success'>{user.stacked} stacked</small></h2>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
<MoreFooter cursor={cursor} fetchMore={fetchMore} Skeleton={UsersSkeleton} />
|
||||||
</Layout>
|
</Layout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function UsersSkeleton () {
|
||||||
|
const users = new Array(21).fill(null)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>{users.map((_, i) => (
|
||||||
|
<div key={i} className='d-flex align-items-center' style={{ height: '34px' }}>
|
||||||
|
<div className='clouds' style={{ width: '172px', borderRadius: '.4rem', height: '27px' }} />
|
||||||
|
<div className='ml-2 clouds' style={{ width: '137px', borderRadius: '.4rem', height: '30px', margin: '3px 0px' }} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user