833dd37469
* Add tip arrows UI (visual) * move tipper into its own component * simplify score calculation * Add tip txns - more specific txn types - fix transact cloud function to be able to create tip txns - insert tips into comments via a context * Refactor tipper to send tip txns * Stop tipping yourself. Disable anons. * Style tipper (smaller) * remove default exports * capitalize tooltips * rename stuff * add exhausting hook dependencies * replace context with prop threading * fix eslint unused vars * fix: thread tips correctly into fr comments
24 lines
783 B
TypeScript
24 lines
783 B
TypeScript
import { TipTxn } from 'common/txn'
|
|
import { groupBy, mapValues, sumBy } from 'lodash'
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
import { listenForTipTxns } from 'web/lib/firebase/txns'
|
|
|
|
export type CommentTips = { [userId: string]: number }
|
|
export type CommentTipMap = { [commentId: string]: CommentTips }
|
|
|
|
export function useTipTxns(contractId: string): CommentTipMap {
|
|
const [txns, setTxns] = useState<TipTxn[]>([])
|
|
|
|
useEffect(() => {
|
|
return listenForTipTxns(contractId, setTxns)
|
|
}, [contractId, setTxns])
|
|
|
|
return useMemo(() => {
|
|
const byComment = groupBy(txns, 'data.commentId')
|
|
return mapValues(byComment, (txns) => {
|
|
const bySender = groupBy(txns, 'fromId')
|
|
return mapValues(bySender, (t) => sumBy(t, 'amount'))
|
|
})
|
|
}, [txns])
|
|
}
|