expo top fix, feed right column loading state (#339)

Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com>
This commit is contained in:
Igor Lobanov 2023-12-18 14:22:20 +01:00 committed by GitHub
parent ffde754a43
commit c1356d77aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 72 deletions

View File

@ -45,8 +45,8 @@ export const Expo = (props: Props) => {
shouts: isLoaded() ? props.shouts : [], shouts: isLoaded() ? props.shouts : [],
}) })
const getLoadShoutsFilters = (filters: LoadShoutsFilters = {}): LoadShoutsFilters => { const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => {
const result = { ...filters } const filters = { ...additionalFilters }
if (props.layout) { if (props.layout) {
filters.layout = props.layout filters.layout = props.layout
@ -54,7 +54,7 @@ export const Expo = (props: Props) => {
filters.excludeLayout = 'article' filters.excludeLayout = 'article'
} }
return result return filters
} }
const loadMore = async (count: number) => { const loadMore = async (count: number) => {

View File

@ -55,8 +55,8 @@ export const Feed = (props: Props) => {
const { t } = useLocalize() const { t } = useLocalize()
const { page, searchParams } = useRouter<FeedSearchParams>() const { page, searchParams } = useRouter<FeedSearchParams>()
const [isLoading, setIsLoading] = createSignal(false) const [isLoading, setIsLoading] = createSignal(false)
const [isRightColumnLoaded, setIsRightColumnLoaded] = createSignal(false)
// state
const { sortedArticles } = useArticlesStore() const { sortedArticles } = useArticlesStore()
const { topTopics } = useTopicsStore() const { topTopics } = useTopicsStore()
const { topAuthors } = useTopAuthorsStore() const { topAuthors } = useTopAuthorsStore()
@ -73,9 +73,15 @@ export const Feed = (props: Props) => {
setUnratedArticles(result) setUnratedArticles(result)
} }
const loadTopComments = async () => {
const comments = await loadReactionsBy({ by: { comment: true }, limit: 5 })
setTopComments(comments)
}
onMount(() => { onMount(() => {
loadMore() loadMore()
loadUnratedArticles() // eslint-disable-next-line promise/catch-or-return
Promise.all([loadUnratedArticles(), loadTopComments()]).finally(() => setIsRightColumnLoaded(true))
}) })
createEffect( createEffect(
@ -118,12 +124,6 @@ export const Feed = (props: Props) => {
setIsLoadMoreButtonVisible(hasMore) setIsLoadMoreButtonVisible(hasMore)
} }
onMount(async () => {
// load 5 recent comments overall
const comments = await loadReactionsBy({ by: { comment: true }, limit: 5 })
setTopComments(comments)
})
const ogImage = getImageUrl('production/image/logo_image.png') const ogImage = getImageUrl('production/image/logo_image.png')
const description = t( const description = t(
'Independent media project about culture, science, art and society with horizontal editing', 'Independent media project about culture, science, art and society with horizontal editing',
@ -221,6 +221,8 @@ export const Feed = (props: Props) => {
</div> </div>
<aside class={clsx('col-md-7 col-xl-6 offset-xl-1', styles.feedAside)}> <aside class={clsx('col-md-7 col-xl-6 offset-xl-1', styles.feedAside)}>
<Show when={isRightColumnLoaded()}>
<Show when={topComments().length > 0}>
<section class={styles.asideSection}> <section class={styles.asideSection}>
<h4>{t('Comments')}</h4> <h4>{t('Comments')}</h4>
<For each={topComments()}> <For each={topComments()}>
@ -247,6 +249,7 @@ export const Feed = (props: Props) => {
}} }}
</For> </For>
</section> </section>
</Show>
<Show when={topTopics().length > 0}> <Show when={topTopics().length > 0}>
<section class={styles.asideSection}> <section class={styles.asideSection}>
@ -282,10 +285,13 @@ export const Feed = (props: Props) => {
<section class={clsx(styles.asideSection)}> <section class={clsx(styles.asideSection)}>
<h4>{t('Be the first to rate')}</h4> <h4>{t('Be the first to rate')}</h4>
<For each={unratedArticles()}> <For each={unratedArticles()}>
{(article) => <ArticleCard article={article} settings={{ noimage: true, nodate: true }} />} {(article) => (
<ArticleCard article={article} settings={{ noimage: true, nodate: true }} />
)}
</For> </For>
</section> </section>
</Show> </Show>
</Show>
</aside> </aside>
</div> </div>
</div> </div>