tips: display total
This commit is contained in:
parent
670c6faea8
commit
fac87f8e0c
|
@ -1,4 +1,4 @@
|
||||||
import { debounce } from 'lodash'
|
import { debounce, sum } from 'lodash'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
import { Comment } from 'common/comment'
|
import { Comment } from 'common/comment'
|
||||||
|
@ -29,6 +29,8 @@ export function Tipper(prop: { comment: Comment; tips: CommentTips }) {
|
||||||
}
|
}
|
||||||
}, [tips, myId])
|
}, [tips, myId])
|
||||||
|
|
||||||
|
const total = sum(Object.values(tips)) - savedTip + localTip
|
||||||
|
|
||||||
// declare debounced function only on first render
|
// declare debounced function only on first render
|
||||||
const [saveTip] = useState(() =>
|
const [saveTip] = useState(() =>
|
||||||
debounce(async (user: User, comment: Comment, change: number) => {
|
debounce(async (user: User, comment: Comment, change: number) => {
|
||||||
|
@ -82,7 +84,7 @@ export function Tipper(prop: { comment: Comment; tips: CommentTips }) {
|
||||||
<Row className="items-center gap-0.5">
|
<Row className="items-center gap-0.5">
|
||||||
<TipButton
|
<TipButton
|
||||||
tipAmount={LIKE_TIP_AMOUNT}
|
tipAmount={LIKE_TIP_AMOUNT}
|
||||||
totalTipped={localTip}
|
totalTipped={total}
|
||||||
onClick={() => addTip(+LIKE_TIP_AMOUNT)}
|
onClick={() => addTip(+LIKE_TIP_AMOUNT)}
|
||||||
userTipped={localTip > 0}
|
userTipped={localTip > 0}
|
||||||
disabled={!canUp}
|
disabled={!canUp}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user