From 74f7469c7dab3803759e936991bd45f3a67bb855 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 18 May 2024 19:45:36 +0300 Subject: [PATCH 1/2] topic followers + shouts counter --- src/components/Topic/Full.tsx | 34 +++++++++++++++++++++-- src/components/Views/Topic.tsx | 17 +++++++++--- src/graphql/client/core.ts | 7 +++++ src/graphql/query/core/topic-followers.ts | 25 +++++++++++++++++ 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/graphql/query/core/topic-followers.ts diff --git a/src/components/Topic/Full.tsx b/src/components/Topic/Full.tsx index 5e22aed1..9b6705b4 100644 --- a/src/components/Topic/Full.tsx +++ b/src/components/Topic/Full.tsx @@ -1,7 +1,7 @@ -import type { Topic } from '../../graphql/schema/core.gen' +import type { Author, Topic } from '../../graphql/schema/core.gen' import { clsx } from 'clsx' -import { Show, createEffect, createSignal } from 'solid-js' +import { For, Show, createEffect, createSignal } from 'solid-js' import { useFollowing } from '../../context/following' import { useLocalize } from '../../context/localize' @@ -9,10 +9,13 @@ import { useSession } from '../../context/session' import { FollowingEntity } from '../../graphql/schema/core.gen' import { Button } from '../_shared/Button' +import stylesCard from '../Author/AuthorCard/AuthorCard.module.scss' +import { Userpic } from '../Author/Userpic' import styles from './Full.module.scss' type Props = { topic: Topic + followers?: Author[] } export const FullTopic = (props: Props) => { @@ -40,6 +43,31 @@ export const FullTopic = (props: Props) => { return (

#{props.topic?.title}

+ +
+ 0}> + + + {(f) => ( + + )} + +
+ {t('SubscriberWithCount', { + count: props.followers.length ?? 0, + })} +
+
+
+ +
+ {t('PublicationsWithCount', { + count: props.topic?.stat?.shouts ?? 0, + })} +
+
+
+

- {props.topic?.title} + {props.topic?.title}
) diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index d788d1f6..3d7ae3f3 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -1,4 +1,4 @@ -import { LoadShoutsOptions, Shout, Topic } from '../../graphql/schema/core.gen' +import { Author, LoadShoutsOptions, Shout, Topic } from '../../graphql/schema/core.gen' import { clsx } from 'clsx' import { For, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js' @@ -33,6 +33,7 @@ interface Props { topic: Topic shouts: Shout[] topicSlug: string + followers?: Author[] } export const PRERENDERED_ARTICLES_COUNT = 28 @@ -56,6 +57,11 @@ export const TopicView = (props: Props) => { setTopic(topics[props.topicSlug]) } }) + const [followers, setFollowers] = createSignal(props.followers || []) + const loadTopicFollowers = async () => { + const result = await apiClient.getTopicFollowers({ slug: props.topicSlug }) + setFollowers(result) + } const loadFavoriteTopArticles = async (topic: string) => { const options: LoadShoutsOptions = { @@ -89,8 +95,11 @@ export const TopicView = (props: Props) => { createEffect( on( - () => topic(), - () => loadRandom(), + () => topic()?.id, + (_) => { + loadTopicFollowers() + loadRandom() + }, { defer: true }, ), ) @@ -158,7 +167,7 @@ export const TopicView = (props: Props) => { - +
diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index bbfa00f4..cb9f4719 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -5,6 +5,7 @@ import type { LoadShoutsOptions, MutationDelete_ShoutArgs, ProfileInput, + QueryGet_Topic_FollowersArgs, QueryLoad_Authors_ByArgs, QueryLoad_Shouts_Random_TopArgs, QueryLoad_Shouts_SearchArgs, @@ -44,6 +45,7 @@ import authorsAll from '../query/core/authors-all' import authorsLoadBy from '../query/core/authors-load-by' import reactionsLoadBy from '../query/core/reactions-load-by' import topicBySlug from '../query/core/topic-by-slug' +import topicFollowers from '../query/core/topic-followers' import topicsAll from '../query/core/topics-all' import topicsRandomQuery from '../query/core/topics-random' @@ -129,6 +131,11 @@ export const apiClient = { return response.data.get_author_followers }, + getTopicFollowers: async ({ slug }: QueryGet_Topic_FollowersArgs): Promise => { + const response = await publicGraphQLClient.query(topicFollowers, { slug }).toPromise() + return response.data.get_topic_followers + }, + getAuthorFollows: async (params: { slug?: string author_id?: number diff --git a/src/graphql/query/core/topic-followers.ts b/src/graphql/query/core/topic-followers.ts new file mode 100644 index 00000000..1ec60ead --- /dev/null +++ b/src/graphql/query/core/topic-followers.ts @@ -0,0 +1,25 @@ +import { gql } from '@urql/core' + +export default gql` + query TopicFollowersQuery($slug: String) { + get_topic_followers(slug: $slug) { + id + slug + name + bio + about + pic + # communities + links + created_at + last_seen + stat { + shouts + authors + followers + rating + comments + } + } + } +` From 4e7cfa924118e27398e0cc03c667a167dd161715 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 24 May 2024 18:07:27 +0300 Subject: [PATCH 2/2] profile-fixes --- src/components/Views/Author/Author.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index b8414e40..905f3fc9 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -67,7 +67,7 @@ export const AuthorView = (props: Props) => { const { authors, profile, topics } = appdata setFollowers(myFollowers) setAuthor(profile) - setFollowing([...authors, ...topics]) + setFollowing([...(authors || []), ...(topics || [])]) } } }) @@ -260,7 +260,9 @@ export const AuthorView = (props: Props) => {
- +