From c8ebb699e2a214829c8b7f213bccfadc9934b9e0 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 6 Jun 2024 12:04:01 +0300 Subject: [PATCH] render-sync --- src/components/Topic/Full.tsx | 6 +- src/components/Views/Topic.tsx | 23 +++-- .../FollowingCounters/FollowingCounters.tsx | 93 +++++++++++-------- 3 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/components/Topic/Full.tsx b/src/components/Topic/Full.tsx index e434b4b1..34a9d4d4 100644 --- a/src/components/Topic/Full.tsx +++ b/src/components/Topic/Full.tsx @@ -9,7 +9,7 @@ import { useSession } from '../../context/session' import { FollowingEntity } from '../../graphql/schema/core.gen' import { Button } from '../_shared/Button' -import { FollowingCounters } from '../_shared/FollowingCounters' +import { FollowingCounters } from '../_shared/FollowingCounters/FollowingCounters' import { Icon } from '../_shared/Icon' import styles from './Full.module.scss' @@ -58,8 +58,8 @@ export const FullTopic = (props: Props) => { diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index 785560f1..0a56b036 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -51,18 +51,17 @@ export const TopicView = (props: Props) => { const [topic, setTopic] = createSignal() createEffect( - on( - [topic, topicEntities], - ([t, ttt]) => { - if (props.topicSlug && !t && ttt) { - setTopic(ttt[props.topicSlug]) - loadTopicFollowers() - loadTopicAuthors() - loadRandom() - } - }, - { defer: true }, - ), + on([() => props.topicSlug, topic, topicEntities], ([slug, t, ttt]) => { + if (slug && !t && ttt) { + console.debug(`${ttt.length} topics preloaded`) + const current = ttt[slug] + console.debug(current) + setTopic(current) + loadTopicFollowers() + loadTopicAuthors() + loadRandom() + } + }), ) const [followers, setFollowers] = createSignal(props.followers || []) diff --git a/src/components/_shared/FollowingCounters/FollowingCounters.tsx b/src/components/_shared/FollowingCounters/FollowingCounters.tsx index fc2228da..99508fc0 100644 --- a/src/components/_shared/FollowingCounters/FollowingCounters.tsx +++ b/src/components/_shared/FollowingCounters/FollowingCounters.tsx @@ -1,4 +1,4 @@ -import { For, Show } from 'solid-js' +import { For, Show, createMemo } from 'solid-js' import { useLocalize } from '../../../context/localize' @@ -12,55 +12,74 @@ type Props = { followersAmount?: number following?: Array followingAmount?: number + authors?: Author[] + authorsAmount?: number + topics?: Topic[] + topicsAmount?: number } +const UserpicList = (props: { items: Array }) => ( +
+ + {(item) => ( + + )} + +
+) + +const Counter = (props: { count: number; label: string }) => ( +
{props.label}
+) + export const FollowingCounters = (props: Props) => { const { t } = useLocalize() + const getFollowersCount = createMemo(() => props.followersAmount || props.followers?.length || 0) + const getFollowingCount = createMemo(() => props.followingAmount || props.following?.length || 0) + const getAuthorsCount = createMemo(() => props.authorsAmount || props.authors?.length || 0) + const getTopicsCount = createMemo(() => props.topicsAmount || props.topics?.length || 0) + return ( <> - 0}> -
- - {(f) => } - -
+ 0}> + -
- {t('some followers', { - count: props.followersAmount || props.followers.length || 0, - })} -
+
- 0}> -
- - {(f) => { - if ('name' in f) { - return ( - - ) - } - - if ('title' in f) { - return ( - - ) - } - - return null - }} - -
+ 0}> + + + 0} + fallback={ + <> + 0}> + + + + 0}> + + + + } + > + -
- {t('some followings', { - count: props.followingAmount || props.following?.length || 0, - })} -
)