Add voters list component
This commit is contained in:
parent
9e69f280cf
commit
21ad1bdf9e
|
@ -233,5 +233,7 @@
|
||||||
"By time": "By time",
|
"By time": "By time",
|
||||||
"New only": "New only",
|
"New only": "New only",
|
||||||
"Bookmarks": "Bookmarks",
|
"Bookmarks": "Bookmarks",
|
||||||
"Logout": "Logout"
|
"Logout": "Logout",
|
||||||
|
"This comment has not yet been rated": "This comment has not yet been rated",
|
||||||
|
"This post has not been rated yet": "This post has not been rated yet"
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,5 +251,7 @@
|
||||||
"By time": "По порядку",
|
"By time": "По порядку",
|
||||||
"New only": "Только новые",
|
"New only": "Только новые",
|
||||||
"Bookmarks": "Закладки",
|
"Bookmarks": "Закладки",
|
||||||
"Logout": "Выход"
|
"Logout": "Выход",
|
||||||
|
"This comment has not yet been rated": "Этот комментарий еще пока никто не оценил",
|
||||||
|
"This post has not been rated yet": "Эту публикацию еще пока никто не оценил"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,12 @@ import type { Reaction } from '../../graphql/types.gen'
|
||||||
import { ReactionKind } from '../../graphql/types.gen'
|
import { ReactionKind } from '../../graphql/types.gen'
|
||||||
import { useSession } from '../../context/session'
|
import { useSession } from '../../context/session'
|
||||||
import { useReactions } from '../../context/reactions'
|
import { useReactions } from '../../context/reactions'
|
||||||
import { createMemo, For } from 'solid-js'
|
import { createMemo } from 'solid-js'
|
||||||
import { loadShout } from '../../stores/zine/articles'
|
import { loadShout } from '../../stores/zine/articles'
|
||||||
import { Popup } from '../_shared/Popup'
|
import { Popup } from '../_shared/Popup'
|
||||||
import { useLocalize } from '../../context/localize'
|
import { useLocalize } from '../../context/localize'
|
||||||
import { useSnackbar } from '../../context/snackbar'
|
import { useSnackbar } from '../../context/snackbar'
|
||||||
|
import VotersList from '../_shared/VotersList'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
comment: Reaction
|
comment: Reaction
|
||||||
|
@ -37,7 +38,7 @@ export const CommentRatingControl = (props: Props) => {
|
||||||
const isDownvoted = createMemo(() => checkReaction(ReactionKind.Dislike))
|
const isDownvoted = createMemo(() => checkReaction(ReactionKind.Dislike))
|
||||||
const canVote = createMemo(() => userSlug() !== props.comment.createdBy.slug)
|
const canVote = createMemo(() => userSlug() !== props.comment.createdBy.slug)
|
||||||
|
|
||||||
const shoutRatingReactions = createMemo(() =>
|
const commentRatingReactions = createMemo(() =>
|
||||||
Object.values(reactionEntities).filter(
|
Object.values(reactionEntities).filter(
|
||||||
(r) =>
|
(r) =>
|
||||||
[ReactionKind.Like, ReactionKind.Dislike].includes(r.kind) &&
|
[ReactionKind.Like, ReactionKind.Dislike].includes(r.kind) &&
|
||||||
|
@ -45,6 +46,7 @@ export const CommentRatingControl = (props: Props) => {
|
||||||
r.replyTo === props.comment.id
|
r.replyTo === props.comment.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const deleteCommentReaction = async (reactionKind: ReactionKind) => {
|
const deleteCommentReaction = async (reactionKind: ReactionKind) => {
|
||||||
const reactionToDelete = Object.values(reactionEntities).find(
|
const reactionToDelete = Object.values(reactionEntities).find(
|
||||||
(r) =>
|
(r) =>
|
||||||
|
@ -102,15 +104,10 @@ export const CommentRatingControl = (props: Props) => {
|
||||||
}
|
}
|
||||||
variant="tiny"
|
variant="tiny"
|
||||||
>
|
>
|
||||||
<ul class={clsx('nodash')}>
|
<VotersList
|
||||||
<For each={shoutRatingReactions()}>
|
reactions={commentRatingReactions()}
|
||||||
{(reaction) => (
|
fallbackMessage={t('This comment has not yet been rated')}
|
||||||
<li>
|
/>
|
||||||
{reaction.kind === ReactionKind.Like ? <>+1</> : <>−1</>} {reaction.createdBy.name}
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
</For>
|
|
||||||
</ul>
|
|
||||||
</Popup>
|
</Popup>
|
||||||
<button
|
<button
|
||||||
role="button"
|
role="button"
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { loadShout } from '../../stores/zine/articles'
|
||||||
import { useSession } from '../../context/session'
|
import { useSession } from '../../context/session'
|
||||||
import { useReactions } from '../../context/reactions'
|
import { useReactions } from '../../context/reactions'
|
||||||
import { Popup } from '../_shared/Popup'
|
import { Popup } from '../_shared/Popup'
|
||||||
|
import VotersList from '../_shared/VotersList'
|
||||||
|
import { useLocalize } from '../../context/localize'
|
||||||
|
|
||||||
interface ShoutRatingControlProps {
|
interface ShoutRatingControlProps {
|
||||||
shout: Shout
|
shout: Shout
|
||||||
|
@ -13,6 +15,7 @@ interface ShoutRatingControlProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
|
export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
|
||||||
|
const { t } = useLocalize()
|
||||||
const { userSlug } = useSession()
|
const { userSlug } = useSession()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -83,15 +86,10 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Popup trigger={<span class={styles.ratingValue}>{props.shout.stat.rating}</span>} variant="tiny">
|
<Popup trigger={<span class={styles.ratingValue}>{props.shout.stat.rating}</span>} variant="tiny">
|
||||||
<ul class={clsx('nodash')}>
|
<VotersList
|
||||||
<For each={shoutRatingReactions()}>
|
reactions={shoutRatingReactions()}
|
||||||
{(reaction) => (
|
fallbackMessage={t('This post has not been rated yet')}
|
||||||
<li>
|
/>
|
||||||
{reaction.kind === ReactionKind.Like ? <>+1</> : <>−1</>} {reaction.createdBy.name}
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
</For>
|
|
||||||
</ul>
|
|
||||||
</Popup>
|
</Popup>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { Author } from '../../graphql/types.gen'
|
import type { Author, User } from '../../graphql/types.gen'
|
||||||
import Userpic from './Userpic'
|
import Userpic from './Userpic'
|
||||||
import { Icon } from '../_shared/Icon'
|
import { Icon } from '../_shared/Icon'
|
||||||
import styles from './Card.module.scss'
|
import styles from './Card.module.scss'
|
||||||
|
|
40
src/components/_shared/VotersList/VotersList.module.scss
Normal file
40
src/components/_shared/VotersList/VotersList.module.scss
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
.VotersList {
|
||||||
|
.users {
|
||||||
|
margin: 0;
|
||||||
|
min-width: 220px;
|
||||||
|
max-height: 360px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.user {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: 1.2rem;
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userpic {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.commentRatingPositive {
|
||||||
|
color: #2bb452;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commentRatingNegative {
|
||||||
|
color: #d00820;
|
||||||
|
}
|
||||||
|
}
|
46
src/components/_shared/VotersList/VotersList.tsx
Normal file
46
src/components/_shared/VotersList/VotersList.tsx
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import type { Reaction } from '../../../graphql/types.gen'
|
||||||
|
import { Author, ReactionKind } from '../../../graphql/types.gen'
|
||||||
|
import { For, Show } from 'solid-js'
|
||||||
|
import Userpic from '../../Author/Userpic'
|
||||||
|
import styles from './VotersList.module.scss'
|
||||||
|
import { clsx } from 'clsx'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
reactions: Reaction[]
|
||||||
|
fallbackMessage: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const VotersList = (props: Props) => {
|
||||||
|
return (
|
||||||
|
<div class={styles.VotersList}>
|
||||||
|
<ul class={clsx('nodash', styles.users)}>
|
||||||
|
<Show
|
||||||
|
when={props.reactions.length > 0}
|
||||||
|
fallback={
|
||||||
|
<li class={styles.item}>
|
||||||
|
<small>{props.fallbackMessage}</small>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<For each={props.reactions}>
|
||||||
|
{(reaction) => (
|
||||||
|
<li class={styles.item}>
|
||||||
|
<div class={styles.user}>
|
||||||
|
<Userpic user={reaction.createdBy as Author} isBig={false} isAuthorsList={false} />
|
||||||
|
<a href={`/author/${reaction.createdBy.slug}`}>{reaction.createdBy.name || ''}</a>
|
||||||
|
</div>
|
||||||
|
{reaction.kind === ReactionKind.Like ? (
|
||||||
|
<div class={styles.commentRatingPositive}>+1</div>
|
||||||
|
) : (
|
||||||
|
<div class={styles.commentRatingNegative}>−1</div>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</Show>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default VotersList
|
1
src/components/_shared/VotersList/index.ts
Normal file
1
src/components/_shared/VotersList/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { default } from './VotersList'
|
Loading…
Reference in New Issue
Block a user