feed-comments-order-fix

This commit is contained in:
Untone 2024-03-01 16:04:28 +03:00
parent deebe79f55
commit 780f59f517
4 changed files with 24 additions and 39 deletions

View File

@ -2,7 +2,8 @@
@include font-size(1.2rem); @include font-size(1.2rem);
color: var(--secondary-color); color: var(--secondary-color);
//align-self: center;
// align-self: center;
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;
justify-content: flex-start; justify-content: flex-start;

View File

@ -1,15 +1,15 @@
import {clsx} from 'clsx' import { clsx } from 'clsx'
import {createMemo, createSignal, For, lazy, onMount, Show} from 'solid-js' import { For, Show, createMemo, createSignal, lazy, onMount } from 'solid-js'
import {useLocalize} from '../../context/localize' import { useLocalize } from '../../context/localize'
import {useReactions} from '../../context/reactions' import { useReactions } from '../../context/reactions'
import {useSession} from '../../context/session' import { useSession } from '../../context/session'
import {Author, Reaction, ReactionKind, ReactionSort} from '../../graphql/schema/core.gen' import { Author, Reaction, ReactionKind, ReactionSort } from '../../graphql/schema/core.gen'
import {byCreated, byStat} from '../../utils/sortby' import { byCreated, byStat } from '../../utils/sortby'
import {Button} from '../_shared/Button' import { Button } from '../_shared/Button'
import {ShowIfAuthenticated} from '../_shared/ShowIfAuthenticated' import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated'
import {Comment} from './Comment' import { Comment } from './Comment'
import styles from './Article.module.scss' import styles from './Article.module.scss'
@ -95,11 +95,7 @@ export const CommentsTree = (props: Props) => {
<ul class={clsx(styles.commentsViewSwitcher, 'view-switcher')}> <ul class={clsx(styles.commentsViewSwitcher, 'view-switcher')}>
<Show when={newReactions().length > 0}> <Show when={newReactions().length > 0}>
<li classList={{ 'view-switcher__item--selected': onlyNew() }}> <li classList={{ 'view-switcher__item--selected': onlyNew() }}>
<Button <Button variant="light" value={t('New only')} onClick={() => setOnlyNew(!onlyNew())} />
variant="light"
value={t('New only')}
onClick={() => setOnlyNew(!onlyNew())}
/>
</li> </li>
</Show> </Show>
<li classList={{ 'view-switcher__item--selected': commentsOrder() === ReactionSort.Newest }}> <li classList={{ 'view-switcher__item--selected': commentsOrder() === ReactionSort.Newest }}>

View File

@ -23,9 +23,9 @@ import { Row2 } from '../../Feed/Row2'
import { Row3 } from '../../Feed/Row3' import { Row3 } from '../../Feed/Row3'
import { Loading } from '../../_shared/Loading' import { Loading } from '../../_shared/Loading'
import { byCreated } from '../../../utils/sortby'
import stylesArticle from '../../Article/Article.module.scss' import stylesArticle from '../../Article/Article.module.scss'
import styles from './Author.module.scss' import styles from './Author.module.scss'
import {byCreated} from "../../../utils/sortby";
type Props = { type Props = {
shouts: Shout[] shouts: Shout[]

View File

@ -14,6 +14,7 @@ import { resetSortedArticles, useArticlesStore } from '../../../stores/zine/arti
import { useTopAuthorsStore } from '../../../stores/zine/topAuthors' import { useTopAuthorsStore } from '../../../stores/zine/topAuthors'
import { useTopicsStore } from '../../../stores/zine/topics' import { useTopicsStore } from '../../../stores/zine/topics'
import { getImageUrl } from '../../../utils/getImageUrl' import { getImageUrl } from '../../../utils/getImageUrl'
import { byCreated } from '../../../utils/sortby'
import { CommentDate } from '../../Article/CommentDate' import { CommentDate } from '../../Article/CommentDate'
import { getShareUrl } from '../../Article/SharePopup' import { getShareUrl } from '../../Article/SharePopup'
import { AuthorBadge } from '../../Author/AuthorBadge' import { AuthorBadge } from '../../Author/AuthorBadge'
@ -48,23 +49,11 @@ type VisibilityItem = {
} }
type FeedSearchParams = { type FeedSearchParams = {
by: 'publish_date' | 'likes_stat' | 'rating' | 'last_comment' by: 'publish_date' | 'likes' | 'comments'
period: FeedPeriod period: FeedPeriod
visibility: VisibilityMode 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 getFromDate = (period: FeedPeriod): number => {
const now = new Date() const now = new Date()
let d: Date = now let d: Date = now
@ -146,7 +135,7 @@ export const FeedView = (props: Props) => {
const loadTopComments = async () => { const loadTopComments = async () => {
const comments = await loadReactionsBy({ by: { comment: true }, limit: 50 }) const comments = await loadReactionsBy({ by: { comment: true }, limit: 50 })
setTopComments(comments) setTopComments(comments.sort(byCreated).reverse())
} }
onMount(() => { onMount(() => {
@ -178,9 +167,8 @@ export const FeedView = (props: Props) => {
offset: sortedArticles().length, offset: sortedArticles().length,
} }
const orderBy = getOrderBy(searchParams().by) if (searchParams()?.by) {
if (orderBy) { options.order_by = searchParams().by
options.order_by = orderBy
} }
const visibilityMode = searchParams().visibility const visibilityMode = searchParams().visibility
@ -222,7 +210,7 @@ export const FeedView = (props: Props) => {
const ogTitle = t('Feed') const ogTitle = t('Feed')
const [shareData, setShareData] = createSignal<Shout | undefined>() const [shareData, setShareData] = createSignal<Shout | undefined>()
const handleShare = (shared) => { const handleShare = (shared: Shout | undefined) => {
showModal('share') showModal('share')
setShareData(shared) setShareData(shared)
} }
@ -260,19 +248,19 @@ export const FeedView = (props: Props) => {
{/*</li>*/} {/*</li>*/}
<li <li
class={clsx({ class={clsx({
'view-switcher__item--selected': searchParams().by === 'rating', 'view-switcher__item--selected': searchParams().by === 'likes',
})} })}
> >
<span class="link" onClick={() => changeSearchParams({ by: 'rating' })}> <span class="link" onClick={() => changeSearchParams({ by: 'likes' })}>
{t('Top rated')} {t('Top rated')}
</span> </span>
</li> </li>
<li <li
class={clsx({ class={clsx({
'view-switcher__item--selected': searchParams().by === 'last_comment', 'view-switcher__item--selected': searchParams().by === 'comments',
})} })}
> >
<span class="link" onClick={() => changeSearchParams({ by: 'last_comment' })}> <span class="link" onClick={() => changeSearchParams({ by: 'comments' })}>
{t('Most commented')} {t('Most commented')}
</span> </span>
</li> </li>