profile-ratings
Some checks failed
deploy / test (push) Failing after 1m11s

This commit is contained in:
Untone 2023-12-28 01:50:42 +03:00
parent 7be0f9e9ef
commit bca0a227e6
7 changed files with 53 additions and 10 deletions

View File

@ -3,6 +3,9 @@ import type { Author } from '../../graphql/schema/core.gen'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import styles from './AuthorRatingControl.module.scss' import styles from './AuthorRatingControl.module.scss'
import { Show, createSignal } from 'solid-js'
import { useLocalize } from '../../context/localize'
import { apiClient } from '../../graphql/client/core'
interface AuthorRatingControlProps { interface AuthorRatingControlProps {
author: Author author: Author
@ -12,12 +15,14 @@ interface AuthorRatingControlProps {
export const AuthorRatingControl = (props: AuthorRatingControlProps) => { export const AuthorRatingControl = (props: AuthorRatingControlProps) => {
const isUpvoted = false const isUpvoted = false
const isDownvoted = false const isDownvoted = false
const { t } = useLocalize()
// eslint-disable-next-line unicorn/consistent-function-scoping // eslint-disable-next-line unicorn/consistent-function-scoping
const handleRatingChange = (isUpvote: boolean) => { const handleRatingChange = async (isUpvote: boolean) => {
console.log('handleRatingChange', { isUpvote }) console.log('handleRatingChange', { isUpvote })
await apiClient.rateAuthor({ rated_slug: props.author.slug, value: isUpvote ? 1 : -1 })
} }
const [rating, setRating] = createSignal(props.author.stat.rating)
return ( return (
<div <div
class={clsx(styles.rating, props.class, { class={clsx(styles.rating, props.class, {
@ -32,7 +37,15 @@ export const AuthorRatingControl = (props: AuthorRatingControlProps) => {
&minus; &minus;
</button> </button>
{/*TODO*/} {/*TODO*/}
<span class={styles.ratingValue}>{123}</span> <div>
<div class={styles.ratingValue}>{rating()}</div>
<Show when={props.author?.stat?.rating_shouts}>
<div class={styles.ratingValue}>{props.author?.stat?.rating_shouts}</div>
</Show>
<Show when={props.author?.stat?.rating_comments}>
<div class={styles.ratingValue}>{props.author?.stat?.rating_comments}</div>
</Show>
</div>
<button <button
class={clsx(styles.ratingControl, styles.upvoteButton)} class={clsx(styles.ratingControl, styles.upvoteButton)}
onClick={() => handleRatingChange(true)} onClick={() => handleRatingChange(true)}

View File

@ -38,8 +38,8 @@ export const FullTopic = (props: Props) => {
return ( return (
<div class={clsx(styles.topicHeader, 'col-md-16 col-lg-12 offset-md-4 offset-lg-6')}> <div class={clsx(styles.topicHeader, 'col-md-16 col-lg-12 offset-md-4 offset-lg-6')}>
<h1>#{props.topic.title}</h1> <h1>#{props.topic?.title}</h1>
<p>{props.topic.body}</p> <p>{props.topic?.body}</p>
<div class={clsx(styles.topicActions)}> <div class={clsx(styles.topicActions)}>
<Show when={!subscribed()}> <Show when={!subscribed()}>
<Button variant="primary" onClick={() => handleSubscribe(true)} value={t('Follow the topic')} /> <Button variant="primary" onClick={() => handleSubscribe(true)} value={t('Follow the topic')} />
@ -51,12 +51,12 @@ export const FullTopic = (props: Props) => {
value={t('Unfollow the topic')} value={t('Unfollow the topic')}
/> />
</Show> </Show>
<a class={styles.write} href={`/create/?topicId=${props.topic.id}`}> <a class={styles.write} href={`/create/?topicId=${props.topic?.id}`}>
{t('Write about the topic')} {t('Write about the topic')}
</a> </a>
</div> </div>
<Show when={props.topic.pic}> <Show when={props.topic?.pic}>
<img src={props.topic.pic} alt={props.topic.title} /> <img src={props.topic.pic} alt={props.topic?.title} />
</Show> </Show>
</div> </div>
) )

View File

@ -162,7 +162,7 @@ export const TopicView = (props: Props) => {
<Beside <Beside
title={t('Topic is supported by')} title={t('Topic is supported by')}
values={authorsByTopic()[topic().slug].slice(0, 6)} values={authorsByTopic()[topic()?.slug]?.slice(0, 6)}
beside={sortedArticles()[4]} beside={sortedArticles()[4]}
wrapper={'author'} wrapper={'author'}
/> />

View File

@ -44,6 +44,7 @@ import topicBySlug from '../query/core/topic-by-slug'
import topicsAll from '../query/core/topics-all' import topicsAll from '../query/core/topics-all'
import userFollowedTopics from '../query/core/topics-by-author' import userFollowedTopics from '../query/core/topics-by-author'
import topicsRandomQuery from '../query/core/topics-random' import topicsRandomQuery from '../query/core/topics-random'
import rateAuthor from '../mutation/core/author-rate'
const publicGraphQLClient = createGraphQLClient('core') const publicGraphQLClient = createGraphQLClient('core')
@ -65,6 +66,13 @@ export const apiClient = {
return response.data.load_shouts_unrated return response.data.load_shouts_unrated
}, },
rateAuthor: async ({ rated_slug, value }: { rated_slug: string; value: number }) => {
const response = await apiClient.private.mutation(rateAuthor, { rated_slug, value }).toPromise()
if (!response.data) console.error('[graphql.client.core] get_topics_random failed', response)
return response.data.rate_author
},
getRandomTopics: async ({ amount }: { amount: number }) => { getRandomTopics: async ({ amount }: { amount: number }) => {
const response = await publicGraphQLClient.query(topicsRandomQuery, { amount }).toPromise() const response = await publicGraphQLClient.query(topicsRandomQuery, { amount }).toPromise()
if (!response.data) console.error('[graphql.client.core] get_topics_random failed', response) if (!response.data) console.error('[graphql.client.core] get_topics_random failed', response)

View File

@ -0,0 +1,9 @@
import { gql } from '@urql/core'
export default gql`
mutation AuthorRate($rated_slug: String!, $value: Int!) {
rate_author(rated_slug: $rated_slug, value: $value) {
error
}
}
`

View File

@ -12,6 +12,15 @@ export default gql`
links links
created_at created_at
last_seen last_seen
stat {
shouts
comments: commented
followers
followings
rating
rating_shouts
rating_comments
}
} }
} }
` `

View File

@ -11,8 +11,12 @@ export default gql`
created_at created_at
stat { stat {
shouts shouts
followers
comments: commented comments: commented
followers
followings
rating
rating_shouts
rating_comments
} }
} }
} }