render-sync

This commit is contained in:
Untone 2024-06-06 12:04:01 +03:00
parent 89a55f7d15
commit c8ebb699e2
3 changed files with 70 additions and 52 deletions

View File

@ -9,7 +9,7 @@ import { useSession } from '../../context/session'
import { FollowingEntity } from '../../graphql/schema/core.gen' import { FollowingEntity } from '../../graphql/schema/core.gen'
import { Button } from '../_shared/Button' import { Button } from '../_shared/Button'
import { FollowingCounters } from '../_shared/FollowingCounters' import { FollowingCounters } from '../_shared/FollowingCounters/FollowingCounters'
import { Icon } from '../_shared/Icon' import { Icon } from '../_shared/Icon'
import styles from './Full.module.scss' import styles from './Full.module.scss'
@ -58,8 +58,8 @@ export const FullTopic = (props: Props) => {
<FollowingCounters <FollowingCounters
followers={props.followers} followers={props.followers}
followersAmount={props.topic?.stat?.followers} followersAmount={props.topic?.stat?.followers}
following={props.authors} authors={props.authors}
followingAmount={props.topic?.stat?.authors} authorsAmount={props.topic?.stat?.authors || props.authors?.length || 0}
/> />
</div> </div>

View File

@ -51,18 +51,17 @@ export const TopicView = (props: Props) => {
const [topic, setTopic] = createSignal<Topic>() const [topic, setTopic] = createSignal<Topic>()
createEffect( createEffect(
on( on([() => props.topicSlug, topic, topicEntities], ([slug, t, ttt]) => {
[topic, topicEntities], if (slug && !t && ttt) {
([t, ttt]) => { console.debug(`${ttt.length} topics preloaded`)
if (props.topicSlug && !t && ttt) { const current = ttt[slug]
setTopic(ttt[props.topicSlug]) console.debug(current)
loadTopicFollowers() setTopic(current)
loadTopicAuthors() loadTopicFollowers()
loadRandom() loadTopicAuthors()
} loadRandom()
}, }
{ defer: true }, }),
),
) )
const [followers, setFollowers] = createSignal<Author[]>(props.followers || []) const [followers, setFollowers] = createSignal<Author[]>(props.followers || [])

View File

@ -1,4 +1,4 @@
import { For, Show } from 'solid-js' import { For, Show, createMemo } from 'solid-js'
import { useLocalize } from '../../../context/localize' import { useLocalize } from '../../../context/localize'
@ -12,55 +12,74 @@ type Props = {
followersAmount?: number followersAmount?: number
following?: Array<Author | Topic> following?: Array<Author | Topic>
followingAmount?: number followingAmount?: number
authors?: Author[]
authorsAmount?: number
topics?: Topic[]
topicsAmount?: number
} }
const UserpicList = (props: { items: Array<Author | Topic> }) => (
<div class={styles.subscribersList}>
<For each={props.items.slice(0, 3)}>
{(item) => (
<Userpic
size="XS"
name={'name' in item ? item.name : 'title' in item ? item.title : ''}
userpic={item.pic}
class={styles.subscribersItem}
/>
)}
</For>
</div>
)
const Counter = (props: { count: number; label: string }) => (
<div class={styles.subscribersCounter}>{props.label}</div>
)
export const FollowingCounters = (props: Props) => { export const FollowingCounters = (props: Props) => {
const { t } = useLocalize() 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 ( return (
<> <>
<a href="?m=followers" class={styles.subscribers}> <a href="?m=followers" class={styles.subscribers}>
<Show when={props.followers && props.followers.length > 0}> <Show when={getFollowersCount() > 0}>
<div class={styles.subscribersList}> <UserpicList items={props.followers || []} />
<For each={props.followers.slice(0, 3)}>
{(f) => <Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} />}
</For>
</div>
</Show> </Show>
<div class={styles.subscribersCounter}> <Counter count={getFollowersCount()} label={t('some followers', { count: getFollowersCount() })} />
{t('some followers', {
count: props.followersAmount || props.followers.length || 0,
})}
</div>
</a> </a>
<a href="?m=following" class={styles.subscribers}> <a href="?m=following" class={styles.subscribers}>
<Show when={props.following && props.following.length > 0}> <Show when={getFollowingCount() > 0}>
<div class={styles.subscribersList}> <UserpicList items={props.following || []} />
<For each={props.following.slice(0, 3)}> </Show>
{(f) => { <Show
if ('name' in f) { when={getFollowingCount() > 0}
return ( fallback={
<Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} /> <>
) <Show when={getAuthorsCount() > 0}>
} <UserpicList items={props.authors || []} />
<Counter
if ('title' in f) { count={getAuthorsCount()}
return ( label={t('some authors', { count: getAuthorsCount() })}
<Userpic size={'XS'} name={f.title} userpic={f.pic} class={styles.subscribersItem} /> />
) </Show>
} <Show when={getTopicsCount() > 0}>
<Counter count={getTopicsCount()} label={t('some topics', { count: getTopicsCount() })} />
return null </Show>
}} </>
</For> }
</div> >
<Counter
count={getFollowingCount()}
label={t('some followings', { count: getFollowingCount() })}
/>
</Show> </Show>
<div class={styles.subscribersCounter}>
{t('some followings', {
count: props.followingAmount || props.following?.length || 0,
})}
</div>
</a> </a>
</> </>
) )