diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index 4287efe7..6842ce86 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -1,7 +1,6 @@ import { useSearchParams } from '@solidjs/router' import { clsx } from 'clsx' -import { For, Match, Show, Suspense, Switch, createEffect, createSignal, on } from 'solid-js' -import { useAuthors } from '~/context/authors' +import { For, Match, Show, Suspense, Switch, createEffect, createMemo, createSignal, on } from 'solid-js' import { useFeed } from '~/context/feed' import { useLocalize } from '~/context/localize' import { useTopics } from '~/context/topics' @@ -10,6 +9,7 @@ import { Author, AuthorsBy, LoadShoutsOptions, Shout, Topic } from '~/graphql/sc import { SHOUTS_PER_PAGE } from '~/routes/(main)' import { getUnixtime } from '~/utils/date' import { restoreScrollPosition, saveScrollPosition } from '~/utils/scroll' +import { byPublished, byStat } from '~/utils/sort' import styles from '../../styles/Topic.module.scss' import { Beside } from '../Feed/Beside' import { Row1 } from '../Feed/Row1' @@ -37,7 +37,6 @@ export const TopicView = (props: Props) => { const { t } = useLocalize() const { feedByTopic, addFeed } = useFeed() const { topicEntities } = useTopics() - const { authorsByTopic } = useAuthors() const [searchParams, changeSearchParams] = useSearchParams<{ by: TopicFeedSortBy }>() const [favoriteTopArticles, setFavoriteTopArticles] = createSignal([]) const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal([]) @@ -147,6 +146,14 @@ export const TopicView = (props: Props) => { }) */ + const topViewedShouts = createMemo(() => { + const loaded = feedByTopic()?.[props.topicSlug] || [] + const sss = [...loaded] as Shout[] + const sortfn = byStat('views') || byPublished + sortfn && sss.sort(sortfn as ((a: Shout, b: Shout) => number) | undefined) + return sss + }) + return (
}> @@ -204,42 +211,42 @@ export const TopicView = (props: Props) => { 0} keyed={true}> - - + + 0} keyed={true}> - 14}> - - + 7}> + + i % 3 === 0)} > {(_shout, index) => { const articles = sortedFeed() - .slice(19) + .slice(13) .slice(index() * 3, index() * 3 + 3) return ( <>