From bca0a227e6bd28e649e1a2eee4c1733dec1707a9 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 28 Dec 2023 01:50:42 +0300 Subject: [PATCH] profile-ratings --- src/components/Author/AuthorRatingControl.tsx | 19 ++++++++++++++++--- src/components/Topic/Full.tsx | 10 +++++----- src/components/Views/Topic.tsx | 2 +- src/graphql/client/core.ts | 8 ++++++++ src/graphql/mutation/core/author-rate.ts | 9 +++++++++ src/graphql/query/core/author-id.ts | 9 +++++++++ src/graphql/query/core/authors-load-by.ts | 6 +++++- 7 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 src/graphql/mutation/core/author-rate.ts diff --git a/src/components/Author/AuthorRatingControl.tsx b/src/components/Author/AuthorRatingControl.tsx index 31af321a..0e1902f4 100644 --- a/src/components/Author/AuthorRatingControl.tsx +++ b/src/components/Author/AuthorRatingControl.tsx @@ -3,6 +3,9 @@ import type { Author } from '../../graphql/schema/core.gen' import { clsx } from 'clsx' 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 { author: Author @@ -12,12 +15,14 @@ interface AuthorRatingControlProps { export const AuthorRatingControl = (props: AuthorRatingControlProps) => { const isUpvoted = false const isDownvoted = false - + const { t } = useLocalize() // eslint-disable-next-line unicorn/consistent-function-scoping - const handleRatingChange = (isUpvote: boolean) => { + const handleRatingChange = async (isUpvote: boolean) => { 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 (
{ − {/*TODO*/} - {123} +
+
{rating()}
+ +
{props.author?.stat?.rating_shouts}
+
+ +
{props.author?.stat?.rating_comments}
+
+
- - {props.topic.title} + + {props.topic?.title} ) diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index a0ac01e2..a6702147 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -162,7 +162,7 @@ export const TopicView = (props: Props) => { diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index cfaa8066..63f6417a 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -44,6 +44,7 @@ import topicBySlug from '../query/core/topic-by-slug' import topicsAll from '../query/core/topics-all' import userFollowedTopics from '../query/core/topics-by-author' import topicsRandomQuery from '../query/core/topics-random' +import rateAuthor from '../mutation/core/author-rate' const publicGraphQLClient = createGraphQLClient('core') @@ -65,6 +66,13 @@ export const apiClient = { 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 }) => { const response = await publicGraphQLClient.query(topicsRandomQuery, { amount }).toPromise() if (!response.data) console.error('[graphql.client.core] get_topics_random failed', response) diff --git a/src/graphql/mutation/core/author-rate.ts b/src/graphql/mutation/core/author-rate.ts new file mode 100644 index 00000000..e1d766a1 --- /dev/null +++ b/src/graphql/mutation/core/author-rate.ts @@ -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 + } + } +` diff --git a/src/graphql/query/core/author-id.ts b/src/graphql/query/core/author-id.ts index 277e0d44..38596c1c 100644 --- a/src/graphql/query/core/author-id.ts +++ b/src/graphql/query/core/author-id.ts @@ -12,6 +12,15 @@ export default gql` links created_at last_seen + stat { + shouts + comments: commented + followers + followings + rating + rating_shouts + rating_comments + } } } ` diff --git a/src/graphql/query/core/authors-load-by.ts b/src/graphql/query/core/authors-load-by.ts index 03b20171..11e11be2 100644 --- a/src/graphql/query/core/authors-load-by.ts +++ b/src/graphql/query/core/authors-load-by.ts @@ -11,8 +11,12 @@ export default gql` created_at stat { shouts - followers comments: commented + followers + followings + rating + rating_shouts + rating_comments } } }