add wot page

This commit is contained in:
keyan 2022-01-17 16:38:40 -06:00
parent 1134ae6c48
commit cdfe973a65
2 changed files with 42 additions and 0 deletions

View File

@ -143,6 +143,17 @@ export default {
) rank_filter WHERE RANK = 1`)
}
break
case 'wot':
items = await models.$queryRaw(`
${SELECT}
FROM "Item"
${timedLeftJoinWeightedSats(1)}
WHERE "parentId" IS NULL AND created_at <= $1
AND "pinId" IS NULL
${timedOrderBySats(1)}
OFFSET $2
LIMIT ${LIMIT}`, decodedCursor.time, decodedCursor.offset)
break
case 'top':
items = await models.$queryRaw(`
${SELECT}
@ -656,6 +667,19 @@ function timedLeftJoinSats (num) {
GROUP BY i.id) x ON "Item".id = x.id`
}
const LEFT_JOIN_WEIGHTED_SATS_SELECT = 'SELECT i.id, SUM(CASE WHEN "ItemAct".act = \'VOTE\' THEN "ItemAct".sats * users.trust ELSE 0 END) as sats, SUM(CASE WHEN "ItemAct".act = \'BOOST\' THEN "ItemAct".sats ELSE 0 END) as boost'
function timedLeftJoinWeightedSats (num) {
return `
LEFT JOIN (
${LEFT_JOIN_WEIGHTED_SATS_SELECT}
FROM "Item" i
JOIN "ItemAct" ON i.id = "ItemAct"."itemId" AND "ItemAct".created_at <= $${num}
JOIN users on "ItemAct"."userId" = users.id
GROUP BY i.id
) x ON "Item".id = x.id`
}
const LEFT_JOIN_SATS =
`LEFT JOIN (${LEFT_JOIN_SATS_SELECT}
FROM "Item" i

18
pages/wot.js Normal file
View File

@ -0,0 +1,18 @@
import Layout from '../components/layout'
import Items from '../components/items'
import { getGetServerSideProps } from '../api/ssrApollo'
import { MORE_ITEMS } from '../fragments/items'
const variables = { sort: 'wot' }
export const getServerSideProps = getGetServerSideProps(MORE_ITEMS, variables)
export default function Index ({ data: { moreItems: { items, pins, cursor } } }) {
return (
<Layout>
<Items
items={items} pins={pins} cursor={cursor}
variables={variables} rank
/>
</Layout>
)
}