import type { Author, LoadShoutsOptions, Reaction, Shout } from '../../graphql/types.gen' import { getPagePath } from '@nanostores/router' import { clsx } from 'clsx' import { createEffect, createSignal, For, on, onMount, Show } from 'solid-js' import { useLocalize } from '../../context/localize' import { useReactions } from '../../context/reactions' import { router, useRouter } from '../../stores/router' import { useArticlesStore, resetSortedArticles } from '../../stores/zine/articles' import { useTopAuthorsStore } from '../../stores/zine/topAuthors' import { useTopicsStore } from '../../stores/zine/topics' import { Icon } from '../_shared/Icon' import { Loading } from '../_shared/Loading' import { CommentDate } from '../Article/CommentDate' import { AuthorLink } from '../Author/AhtorLink' import { AuthorBadge } from '../Author/AuthorBadge' import { ArticleCard } from '../Feed/ArticleCard' import { Sidebar } from '../Feed/Sidebar' import styles from './Feed.module.scss' import stylesBeside from '../../components/Feed/Beside.module.scss' import stylesTopic from '../Feed/CardTopic.module.scss' export const FEED_PAGE_SIZE = 20 type FeedSearchParams = { by: 'publish_date' | 'rating' | 'last_comment' } const getOrderBy = (by: FeedSearchParams['by']) => { if (by === 'rating') { return 'rating_stat' } if (by === 'last_comment') { return 'last_comment' } return '' } type Props = { loadShouts: (options: LoadShoutsOptions) => Promise<{ hasMore: boolean; newShouts: Shout[] }> } export const FeedView = (props: Props) => { const { t } = useLocalize() const { page, searchParams } = useRouter() const [isLoading, setIsLoading] = createSignal(false) // state const { sortedArticles } = useArticlesStore() const { topTopics } = useTopicsStore() const { topAuthors } = useTopAuthorsStore() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [topComments, setTopComments] = createSignal([]) const { actions: { loadReactionsBy }, } = useReactions() onMount(() => { loadMore() }) createEffect( on( () => page().route + searchParams().by, () => { resetSortedArticles() loadMore() }, { defer: true }, ), ) const loadFeedShouts = () => { const options: LoadShoutsOptions = { limit: FEED_PAGE_SIZE, offset: sortedArticles().length, } const orderBy = getOrderBy(searchParams().by) if (orderBy) { options.order_by = orderBy } return props.loadShouts(options) } const loadMore = async () => { setIsLoading(true) const { hasMore, newShouts } = await loadFeedShouts() setIsLoading(false) loadReactionsBy({ by: { shouts: newShouts.map((s) => s.slug), }, }) setIsLoadMoreButtonVisible(hasMore) } onMount(async () => { // load 5 recent comments overall const comments = await loadReactionsBy({ by: { comment: true }, limit: 5 }) setTopComments(comments) }) return (
}> 0}> {(article) => }

{t('Popular authors')}

{t('All authors')}
    {(author) => (
  • )}
{(article) => }

) }