make freebie comments visible case by case
This commit is contained in:
parent
56f08e0144
commit
369bd82a84
|
@ -17,17 +17,17 @@ async function comments (me, models, id, sort) {
|
||||||
let orderBy
|
let orderBy
|
||||||
switch (sort) {
|
switch (sort) {
|
||||||
case 'top':
|
case 'top':
|
||||||
orderBy = `ORDER BY ${await orderByNumerator(me, models)} DESC, "Item".msats DESC, "Item".id DESC`
|
orderBy = `ORDER BY ${await orderByNumerator(me, models)} DESC, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
|
||||||
break
|
break
|
||||||
case 'recent':
|
case 'recent':
|
||||||
orderBy = 'ORDER BY "Item".created_at DESC, "Item".msats DESC, "Item".id DESC'
|
orderBy = 'ORDER BY "Item".created_at DESC, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
orderBy = `ORDER BY ${await orderByNumerator(me, models)}/POWER(GREATEST(3, EXTRACT(EPOCH FROM (now_utc() - "Item".created_at))/3600), 1.3) DESC NULLS LAST, "Item".msats DESC, "Item".id DESC`
|
orderBy = `ORDER BY ${await orderByNumerator(me, models)}/POWER(GREATEST(3, EXTRACT(EPOCH FROM (now_utc() - "Item".created_at))/3600), 1.3) DESC NULLS LAST, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const filter = await filterClause(me, models)
|
const filter = await commentFilterClause(me, models)
|
||||||
if (me) {
|
if (me) {
|
||||||
const [{ item_comments_with_me: comments }] = await models.$queryRaw(
|
const [{ item_comments_with_me: comments }] = await models.$queryRaw(
|
||||||
'SELECT item_comments_with_me($1, $2, $3, $4, $5)', Number(id), Number(me.id), COMMENT_DEPTH_LIMIT, filter, orderBy)
|
'SELECT item_comments_with_me($1, $2, $3, $4, $5)', Number(id), Number(me.id), COMMENT_DEPTH_LIMIT, filter, orderBy)
|
||||||
|
@ -110,6 +110,25 @@ export async function joinSatRankView (me, models) {
|
||||||
return 'JOIN sat_rank_tender_view ON "Item".id = sat_rank_tender_view.id'
|
return 'JOIN sat_rank_tender_view ON "Item".id = sat_rank_tender_view.id'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function commentFilterClause (me, models) {
|
||||||
|
let clause = ` AND ("Item"."weightedVotes" - "Item"."weightedDownVotes" > -${ITEM_FILTER_THRESHOLD}`
|
||||||
|
if (me) {
|
||||||
|
const user = await models.user.findUnique({ where: { id: me.id } })
|
||||||
|
// wild west mode has everything
|
||||||
|
if (user.wildWestMode) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// always include if it's mine
|
||||||
|
clause += ` OR "Item"."userId" = ${me.id}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// close the clause
|
||||||
|
clause += ')'
|
||||||
|
|
||||||
|
return clause
|
||||||
|
}
|
||||||
|
|
||||||
export async function filterClause (me, models) {
|
export async function filterClause (me, models) {
|
||||||
// by default don't include freebies unless they have upvotes
|
// by default don't include freebies unless they have upvotes
|
||||||
let clause = ' AND (NOT "Item".freebie OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0'
|
let clause = ' AND (NOT "Item".freebie OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0'
|
||||||
|
|
|
@ -20,6 +20,7 @@ import Share from './share'
|
||||||
import ItemInfo from './item-info'
|
import ItemInfo from './item-info'
|
||||||
import { Badge } from 'react-bootstrap'
|
import { Badge } from 'react-bootstrap'
|
||||||
import { RootProvider, useRoot } from './root'
|
import { RootProvider, useRoot } from './root'
|
||||||
|
import { useMe } from './me'
|
||||||
|
|
||||||
function Parent ({ item, rootText }) {
|
function Parent ({ item, rootText }) {
|
||||||
const root = useRoot()
|
const root = useRoot()
|
||||||
|
@ -87,7 +88,12 @@ export default function Comment ({
|
||||||
rootText, noComments, noReply, truncate, depth
|
rootText, noComments, noReply, truncate, depth
|
||||||
}) {
|
}) {
|
||||||
const [edit, setEdit] = useState()
|
const [edit, setEdit] = useState()
|
||||||
const [collapse, setCollapse] = useState(false)
|
const me = useMe()
|
||||||
|
const [collapse, setCollapse] = useState(
|
||||||
|
!me?.wildWestMode && !me?.greeterMode &&
|
||||||
|
!item.mine && item.freebie && item.wvotes <= 0
|
||||||
|
? 'yep'
|
||||||
|
: 'nope')
|
||||||
const ref = useRef(null)
|
const ref = useRef(null)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const root = useRoot()
|
const root = useRoot()
|
||||||
|
@ -101,7 +107,7 @@ export default function Comment ({
|
||||||
query: { id: router.query.id }
|
query: { id: router.query.id }
|
||||||
}, undefined, { scroll: false })
|
}, undefined, { scroll: false })
|
||||||
}
|
}
|
||||||
setCollapse(localStorage.getItem(`commentCollapse:${item.id}`))
|
setCollapse(localStorage.getItem(`commentCollapse:${item.id}`) || collapse)
|
||||||
}, [item])
|
}, [item])
|
||||||
|
|
||||||
const bottomedOut = depth === COMMENT_DEPTH_LIMIT
|
const bottomedOut = depth === COMMENT_DEPTH_LIMIT
|
||||||
|
@ -110,7 +116,7 @@ export default function Comment ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref} className={includeParent ? '' : `${styles.comment} ${collapse ? styles.collapsed : ''}`}
|
ref={ref} className={includeParent ? '' : `${styles.comment} ${collapse === 'yep' ? styles.collapsed : ''}`}
|
||||||
>
|
>
|
||||||
<div className={`${itemStyles.item} ${styles.item}`}>
|
<div className={`${itemStyles.item} ${styles.item}`}>
|
||||||
{item.meDontLike
|
{item.meDontLike
|
||||||
|
@ -135,16 +141,16 @@ export default function Comment ({
|
||||||
onEdit={e => { setEdit(!edit) }}
|
onEdit={e => { setEdit(!edit) }}
|
||||||
editText={edit ? 'cancel' : 'edit'}
|
editText={edit ? 'cancel' : 'edit'}
|
||||||
/>
|
/>
|
||||||
{!includeParent && (collapse
|
{!includeParent && (collapse === 'yep'
|
||||||
? <Eye
|
? <Eye
|
||||||
className={styles.collapser} height={10} width={10} onClick={() => {
|
className={styles.collapser} height={10} width={10} onClick={() => {
|
||||||
setCollapse(false)
|
setCollapse('nope')
|
||||||
localStorage.removeItem(`commentCollapse:${item.id}`)
|
localStorage.setItem(`commentCollapse:${item.id}`, 'nope')
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
: <EyeClose
|
: <EyeClose
|
||||||
className={styles.collapser} height={10} width={10} onClick={() => {
|
className={styles.collapser} height={10} width={10} onClick={() => {
|
||||||
setCollapse(true)
|
setCollapse('yep')
|
||||||
localStorage.setItem(`commentCollapse:${item.id}`, 'yep')
|
localStorage.setItem(`commentCollapse:${item.id}`, 'yep')
|
||||||
}}
|
}}
|
||||||
/>)}
|
/>)}
|
||||||
|
|
|
@ -69,7 +69,7 @@ export default function Comments ({ parentId, pinned, commentSats, comments, ...
|
||||||
document.querySelector(hash).scrollIntoView({ behavior: 'smooth' })
|
document.querySelector(hash).scrollIntoView({ behavior: 'smooth' })
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
}, [])
|
}, [typeof window !== 'undefined' && window.location.hash])
|
||||||
const [loading, setLoading] = useState()
|
const [loading, setLoading] = useState()
|
||||||
const [getComments] = useLazyQuery(COMMENTS_QUERY, {
|
const [getComments] = useLazyQuery(COMMENTS_QUERY, {
|
||||||
fetchPolicy: 'network-only',
|
fetchPolicy: 'network-only',
|
||||||
|
|
|
@ -15,6 +15,7 @@ export const COMMENT_FIELDS = gql`
|
||||||
}
|
}
|
||||||
sats
|
sats
|
||||||
upvotes
|
upvotes
|
||||||
|
wvotes
|
||||||
boost
|
boost
|
||||||
meSats
|
meSats
|
||||||
meDontLike
|
meDontLike
|
||||||
|
|
Loading…
Reference in New Issue