top cowboys
This commit is contained in:
parent
a5b2de64d3
commit
97f74da0fd
|
@ -90,6 +90,20 @@ export default {
|
|||
|
||||
return user.name?.toUpperCase() === name?.toUpperCase() || !(await models.user.findUnique({ where: { name } }))
|
||||
},
|
||||
topCowboys: async (parent, { cursor }, { models, me }) => {
|
||||
const decodedCursor = decodeCursor(cursor)
|
||||
const users = await models.$queryRaw(`
|
||||
SELECT users.*
|
||||
FROM users
|
||||
WHERE NOT "hideFromTopUsers" AND streak IS NOT NULL
|
||||
ORDER BY streak DESC, created_at ASC
|
||||
OFFSET $1
|
||||
LIMIT ${LIMIT}`, decodedCursor.offset)
|
||||
return {
|
||||
cursor: users.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
|
||||
users
|
||||
}
|
||||
},
|
||||
topUsers: async (parent, { cursor, when, sort }, { models, me }) => {
|
||||
const decodedCursor = decodeCursor(cursor)
|
||||
let users
|
||||
|
@ -151,7 +165,7 @@ export default {
|
|||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
||||
} else {
|
||||
users = await models.$queryRaw(`
|
||||
SELECT u.id, u.name, u."photoId", floor(sum(amount)/1000) as stacked
|
||||
SELECT u.id, u.name, u.streak, u."photoId", floor(sum(amount)/1000) as stacked
|
||||
FROM
|
||||
((SELECT users.*, "ItemAct".msats as amount
|
||||
FROM "ItemAct"
|
||||
|
@ -172,7 +186,7 @@ export default {
|
|||
JOIN users on users.id = "ReferralAct"."referrerId"
|
||||
WHERE "ReferralAct".msats > 0 ${within('ReferralAct', when)}
|
||||
AND NOT users."hideFromTopUsers")) u
|
||||
GROUP BY u.id, u.name, u.created_at, u."photoId"
|
||||
GROUP BY u.id, u.name, u.created_at, u."photoId", u.streak
|
||||
ORDER BY stacked DESC NULLS LAST, created_at DESC
|
||||
OFFSET $2
|
||||
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
|
||||
|
|
|
@ -8,6 +8,7 @@ export default gql`
|
|||
users: [User!]
|
||||
nameAvailable(name: String!): Boolean!
|
||||
topUsers(cursor: String, when: String, sort: String): Users
|
||||
topCowboys(cursor: String): Users
|
||||
searchUsers(q: String!, limit: Int, similarity: Float): [User!]!
|
||||
hasNewNotes: Boolean!
|
||||
}
|
||||
|
|
|
@ -10,6 +10,13 @@ export default function TopHeader ({ cat }) {
|
|||
const top = async values => {
|
||||
const { what, when, ...query } = values
|
||||
|
||||
if (what === 'cowboys') {
|
||||
await router.push({
|
||||
pathname: `/top/${what}`
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof query.sort !== 'undefined') {
|
||||
if (query.sort === '' ||
|
||||
(what === 'users' && !USER_SORTS.includes(query.sort)) ||
|
||||
|
@ -19,7 +26,7 @@ export default function TopHeader ({ cat }) {
|
|||
}
|
||||
|
||||
await router.push({
|
||||
pathname: `/top/${what}/${when}`,
|
||||
pathname: `/top/${what}/${when || 'day'}`,
|
||||
query
|
||||
})
|
||||
}
|
||||
|
@ -42,24 +49,28 @@ export default function TopHeader ({ cat }) {
|
|||
onChange={(formik, e) => top({ ...formik?.values, what: e.target.value })}
|
||||
name='what'
|
||||
size='sm'
|
||||
items={['posts', 'comments', 'users']}
|
||||
/>
|
||||
by
|
||||
<Select
|
||||
groupClassName='mx-2 mb-0'
|
||||
onChange={(formik, e) => top({ ...formik?.values, sort: e.target.value })}
|
||||
name='sort'
|
||||
size='sm'
|
||||
items={cat === 'users' ? USER_SORTS : ITEM_SORTS}
|
||||
/>
|
||||
for
|
||||
<Select
|
||||
groupClassName='mb-0 ml-2'
|
||||
onChange={(formik, e) => top({ ...formik?.values, when: e.target.value })}
|
||||
name='when'
|
||||
size='sm'
|
||||
items={['day', 'week', 'month', 'year', 'forever']}
|
||||
items={['posts', 'comments', 'users', 'cowboys']}
|
||||
/>
|
||||
{cat !== 'cowboys' &&
|
||||
<>
|
||||
by
|
||||
<Select
|
||||
groupClassName='mx-2 mb-0'
|
||||
onChange={(formik, e) => top({ ...formik?.values, sort: e.target.value })}
|
||||
name='sort'
|
||||
size='sm'
|
||||
items={cat === 'users' ? USER_SORTS : ITEM_SORTS}
|
||||
/>
|
||||
for
|
||||
<Select
|
||||
groupClassName='mb-0 ml-2'
|
||||
onChange={(formik, e) => top({ ...formik?.values, when: e.target.value })}
|
||||
name='when'
|
||||
size='sm'
|
||||
items={['day', 'week', 'month', 'year', 'forever']}
|
||||
/>
|
||||
</>}
|
||||
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
|
|
|
@ -151,6 +151,24 @@ export const TOP_USERS = gql`
|
|||
}
|
||||
`
|
||||
|
||||
export const TOP_COWBOYS = gql`
|
||||
query TopCowboys($cursor: String) {
|
||||
topCowboys(cursor: $cursor) {
|
||||
users {
|
||||
name
|
||||
streak
|
||||
photoId
|
||||
stacked(when: "forever")
|
||||
spent(when: "forever")
|
||||
ncomments(when: "forever")
|
||||
nitems(when: "forever")
|
||||
referrals(when: "forever")
|
||||
}
|
||||
cursor
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const USER_FULL = gql`
|
||||
${USER_FIELDS}
|
||||
${ITEM_WITH_COMMENTS}
|
||||
|
|
|
@ -49,6 +49,19 @@ function getClient (uri) {
|
|||
}
|
||||
}
|
||||
},
|
||||
topCowboys: {
|
||||
keyArgs: [],
|
||||
merge (existing, incoming) {
|
||||
if (isFirstPage(incoming.cursor, existing?.users)) {
|
||||
return incoming
|
||||
}
|
||||
|
||||
return {
|
||||
cursor: incoming.cursor,
|
||||
users: [...(existing?.users || []), ...incoming.users]
|
||||
}
|
||||
}
|
||||
},
|
||||
items: {
|
||||
keyArgs: ['sub', 'sort', 'type', 'name', 'within'],
|
||||
merge (existing, incoming) {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import Layout from '../../components/layout'
|
||||
import { getGetServerSideProps } from '../../api/ssrApollo'
|
||||
import TopHeader from '../../components/top-header'
|
||||
import { TOP_COWBOYS } from '../../fragments/users'
|
||||
import { useQuery } from '@apollo/client'
|
||||
import MoreFooter from '../../components/more-footer'
|
||||
import UserList, { UsersSkeleton } from '../../components/user-list'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps(TOP_COWBOYS)
|
||||
|
||||
export default function Index ({ data: { topCowboys: { users, cursor } } }) {
|
||||
const { data, fetchMore } = useQuery(TOP_COWBOYS)
|
||||
|
||||
if (data) {
|
||||
({ topCowboys: { users, cursor } } = data)
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<TopHeader cat='cowboys' />
|
||||
<UserList users={users} />
|
||||
<MoreFooter cursor={cursor} fetchMore={fetchMore} Skeleton={UsersSkeleton} />
|
||||
</Layout>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue