disabling-on-load

This commit is contained in:
Untone 2024-01-23 02:16:22 +03:00
parent c96d723659
commit e4332128c8

View File

@ -1,5 +1,5 @@
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { createMemo, Show } from 'solid-js' import { createMemo, createSignal, Show } from 'solid-js'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
import { useReactions } from '../../context/reactions' import { useReactions } from '../../context/reactions'
@ -50,14 +50,15 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
!r.reply_to, !r.reply_to,
), ),
) )
const [isLoading, setIsLoading] = createSignal(false)
const handleRatingChange = async (isUpvote: boolean) => { const handleRatingChange = async (isUpvote: boolean) => {
setIsLoading(true)
requireAuthentication(async () => { requireAuthentication(async () => {
await createReaction({ await createReaction({
kind: isUpvote ? ReactionKind.Like : ReactionKind.Dislike, kind: isUpvote ? ReactionKind.Like : ReactionKind.Dislike,
shout: props.shout.id, shout: props.shout.id,
}) })
setIsLoading(false)
loadShout(props.shout.slug) loadShout(props.shout.slug)
loadReactionsBy({ loadReactionsBy({
by: { shout: props.shout.slug }, by: { shout: props.shout.slug },
@ -67,7 +68,7 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
return ( return (
<div class={clsx(styles.rating, props.class)}> <div class={clsx(styles.rating, props.class)}>
<button onClick={() => handleRatingChange(false)}> <button onClick={() => handleRatingChange(false)} disabled={isLoading()}>
<Show when={!isDownvoted()}> <Show when={!isDownvoted()}>
<Icon name="rating-control-less" /> <Icon name="rating-control-less" />
</Show> </Show>
@ -83,7 +84,7 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
/> />
</Popup> </Popup>
<button onClick={() => handleRatingChange(true)}> <button onClick={() => handleRatingChange(true)} disabled={isLoading()}>
<Show when={!isUpvoted()}> <Show when={!isUpvoted()}>
<Icon name="rating-control-more" /> <Icon name="rating-control-more" />
</Show> </Show>