Added user file vote

This commit is contained in:
mrfry 2021-05-04 17:59:54 +02:00
parent 9ef2c10af1
commit d3f45e62f5
4 changed files with 207 additions and 23 deletions

View file

@ -0,0 +1,48 @@
import React from 'react'
import styles from './upDownVote.module.css'
export default function UpDownVote({
onUp,
onDown,
onClear,
upvotes,
downvotes,
userId,
}) {
const upvoted = upvotes.includes(userId)
const downvoted = downvotes.includes(userId)
return (
<div className={styles.container}>
<div
className={styles.action}
onClick={(e) => {
e.stopPropagation()
if (!upvoted) {
onUp()
} else {
onClear()
}
}}
>
<div>👍</div>
<div className={`${upvoted && styles.voted}`}>{upvotes.length}</div>
</div>
<div
className={styles.action}
onClick={(e) => {
e.stopPropagation()
if (!downvoted) {
onDown()
} else {
onClear()
}
}}
>
<div>👎</div>
<div className={`${downvoted && styles.voted}`}>{downvotes.length}</div>
</div>
</div>
)
}

View file

@ -0,0 +1,26 @@
.container {
display: flex;
align-items: center;
padding: 3px;
}
.container > div {
display: flex;
align-items: center;
}
.container > div > * {
padding: 3px;
}
.action {
border-radius: 3px;
}
.action:hover {
background-color: #555;
}
.voted {
color: var(--text-color);
}