show when items are outlawed

This commit is contained in:
keyan 2022-09-22 13:44:50 -05:00
parent 4b00661ad0
commit 2c7c237fc7
9 changed files with 140 additions and 3 deletions

View File

@ -273,6 +273,25 @@ export default {
items
}
},
outlawedItems: 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" <= -${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)
@ -844,6 +863,12 @@ export default {
return !!dontLike
},
outlawed: async (item, args, { me, models }) => {
if (me && Number(item.userId) === Number(me.id)) {
return false
}
return item.weightedVotes - item.weightedDownVotes <= -ITEM_FILTER_THRESHOLD
},
mine: async (item, args, { me, models }) => {
return me?.id === item.userId
},
@ -1014,7 +1039,8 @@ export const SELECT =
"Item".text, "Item".url, "Item"."userId", "Item"."fwdUserId", "Item"."parentId", "Item"."pinId", "Item"."maxBid",
"Item".company, "Item".location, "Item".remote,
"Item"."subName", "Item".status, "Item"."uploadId", "Item"."pollCost", "Item"."paidImgLink",
"Item".sats, "Item".ncomments, "Item"."commentSats", "Item"."lastCommentAt", ltree2text("Item"."path") AS "path"`
"Item".sats, "Item".ncomments, "Item"."commentSats", "Item"."lastCommentAt", "Item"."weightedVotes",
"Item"."weightedDownVotes", ltree2text("Item"."path") AS "path"`
async function newTimedOrderByWeightedSats (me, models, num) {
return `

View File

@ -12,6 +12,7 @@ export default gql`
search(q: String, sub: String, cursor: String): Items
auctionPosition(sub: String, id: ID, bid: Int!): Int!
itemRepetition(parentId: ID): Int!
outlawedItems(cursor: String): Items
}
type ItemActResult {
@ -80,6 +81,7 @@ export default gql`
upvotes: Int!
meSats: Int!
meDontLike: Boolean!
outlawed: Boolean!
paidImgLink: Boolean
ncomments: Int!
comments: [Item!]!

View File

@ -16,6 +16,7 @@ import { ignoreClick } from '../lib/clicks'
import { useMe } from './me'
import DontLikeThis from './dont-link-this'
import Flag from '../svgs/flag-fill.svg'
import { Badge } from 'react-bootstrap'
function Parent ({ item, rootText }) {
const ParentFrag = () => (
@ -133,6 +134,7 @@ export default function Comment ({
</Link>
{includeParent && <Parent item={item} rootText={rootText} />}
{me && !item.meSats && !item.meDontLike && <DontLikeThis id={item.id} />}
{item.outlawed && <Link href='/outlawed'><a>{' '}<Badge className={itemStyles.newComment} variant={null}>OUTLAWED</Badge></a></Link>}
{canEdit &&
<>
<span> \ </span>

View File

@ -111,6 +111,7 @@ export default function Item ({ item, rank, showFwdUser, toc, children }) {
<a title={item.createdAt} className='text-reset'>{timeSince(new Date(item.createdAt))}</a>
</Link>
{me && !item.meSats && !item.position && !item.meDontLike && <DontLikeThis id={item.id} />}
{item.outlawed && <Link href='/outlawed'><a>{' '}<Badge className={styles.newComment} variant={null}>OUTLAWED</Badge></a></Link>}
{item.prior &&
<>
<span> \ </span>

View File

@ -30,7 +30,12 @@ export default function Items ({ variables = {}, rank, items, pins, cursor }) {
? <><div /><div className='pb-3'><Comment item={item} noReply includeParent /></div></>
: (item.maxBid
? <ItemJob item={item} rank={rank && i + 1} />
: <Item item={item} rank={rank && i + 1} />)}
: (item.title
? <Item item={item} rank={rank && i + 1} />
: (
<div className='pb-2'>
<Comment item={item} noReply includeParent clickToContext />
</div>)))}
</React.Fragment>
))}
</div>
@ -42,7 +47,7 @@ export default function Items ({ variables = {}, rank, items, pins, cursor }) {
)
}
function ItemsSkeleton ({ rank, startRank = 0 }) {
export function ItemsSkeleton ({ rank, startRank = 0 }) {
const items = new Array(21).fill(null)
return (

View File

@ -15,6 +15,7 @@ export const COMMENT_FIELDS = gql`
boost
meSats
meDontLike
outlawed
path
commentSats
mine

View File

@ -22,6 +22,7 @@ export const ITEM_FIELDS = gql`
path
meSats
meDontLike
outlawed
ncomments
commentSats
lastCommentAt
@ -68,6 +69,19 @@ export const ITEMS = gql`
}
}`
export const OUTLAWED_ITEMS = gql`
${ITEM_FIELDS}
query outlawedItems($cursor: String) {
outlawedItems(cursor: $cursor) {
cursor
items {
...ItemFields
text
}
}
}`
export const POLL_FIELDS = gql`
fragment PollFields on Item {
poll {

View File

@ -52,6 +52,19 @@ export default function getApolloClient () {
}
}
},
outlawedItems: {
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) {

73
pages/outlawed.js Normal file
View File

@ -0,0 +1,73 @@
import Layout from '../components/layout'
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'
export const getServerSideProps = getGetServerSideProps(OUTLAWED_ITEMS)
export default function Index ({ data: { outlawedItems: { items, cursor } } }) {
return (
<Layout>
<Items
items={items} cursor={cursor}
/>
</Layout>
)
}
function Items ({ rank, items, cursor }) {
const { data, fetchMore } = useQuery(OUTLAWED_ITEMS)
const router = useRouter()
if (!data && !items) {
return <ItemsSkeleton rank={rank} />
}
if (data) {
({ 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} />}
/>
</>
)
}