add recent comments

This commit is contained in:
keyan 2022-08-18 17:05:58 -05:00
parent db953bd41b
commit ccb5a81dd5
3 changed files with 31 additions and 4 deletions

View File

@ -236,6 +236,15 @@ export default {
let comments, user
switch (sort) {
case 'recent':
comments = await models.$queryRaw(`
${SELECT}
FROM "Item"
WHERE "parentId" IS NOT NULL AND created_at <= $1
ORDER BY created_at DESC
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
break
case 'user':
if (!name) {
throw new UserInputError('must supply name', { argumentName: 'name' })

18
pages/recent/comments.js Normal file
View File

@ -0,0 +1,18 @@
import Layout from '../../components/layout'
import { getGetServerSideProps } from '../../api/ssrApollo'
import { MORE_FLAT_COMMENTS } from '../../fragments/comments'
import CommentsFlat from '../../components/comments-flat'
const variables = { sort: 'recent' }
export const getServerSideProps = getGetServerSideProps(MORE_FLAT_COMMENTS, variables)
export default function Index ({ data: { moreFlatComments: { comments, cursor } } }) {
return (
<Layout>
<CommentsFlat
comments={comments} cursor={cursor}
variables={{ sort: 'recent' }} includeParent noReply
/>
</Layout>
)
}

View File

@ -1,7 +1,7 @@
import Layout from '../components/layout'
import Items from '../components/items'
import { getGetServerSideProps } from '../api/ssrApollo'
import { ITEMS } from '../fragments/items'
import Layout from '../../components/layout'
import Items from '../../components/items'
import { getGetServerSideProps } from '../../api/ssrApollo'
import { ITEMS } from '../../fragments/items'
const variables = { sort: 'recent' }
export const getServerSideProps = getGetServerSideProps(ITEMS, variables)