add borderland

This commit is contained in:
keyan 2022-09-22 15:42:04 -05:00
parent 2c7c237fc7
commit 9c4d74888f
7 changed files with 128 additions and 43 deletions

View File

@ -292,6 +292,26 @@ export default {
items
}
},
borderlandItems: async (parent, { cursor }, { me, models }) => {
const decodedCursor = decodeCursor(cursor)
const notMine = () => {
return me ? ` AND "userId" <> ${me.id} ` : ''
}
const items = await models.$queryRaw(`
${SELECT}
FROM "Item"
WHERE "Item"."weightedVotes" - "Item"."weightedDownVotes" < 0
AND "Item"."weightedVotes" - "Item"."weightedDownVotes" > -${ITEM_FILTER_THRESHOLD}
${notMine()}
ORDER BY created_at DESC
OFFSET $1
LIMIT ${LIMIT}`, decodedCursor.offset)
return {
cursor: items.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
items
}
},
moreFlatComments: async (parent, { cursor, name, sort, within }, { me, models }) => {
const decodedCursor = decodeCursor(cursor)

View File

@ -13,6 +13,7 @@ export default gql`
auctionPosition(sub: String, id: ID, bid: Int!): Int!
itemRepetition(parentId: ID): Int!
outlawedItems(cursor: String): Items
borderlandItems(cursor: String): Items
}
type ItemActResult {

47
components/items-mixed.js Normal file
View File

@ -0,0 +1,47 @@
import { useRouter } from 'next/router'
import React from 'react'
import { ignoreClick } from '../lib/clicks'
import Comment from './comment'
import Item from './item'
import ItemJob from './item-job'
import { ItemsSkeleton } from './items'
import styles from './items.module.css'
import MoreFooter from './more-footer'
export default function MixedItems ({ rank, items, cursor, fetchMore }) {
const router = useRouter()
return (
<>
<div className={styles.grid}>
{items.map((item, i) => (
<React.Fragment key={item.id}>
{item.parentId
? (
<><div />
<div
className='pb-1 mb-1 clickToContext' onClick={e => {
if (ignoreClick(e)) {
return
}
router.push({
pathname: '/items/[id]',
query: { id: item.root.id, commentId: item.id }
}, `/items/${item.root.id}`)
}}
>
<Comment item={item} noReply includeParent clickToContext />
</div>
</>)
: (item.maxBid
? <ItemJob item={item} rank={rank && i + 1} />
: <Item item={item} rank={rank && i + 1} />)}
</React.Fragment>
))}
</div>
<MoreFooter
cursor={cursor} fetchMore={fetchMore}
Skeleton={() => <ItemsSkeleton rank={rank} startRank={items.length} />}
/>
</>
)
}

View File

@ -82,6 +82,19 @@ export const OUTLAWED_ITEMS = gql`
}
}`
export const BORDERLAND_ITEMS = gql`
${ITEM_FIELDS}
query borderlandItems($cursor: String) {
borderlandItems(cursor: $cursor) {
cursor
items {
...ItemFields
text
}
}
}`
export const POLL_FIELDS = gql`
fragment PollFields on Item {
poll {

View File

@ -65,6 +65,19 @@ export default function getApolloClient () {
}
}
},
borderlandItems: {
keyArgs: [],
merge (existing, incoming) {
if (isFirstPage(incoming.cursor, existing?.items)) {
return incoming
}
return {
cursor: incoming.cursor,
items: [...(existing?.items || []), ...incoming.items]
}
}
},
search: {
keyArgs: ['q'],
merge (existing, incoming) {

32
pages/borderland.js Normal file
View File

@ -0,0 +1,32 @@
import Layout from '../components/layout'
import { ItemsSkeleton } from '../components/items'
import { getGetServerSideProps } from '../api/ssrApollo'
import { BORDERLAND_ITEMS } from '../fragments/items'
import { useQuery } from '@apollo/client'
import MixedItems from '../components/items-mixed'
export const getServerSideProps = getGetServerSideProps(BORDERLAND_ITEMS)
export default function Index ({ data: { borderlandItems: { items, cursor } } }) {
return (
<Layout>
<Items
items={items} cursor={cursor}
/>
</Layout>
)
}
function Items ({ rank, items, cursor }) {
const { data, fetchMore } = useQuery(BORDERLAND_ITEMS)
if (!data && !items) {
return <ItemsSkeleton rank={rank} />
}
if (data) {
({ borderlandItems: { items, cursor } } = data)
}
return <MixedItems items={items} cursor={cursor} rank fetchMore={fetchMore} />
}

View File

@ -3,14 +3,7 @@ import { ItemsSkeleton } from '../components/items'
import { getGetServerSideProps } from '../api/ssrApollo'
import { OUTLAWED_ITEMS } from '../fragments/items'
import { useQuery } from '@apollo/client'
import React from 'react'
import styles from '../components/items.module.css'
import MoreFooter from '../components/more-footer'
import Item from '../components/item'
import ItemJob from '../components/item-job'
import Comment from '../components/comment'
import { ignoreClick } from '../lib/clicks'
import { useRouter } from 'next/router'
import MixedItems from '../components/items-mixed'
export const getServerSideProps = getGetServerSideProps(OUTLAWED_ITEMS)
@ -26,7 +19,6 @@ export default function Index ({ data: { outlawedItems: { items, cursor } } }) {
function Items ({ rank, items, cursor }) {
const { data, fetchMore } = useQuery(OUTLAWED_ITEMS)
const router = useRouter()
if (!data && !items) {
return <ItemsSkeleton rank={rank} />
@ -36,38 +28,5 @@ function Items ({ rank, items, cursor }) {
({ outlawedItems: { items, cursor } } = data)
}
return (
<>
<div className={styles.grid}>
{items.map((item, i) => (
<React.Fragment key={item.id}>
{item.parentId
? (
<><div />
<div
className='pb-1 mb-1 clickToContext' onClick={e => {
if (ignoreClick(e)) {
return
}
router.push({
pathname: '/items/[id]',
query: { id: item.root.id, commentId: item.id }
}, `/items/${item.root.id}`)
}}
>
<Comment item={item} noReply includeParent clickToContext />
</div>
</>)
: (item.maxBid
? <ItemJob item={item} rank={rank && i + 1} />
: <Item item={item} rank={rank && i + 1} />)}
</React.Fragment>
))}
</div>
<MoreFooter
cursor={cursor} fetchMore={fetchMore}
Skeleton={() => <ItemsSkeleton rank={rank} startRank={items.length} />}
/>
</>
)
return <MixedItems items={items} cursor={cursor} rank fetchMore={fetchMore} />
}