From 423af46377cb8253645d134b52f165590cd4dfdc Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 29 Feb 2024 23:46:15 +0300 Subject: [PATCH 1/3] fixed --- .../Views/AllAuthors/AllAuthors.tsx | 2 ++ src/components/Views/AllTopics/AllTopics.tsx | 2 +- src/components/Views/Feed/Feed.tsx | 29 +++++-------------- src/pages/allAuthors.page.server.ts | 6 ++-- src/pages/types.ts | 2 ++ 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/components/Views/AllAuthors/AllAuthors.tsx b/src/components/Views/AllAuthors/AllAuthors.tsx index 3934a73d..9509b7bf 100644 --- a/src/components/Views/AllAuthors/AllAuthors.tsx +++ b/src/components/Views/AllAuthors/AllAuthors.tsx @@ -23,6 +23,8 @@ type AllAuthorsPageSearchParams = { type Props = { authors: Author[] + topFollowedAuthors?: Author[] + topWritingAuthors?: Author[] isLoaded: boolean } diff --git a/src/components/Views/AllTopics/AllTopics.tsx b/src/components/Views/AllTopics/AllTopics.tsx index 36548a33..3fe6243d 100644 --- a/src/components/Views/AllTopics/AllTopics.tsx +++ b/src/components/Views/AllTopics/AllTopics.tsx @@ -28,7 +28,7 @@ type Props = { isLoaded: boolean } -const PAGE_SIZE = 20 +export const PAGE_SIZE = 20 export const AllTopics = (props: Props) => { const { t, lang } = useLocalize() diff --git a/src/components/Views/Feed/Feed.tsx b/src/components/Views/Feed/Feed.tsx index 2a886a10..9f07159b 100644 --- a/src/components/Views/Feed/Feed.tsx +++ b/src/components/Views/Feed/Feed.tsx @@ -48,23 +48,11 @@ type VisibilityItem = { } type FeedSearchParams = { - by: 'publish_date' | 'likes_stat' | 'rating' | 'last_comment' + by: 'publish_date' | 'likes' | 'comments' period: FeedPeriod visibility: VisibilityMode } -const getOrderBy = (by: FeedSearchParams['by']) => { - if (by === 'likes_stat' || by === 'rating') { - return 'likes_stat' - } - - if (by === 'last_comment') { - return 'last_comment' - } - - return '' -} - const getFromDate = (period: FeedPeriod): number => { const now = new Date() let d: Date = now @@ -178,9 +166,8 @@ export const FeedView = (props: Props) => { offset: sortedArticles().length, } - const orderBy = getOrderBy(searchParams().by) - if (orderBy) { - options.order_by = orderBy + if (searchParams()?.by) { + options.order_by = searchParams().by } const visibilityMode = searchParams().visibility @@ -222,7 +209,7 @@ export const FeedView = (props: Props) => { const ogTitle = t('Feed') const [shareData, setShareData] = createSignal() - const handleShare = (shared) => { + const handleShare = (shared: Shout | undefined) => { showModal('share') setShareData(shared) } @@ -260,19 +247,19 @@ export const FeedView = (props: Props) => { {/**/}
  • - changeSearchParams({ by: 'rating' })}> + changeSearchParams({ by: 'likes' })}> {t('Top rated')}
  • - changeSearchParams({ by: 'last_comment' })}> + changeSearchParams({ by: 'comments' })}> {t('Most commented')}
  • diff --git a/src/pages/allAuthors.page.server.ts b/src/pages/allAuthors.page.server.ts index dcc8681b..5fbd4992 100644 --- a/src/pages/allAuthors.page.server.ts +++ b/src/pages/allAuthors.page.server.ts @@ -2,11 +2,13 @@ import type { PageContext } from '../renderer/types' import type { PageProps } from './types' import { apiClient } from '../graphql/client/core' +import { PAGE_SIZE } from "../components/Views/AllTopics/AllTopics"; export const onBeforeRender = async (_pageContext: PageContext) => { const allAuthors = await apiClient.getAllAuthors() - - const pageProps: PageProps = { allAuthors, seo: { title: '' } } + const topWritingAuthors = await apiClient.loadAuthorsBy({ by: { order: 'shouts' }, limit: PAGE_SIZE}) + const topFollowedAuthors = await apiClient.loadAuthorsBy({ by: { order: 'followers' }, limit: PAGE_SIZE}) + const pageProps: PageProps = { allAuthors, seo: { title: '' }, topWritingAuthors, topFollowedAuthors } return { pageContext: { diff --git a/src/pages/types.ts b/src/pages/types.ts index 96701c6c..af588d9f 100644 --- a/src/pages/types.ts +++ b/src/pages/types.ts @@ -10,6 +10,8 @@ export type PageProps = { homeShouts?: Shout[] author?: Author allAuthors?: Author[] + topWritingAuthors?: Author[] + topFollowedAuthors?: Author[] topic?: Topic allTopics?: Topic[] searchQuery?: string From 72610d10b5d832b235b6f9de212e0e81532a385e Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 29 Feb 2024 23:54:34 +0300 Subject: [PATCH 2/3] wip --- src/pages/allAuthors.page.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/allAuthors.page.tsx b/src/pages/allAuthors.page.tsx index 7079e8af..b0a78e38 100644 --- a/src/pages/allAuthors.page.tsx +++ b/src/pages/allAuthors.page.tsx @@ -5,10 +5,11 @@ import { createEffect, createSignal, onMount } from 'solid-js' import { AllAuthors } from '../components/Views/AllAuthors/' import { PageLayout } from '../components/_shared/PageLayout' import { useLocalize } from '../context/localize' -import { loadAllAuthors } from '../stores/zine/authors' +import {loadAllAuthors, loadAuthors} from '../stores/zine/authors' +import {PAGE_SIZE} from "../components/Views/AllTopics/AllTopics"; export const AllAuthorsPage = (props: PageProps) => { - const [isLoaded, setIsLoaded] = createSignal(Boolean(props.allAuthors)) + const [isLoaded, setIsLoaded] = createSignal(Boolean(props.allAuthors && props.topFollowedAuthors && props.topWritingAuthors)) const { t } = useLocalize() @@ -18,12 +19,14 @@ export const AllAuthorsPage = (props: PageProps) => { } await loadAllAuthors() + await loadAuthors({ by: { order: 'shouts' }, limit: PAGE_SIZE }) + await loadAuthors({ by: { order: 'followers' }, limit: PAGE_SIZE }) setIsLoaded(true) }) return ( - + ) } From d0be8ffb6a0a6af5d9fbf3fa4bd71cbdb3e07c4c Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 1 Mar 2024 00:11:59 +0300 Subject: [PATCH 3/3] minor --- .../CommentDate/CommentDate.module.scss | 2 +- src/components/Article/CommentsTree.tsx | 26 ++++++++----------- src/components/Views/Author/Author.tsx | 2 +- src/pages/allAuthors.page.server.ts | 14 +++++++--- src/pages/allAuthors.page.tsx | 19 +++++++++----- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/components/Article/CommentDate/CommentDate.module.scss b/src/components/Article/CommentDate/CommentDate.module.scss index 20410cce..61e3b465 100644 --- a/src/components/Article/CommentDate/CommentDate.module.scss +++ b/src/components/Article/CommentDate/CommentDate.module.scss @@ -2,7 +2,7 @@ @include font-size(1.2rem); color: var(--secondary-color); - //align-self: center; + align-self: center; display: flex; align-items: flex-start; justify-content: flex-start; diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index cf28fcfd..60054831 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -1,15 +1,15 @@ -import {clsx} from 'clsx' -import {createMemo, createSignal, For, lazy, onMount, Show} from 'solid-js' +import { clsx } from 'clsx' +import { For, Show, createMemo, createSignal, lazy, onMount } from 'solid-js' -import {useLocalize} from '../../context/localize' -import {useReactions} from '../../context/reactions' -import {useSession} from '../../context/session' -import {Author, Reaction, ReactionKind, ReactionSort} from '../../graphql/schema/core.gen' -import {byCreated, byStat} from '../../utils/sortby' -import {Button} from '../_shared/Button' -import {ShowIfAuthenticated} from '../_shared/ShowIfAuthenticated' +import { useLocalize } from '../../context/localize' +import { useReactions } from '../../context/reactions' +import { useSession } from '../../context/session' +import { Author, Reaction, ReactionKind, ReactionSort } from '../../graphql/schema/core.gen' +import { byCreated, byStat } from '../../utils/sortby' +import { Button } from '../_shared/Button' +import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated' -import {Comment} from './Comment' +import { Comment } from './Comment' import styles from './Article.module.scss' @@ -95,11 +95,7 @@ export const CommentsTree = (props: Props) => {
      0}>
    • -
    • diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 352d8f6c..1649d92c 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -23,9 +23,9 @@ import { Row2 } from '../../Feed/Row2' import { Row3 } from '../../Feed/Row3' import { Loading } from '../../_shared/Loading' +import { byCreated } from '../../../utils/sortby' import stylesArticle from '../../Article/Article.module.scss' import styles from './Author.module.scss' -import {byCreated} from "../../../utils/sortby"; type Props = { shouts: Shout[] diff --git a/src/pages/allAuthors.page.server.ts b/src/pages/allAuthors.page.server.ts index 5fbd4992..cefcdb28 100644 --- a/src/pages/allAuthors.page.server.ts +++ b/src/pages/allAuthors.page.server.ts @@ -1,13 +1,21 @@ import type { PageContext } from '../renderer/types' import type { PageProps } from './types' +import { PAGE_SIZE } from '../components/Views/AllTopics/AllTopics' import { apiClient } from '../graphql/client/core' -import { PAGE_SIZE } from "../components/Views/AllTopics/AllTopics"; export const onBeforeRender = async (_pageContext: PageContext) => { const allAuthors = await apiClient.getAllAuthors() - const topWritingAuthors = await apiClient.loadAuthorsBy({ by: { order: 'shouts' }, limit: PAGE_SIZE}) - const topFollowedAuthors = await apiClient.loadAuthorsBy({ by: { order: 'followers' }, limit: PAGE_SIZE}) + const topWritingAuthors = await apiClient.loadAuthorsBy({ + by: { order: 'shouts' }, + limit: PAGE_SIZE, + offset: 0, + }) + const topFollowedAuthors = await apiClient.loadAuthorsBy({ + by: { order: 'followers' }, + limit: PAGE_SIZE, + offset: 0, + }) const pageProps: PageProps = { allAuthors, seo: { title: '' }, topWritingAuthors, topFollowedAuthors } return { diff --git a/src/pages/allAuthors.page.tsx b/src/pages/allAuthors.page.tsx index b0a78e38..c49dc26e 100644 --- a/src/pages/allAuthors.page.tsx +++ b/src/pages/allAuthors.page.tsx @@ -3,13 +3,15 @@ import type { PageProps } from './types' import { createEffect, createSignal, onMount } from 'solid-js' import { AllAuthors } from '../components/Views/AllAuthors/' +import { PAGE_SIZE } from '../components/Views/AllTopics/AllTopics' import { PageLayout } from '../components/_shared/PageLayout' import { useLocalize } from '../context/localize' -import {loadAllAuthors, loadAuthors} from '../stores/zine/authors' -import {PAGE_SIZE} from "../components/Views/AllTopics/AllTopics"; +import { loadAllAuthors, loadAuthors } from '../stores/zine/authors' export const AllAuthorsPage = (props: PageProps) => { - const [isLoaded, setIsLoaded] = createSignal(Boolean(props.allAuthors && props.topFollowedAuthors && props.topWritingAuthors)) + const [isLoaded, setIsLoaded] = createSignal( + Boolean(props.allAuthors && props.topFollowedAuthors && props.topWritingAuthors), + ) const { t } = useLocalize() @@ -19,14 +21,19 @@ export const AllAuthorsPage = (props: PageProps) => { } await loadAllAuthors() - await loadAuthors({ by: { order: 'shouts' }, limit: PAGE_SIZE }) - await loadAuthors({ by: { order: 'followers' }, limit: PAGE_SIZE }) + await loadAuthors({ by: { order: 'shouts' }, limit: PAGE_SIZE, offset: 0 }) + await loadAuthors({ by: { order: 'followers' }, limit: PAGE_SIZE, offset: 0 }) setIsLoaded(true) }) return ( - + ) }