topics-render-fix

This commit is contained in:
Untone 2024-07-06 01:24:22 +03:00
parent de29d435ec
commit 2d5e9877ee
5 changed files with 12 additions and 14 deletions

View File

@ -220,7 +220,7 @@ export const Header = (props: Props) => {
onMouseOut={hideSubnavigation} onMouseOut={hideSubnavigation}
href="/topic" href="/topic"
active={isTopicsVisible()} active={isTopicsVisible()}
body={t('topics')} body={t('Topics')}
onClick={(event: MouseEvent) => handleToggleMenuByLink(event, 'topic')} onClick={(event: MouseEvent) => handleToggleMenuByLink(event, 'topic')}
/> />
<Link <Link
@ -377,7 +377,7 @@ export const Header = (props: Props) => {
<A href="/dogma">{t('Dogma')}</A> <A href="/dogma">{t('Dogma')}</A>
</li> </li>
<li> <li>
<A href="/principles">{t('Community Principles')}</A> <A href="/principles">{t('Our principles')}</A>
</li> </li>
<li> <li>
<A href="/guide">{t('Platform Guide')}</A> <A href="/guide">{t('Platform Guide')}</A>

View File

@ -34,11 +34,11 @@ export const AllAuthors = (props: Props) => {
const [searchParams] = useSearchParams<{ by?: string }>() const [searchParams] = useSearchParams<{ by?: string }>()
const { authorsSorted, addAuthors, setAuthorsSort } = useAuthors() const { authorsSorted, addAuthors, setAuthorsSort } = useAuthors()
createEffect(on(() => searchParams?.by || 'name', setAuthorsSort, {})) createEffect(on(() => searchParams?.by || 'name', setAuthorsSort, {}))
createEffect(() => addAuthors?.([...(props.authors || [])])) createEffect(on(() => props.authors || [], addAuthors, {}))
const filteredAuthors = createMemo(() => { const filteredAuthors = createMemo(() => {
const query = searchQuery().toLowerCase() const query = searchQuery().toLowerCase()
return authorsSorted?.().filter((a: Author) => a?.name?.toLowerCase().includes(query)) return authorsSorted?.()?.filter((a: Author) => a?.name?.toLowerCase().includes(query)) || []
}) })
const byLetterFiltered = createMemo<{ [letter: string]: Author[] }>(() => { const byLetterFiltered = createMemo<{ [letter: string]: Author[] }>(() => {
@ -165,7 +165,7 @@ export const AllAuthors = (props: Props) => {
</Show> </Show>
<Show when={searchParams?.by !== 'name' && props.isLoaded}> <Show when={searchParams?.by !== 'name' && props.isLoaded}>
<AuthorsList <AuthorsList
allAuthorsLength={authorsSorted?.()?.length || 0} allAuthorsLength={authorsSorted()?.length || 0}
searchQuery={searchQuery()} searchQuery={searchQuery()}
query={searchParams?.by === 'followers' ? 'followers' : 'shouts'} query={searchParams?.by === 'followers' ? 'followers' : 'shouts'}
/> />

View File

@ -1,7 +1,7 @@
import { Meta } from '@solidjs/meta' import { Meta } from '@solidjs/meta'
import { A, useSearchParams } from '@solidjs/router' import { A, useSearchParams } from '@solidjs/router'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { For, Show, createEffect, createMemo, createSignal, on } from 'solid-js' import { For, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js'
import { Loading } from '~/components/_shared/Loading' import { Loading } from '~/components/_shared/Loading'
import { SearchField } from '~/components/_shared/SearchField' import { SearchField } from '~/components/_shared/SearchField'
import { useLocalize } from '~/context/localize' import { useLocalize } from '~/context/localize'
@ -31,8 +31,9 @@ export const AllTopics = (props: Props) => {
const alphabet = createMemo(() => ABC[lang()]) const alphabet = createMemo(() => ABC[lang()])
const { setTopicsSort, sortedTopics } = useTopics() const { setTopicsSort, sortedTopics } = useTopics()
const topics = createMemo(() => sortedTopics() || props.topics) const topics = createMemo(() => sortedTopics() || props.topics)
const [searchParams] = useSearchParams<{ by?: string }>() const [searchParams, changeSearchParams] = useSearchParams<{ by?: string }>()
createEffect(on(() => searchParams?.by || 'shouts', setTopicsSort, {})) createEffect(on(() => searchParams?.by || 'shouts', setTopicsSort, {defer:true}))
onMount(() => setTimeout(() => !searchParams?.by && changeSearchParams({ by: 'shouts'}), 1))
// sorted derivative // sorted derivative
const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => { const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => {

View File

@ -113,7 +113,7 @@ export const TopicsProvider = (props: { children: JSX.Element }) => {
createEffect(() => { createEffect(() => {
const topics = Object.values(topicEntities()) const topics = Object.values(topicEntities())
console.debug('[context.topics] effect trig', topics) // console.debug('[context.topics] effect trig', topics)
switch (sortAllBy()) { switch (sortAllBy()) {
case 'followers': { case 'followers': {
topics.sort(byTopicStatDesc('followers')) topics.sort(byTopicStatDesc('followers'))

View File

@ -1,9 +1,8 @@
import { RouteDefinition, RouteLoadFuncArgs, type RouteSectionProps, createAsync } from '@solidjs/router' import { RouteDefinition, RouteLoadFuncArgs, type RouteSectionProps, createAsync } from '@solidjs/router'
import { Suspense, createEffect } from 'solid-js' import { Suspense } from 'solid-js'
import { AllAuthors } from '~/components/Views/AllAuthors' import { AllAuthors } from '~/components/Views/AllAuthors'
import { Loading } from '~/components/_shared/Loading' import { Loading } from '~/components/_shared/Loading'
import { PageLayout } from '~/components/_shared/PageLayout' import { PageLayout } from '~/components/_shared/PageLayout'
import { useAuthors } from '~/context/authors'
import { useLocalize } from '~/context/localize' import { useLocalize } from '~/context/localize'
import { ReactionsProvider } from '~/context/reactions' import { ReactionsProvider } from '~/context/reactions'
import { loadAuthors } from '~/graphql/api/public' import { loadAuthors } from '~/graphql/api/public'
@ -48,9 +47,7 @@ export const route = {
export default function AllAuthorsPage(props: RouteSectionProps<{ authors: Author[] }>) { export default function AllAuthorsPage(props: RouteSectionProps<{ authors: Author[] }>) {
const { t } = useLocalize() const { t } = useLocalize()
const authors = createAsync<Author[]>(async () => props.data.authors || (await fetchData()) || []) const authors = createAsync<Author[]>(async () => props.data.authors || await fetchData())
const { addAuthors } = useAuthors()
createEffect(() => addAuthors(authors() || []))
return ( return (
<PageLayout withPadding={true} title={`${t('Discours')} :: ${t('All authors')}`}> <PageLayout withPadding={true} title={`${t('Discours')} :: ${t('All authors')}`}>
<ReactionsProvider> <ReactionsProvider>