import { createEffect, createMemo, createSignal, For, onMount, Show } from 'solid-js' import '../../styles/Feed.scss' import stylesBeside from '../../components/Feed/Beside.module.scss' import { Icon } from '../_shared/Icon' import { ArticleCard } from '../Feed/Card' import { AuthorCard } from '../Author/Card' import { t } from '../../utils/intl' import { FeedSidebar } from '../Feed/Sidebar' import { Comment as CommentCard } from '../Article/Comment' import { loadShouts, useArticlesStore } from '../../stores/zine/articles' import { useReactionsStore } from '../../stores/zine/reactions' import { useAuthorsStore } from '../../stores/zine/authors' import { useTopicsStore } from '../../stores/zine/topics' import { useTopAuthorsStore } from '../../stores/zine/topAuthors' import { useSession } from '../../context/session' import stylesTopic from '../Feed/CardTopic.module.scss' import styles from './Feed.module.scss' import { clsx } from 'clsx' // const AUTHORSHIP_REACTIONS = [ // ReactionKind.Accept, // ReactionKind.Reject, // ReactionKind.Propose, // ReactionKind.Ask // ] export const FEED_PAGE_SIZE = 20 export const FeedView = () => { // state const { sortedArticles } = useArticlesStore() const { sortedReactions: topComments, loadReactionsBy } = useReactionsStore() const { sortedAuthors } = useAuthorsStore() const { topTopics } = useTopicsStore() const { topAuthors } = useTopAuthorsStore() const { session } = useSession() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const collaborativeShouts = createMemo(() => sortedArticles().filter((shout) => shout.visibility === 'authors') ) createEffect(async () => { if (collaborativeShouts()) { // load reactions on collaborativeShouts await loadReactionsBy({ by: { shouts: [...collaborativeShouts()] }, limit: 5 }) } }) const userslug = createMemo(() => session()?.user?.slug) createEffect(async () => { if (userslug()) { // load recent editing shouts ( visibility = authors ) await loadShouts({ filters: { author: userslug(), visibility: 'authors' }, limit: 15 }) } }) const loadMore = async () => { const { hasMore } = await loadShouts({ filters: { visibility: 'community' }, limit: FEED_PAGE_SIZE, offset: sortedArticles().length }) setIsLoadMoreButtonVisible(hasMore) } onMount(async () => { // load 5 recent comments overall await loadReactionsBy({ by: { comment: true }, limit: 5, offset: 0 }) // load recent shouts not only published ( visibility = community ) await loadMore() }) return ( <>