display earned sats in comments
This commit is contained in:
parent
6aeeb40623
commit
4be5cfa5c7
|
@ -72,7 +72,8 @@ export default {
|
|||
itemRepetition: async (parent, { parentId }, { me, models }) => {
|
||||
if (!me) return 0
|
||||
// how many of the parents starting at parentId belong to me
|
||||
const [{ item_spam: count }] = await models.$queryRaw(`SELECT item_spam($1, $2, '${ITEM_SPAM_INTERVAL}')`, Number(parentId), Number(me.id))
|
||||
const [{ item_spam: count }] = await models.$queryRaw(`SELECT item_spam($1, $2, '${ITEM_SPAM_INTERVAL}')`,
|
||||
Number(parentId), Number(me.id))
|
||||
|
||||
return count
|
||||
},
|
||||
|
@ -709,37 +710,12 @@ export default {
|
|||
}
|
||||
return await models.user.findUnique({ where: { id: item.fwdUserId } })
|
||||
},
|
||||
ncomments: async (item, args, { models }) => {
|
||||
const [{ count }] = await models.$queryRaw`
|
||||
SELECT count(*)
|
||||
FROM "Item"
|
||||
WHERE path <@ text2ltree(${item.path}) AND id != ${Number(item.id)}`
|
||||
return count || 0
|
||||
},
|
||||
comments: async (item, args, { models }) => {
|
||||
if (item.comments) {
|
||||
return item.comments
|
||||
}
|
||||
return comments(models, item.id, 'hot')
|
||||
},
|
||||
sats: async (item, args, { models }) => {
|
||||
const { sum: { sats } } = await models.itemAct.aggregate({
|
||||
sum: {
|
||||
sats: true
|
||||
},
|
||||
where: {
|
||||
itemId: Number(item.id),
|
||||
userId: {
|
||||
not: Number(item.userId)
|
||||
},
|
||||
act: {
|
||||
not: 'BOOST'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return sats || 0
|
||||
},
|
||||
upvotes: async (item, args, { models }) => {
|
||||
const { sum: { sats } } = await models.itemAct.aggregate({
|
||||
sum: {
|
||||
|
@ -966,7 +942,8 @@ export const SELECT =
|
|||
`SELECT "Item".id, "Item".created_at as "createdAt", "Item".updated_at as "updatedAt", "Item".title,
|
||||
"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", ltree2text("Item"."path") AS "path"`
|
||||
"Item"."subName", "Item".status, "Item"."uploadId", "Item"."pollCost", "Item"."paidImgLink",
|
||||
"Item".sats, "Item".ncomments, "Item"."commentSats", "Item"."lastCommentAt", ltree2text("Item"."path") AS "path"`
|
||||
|
||||
function newTimedOrderByWeightedSats (num) {
|
||||
return `
|
||||
|
|
|
@ -74,6 +74,8 @@ export default gql`
|
|||
mine: Boolean!
|
||||
boost: Int!
|
||||
sats: Int!
|
||||
commentSats: Int!
|
||||
lastCommentAt: String
|
||||
upvotes: Int!
|
||||
meSats: Int!
|
||||
paidImgLink: Boolean
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Nav, Navbar } from 'react-bootstrap'
|
|||
import { COMMENTS_QUERY } from '../fragments/items'
|
||||
import { COMMENTS } from '../fragments/comments'
|
||||
|
||||
export function CommentsHeader ({ handleSort }) {
|
||||
export function CommentsHeader ({ handleSort, commentSats }) {
|
||||
const [sort, setSort] = useState('hot')
|
||||
|
||||
const getHandleClick = sort => {
|
||||
|
@ -17,11 +17,15 @@ export function CommentsHeader ({ handleSort }) {
|
|||
}
|
||||
|
||||
return (
|
||||
<Navbar className='py-1'>
|
||||
<Navbar className='pt-1 pb-0'>
|
||||
<Nav
|
||||
className={styles.navbarNav}
|
||||
activeKey={sort}
|
||||
>
|
||||
<Nav.Item className='text-muted'>
|
||||
{commentSats} sats
|
||||
</Nav.Item>
|
||||
<div className='ml-auto d-flex'>
|
||||
<Nav.Item>
|
||||
<Nav.Link
|
||||
eventKey='hot'
|
||||
|
@ -49,12 +53,13 @@ export function CommentsHeader ({ handleSort }) {
|
|||
top
|
||||
</Nav.Link>
|
||||
</Nav.Item>
|
||||
</div>
|
||||
</Nav>
|
||||
</Navbar>
|
||||
)
|
||||
}
|
||||
|
||||
export default function Comments ({ parentId, comments, ...props }) {
|
||||
export default function Comments ({ parentId, commentSats, comments, ...props }) {
|
||||
const client = useApolloClient()
|
||||
useEffect(() => {
|
||||
const hash = window.location.hash
|
||||
|
@ -87,7 +92,7 @@ export default function Comments ({ parentId, comments, ...props }) {
|
|||
|
||||
return (
|
||||
<>
|
||||
{comments.length ? <CommentsHeader handleSort={sort => getComments({ variables: { id: parentId, sort } })} /> : null}
|
||||
{comments.length ? <CommentsHeader commentSats={commentSats} handleSort={sort => getComments({ variables: { id: parentId, sort } })} /> : null}
|
||||
{loading
|
||||
? <CommentsSkeleton />
|
||||
: comments.map(item => (
|
||||
|
|
|
@ -112,7 +112,7 @@ export default function ItemFull ({ item, bio, ...props }) {
|
|||
</div>)}
|
||||
{item.comments &&
|
||||
<div className={styles.comments}>
|
||||
<Comments parentId={item.id} comments={item.comments} />
|
||||
<Comments parentId={item.id} commentSats={item.commentSats} comments={item.comments} />
|
||||
</div>}
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -22,6 +22,8 @@ export const ITEM_FIELDS = gql`
|
|||
path
|
||||
meSats
|
||||
ncomments
|
||||
commentSats
|
||||
lastCommentAt
|
||||
maxBid
|
||||
company
|
||||
location
|
||||
|
|
Loading…
Reference in New Issue