mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Vote imporvements
This commit is contained in:
parent
d22e20b79e
commit
5611fd8d66
2 changed files with 25 additions and 21 deletions
|
@ -9,6 +9,7 @@ export default function UpDownVote({
|
||||||
upvotes,
|
upvotes,
|
||||||
downvotes,
|
downvotes,
|
||||||
userId,
|
userId,
|
||||||
|
disabled,
|
||||||
}) {
|
}) {
|
||||||
const upvoted = upvotes.includes(userId)
|
const upvoted = upvotes.includes(userId)
|
||||||
const downvoted = downvotes.includes(userId)
|
const downvoted = downvotes.includes(userId)
|
||||||
|
@ -19,6 +20,9 @@ export default function UpDownVote({
|
||||||
className={styles.action}
|
className={styles.action}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
if (disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!upvoted) {
|
if (!upvoted) {
|
||||||
onUp()
|
onUp()
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,6 +37,9 @@ export default function UpDownVote({
|
||||||
className={styles.action}
|
className={styles.action}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
if (disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!downvoted) {
|
if (!downvoted) {
|
||||||
onDown()
|
onDown()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -193,6 +193,7 @@ export default function UserFiles({ router, globalData }) {
|
||||||
const [usageShowing, setUsageShowing] = useState(false)
|
const [usageShowing, setUsageShowing] = useState(false)
|
||||||
const [searchTerm, setSearchTerm] = useState()
|
const [searchTerm, setSearchTerm] = useState()
|
||||||
const [uploading, setUploading] = useState(false)
|
const [uploading, setUploading] = useState(false)
|
||||||
|
const [votingDisabled, setVotingDisabled] = useState(false)
|
||||||
|
|
||||||
const currDir = router.query.dir ? decodeURIComponent(router.query.dir) : ''
|
const currDir = router.query.dir ? decodeURIComponent(router.query.dir) : ''
|
||||||
|
|
||||||
|
@ -236,6 +237,19 @@ export default function UserFiles({ router, globalData }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleVote = (type, dir) => {
|
||||||
|
setVotingDisabled(true)
|
||||||
|
vote(type, dir)
|
||||||
|
.then((res) => {
|
||||||
|
setDirs(res.files)
|
||||||
|
setVotingDisabled(false)
|
||||||
|
})
|
||||||
|
.catch((res) => {
|
||||||
|
alert(res.msg)
|
||||||
|
setVotingDisabled(false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const renderDirList = (dirs) => {
|
const renderDirList = (dirs) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -348,35 +362,18 @@ export default function UserFiles({ router, globalData }) {
|
||||||
{Array.isArray(upvotes) && Array.isArray(downvotes) && (
|
{Array.isArray(upvotes) && Array.isArray(downvotes) && (
|
||||||
<UpDownVote
|
<UpDownVote
|
||||||
onUp={() => {
|
onUp={() => {
|
||||||
vote('up', dir)
|
handleVote('up', dir)
|
||||||
.then((res) => {
|
|
||||||
setDirs(res.files)
|
|
||||||
})
|
|
||||||
.catch((res) => {
|
|
||||||
alert(res.msg)
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
onDown={() => {
|
onDown={() => {
|
||||||
vote('down', dir)
|
handleVote('down', dir)
|
||||||
.then((res) => {
|
|
||||||
setDirs(res.files)
|
|
||||||
})
|
|
||||||
.catch((res) => {
|
|
||||||
alert(res.msg)
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
onClear={() => {
|
onClear={() => {
|
||||||
vote('clear', dir)
|
handleVote('clear', dir)
|
||||||
.then((res) => {
|
|
||||||
setDirs(res.files)
|
|
||||||
})
|
|
||||||
.catch((res) => {
|
|
||||||
alert(res.msg)
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
upvotes={upvotes}
|
upvotes={upvotes}
|
||||||
downvotes={downvotes}
|
downvotes={downvotes}
|
||||||
userId={userId}
|
userId={userId}
|
||||||
|
disabled={votingDisabled}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue