Add apiReqest to random topucs in Header (#220)
This commit is contained in:
parent
218c190d2e
commit
f060841672
|
@ -20,6 +20,8 @@ import { useLocalize } from '../../../context/localize'
|
||||||
import { useSession } from '../../../context/session'
|
import { useSession } from '../../../context/session'
|
||||||
|
|
||||||
import styles from './Header.module.scss'
|
import styles from './Header.module.scss'
|
||||||
|
import { apiClient } from '../../../utils/apiClient'
|
||||||
|
import { RANDOM_TOPICS_COUNT } from '../../Views/Home'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title?: string
|
title?: string
|
||||||
|
@ -28,7 +30,6 @@ type Props = {
|
||||||
articleBody?: string
|
articleBody?: string
|
||||||
cover?: string
|
cover?: string
|
||||||
scrollToComments?: (value: boolean) => void
|
scrollToComments?: (value: boolean) => void
|
||||||
randomTopics?: Topic[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HeaderSearchParams = {
|
type HeaderSearchParams = {
|
||||||
|
@ -46,6 +47,7 @@ export const Header = (props: Props) => {
|
||||||
|
|
||||||
const { page, searchParams } = useRouter<HeaderSearchParams>()
|
const { page, searchParams } = useRouter<HeaderSearchParams>()
|
||||||
|
|
||||||
|
const [randomTopics, setRandomTopics] = createSignal([])
|
||||||
const [getIsScrollingBottom, setIsScrollingBottom] = createSignal(false)
|
const [getIsScrollingBottom, setIsScrollingBottom] = createSignal(false)
|
||||||
const [getIsScrolled, setIsScrolled] = createSignal(false)
|
const [getIsScrolled, setIsScrolled] = createSignal(false)
|
||||||
const [fixed, setFixed] = createSignal(false)
|
const [fixed, setFixed] = createSignal(false)
|
||||||
|
@ -139,6 +141,10 @@ export const Header = (props: Props) => {
|
||||||
}, time)
|
}, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const topics = await apiClient.getRandomTopics({ amount: RANDOM_TOPICS_COUNT })
|
||||||
|
setRandomTopics(topics)
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
<header
|
<header
|
||||||
class={styles.mainHeader}
|
class={styles.mainHeader}
|
||||||
|
@ -337,8 +343,8 @@ export const Header = (props: Props) => {
|
||||||
onMouseOut={hideSubnavigation}
|
onMouseOut={hideSubnavigation}
|
||||||
>
|
>
|
||||||
<ul class="nodash">
|
<ul class="nodash">
|
||||||
<Show when={props.randomTopics && props.randomTopics.length > 0}>
|
<Show when={randomTopics().length > 0}>
|
||||||
<For each={props.randomTopics}>
|
<For each={randomTopics()}>
|
||||||
{(topic) => (
|
{(topic) => (
|
||||||
<li class="item">
|
<li class="item">
|
||||||
<a href={`/topic/${topic.slug}`}>
|
<a href={`/topic/${topic.slug}`}>
|
||||||
|
|
|
@ -25,8 +25,7 @@ import { splitToPages } from '../../utils/splitToPages'
|
||||||
import { ArticleCard } from '../Feed/ArticleCard'
|
import { ArticleCard } from '../Feed/ArticleCard'
|
||||||
import { useLocalize } from '../../context/localize'
|
import { useLocalize } from '../../context/localize'
|
||||||
|
|
||||||
type HomeProps = {
|
type Props = {
|
||||||
randomTopics: Topic[]
|
|
||||||
shouts: Shout[]
|
shouts: Shout[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ export const RANDOM_TOPICS_COUNT = 12
|
||||||
const CLIENT_LOAD_ARTICLES_COUNT = 29
|
const CLIENT_LOAD_ARTICLES_COUNT = 29
|
||||||
const LOAD_MORE_PAGE_SIZE = 16 // Row1 + Row3 + Row2 + Beside (3 + 1) + Row1 + Row 2 + Row3
|
const LOAD_MORE_PAGE_SIZE = 16 // Row1 + Row3 + Row2 + Beside (3 + 1) + Row1 + Row 2 + Row3
|
||||||
|
|
||||||
export const HomeView = (props: HomeProps) => {
|
export const HomeView = (props: Props) => {
|
||||||
const {
|
const {
|
||||||
sortedArticles,
|
sortedArticles,
|
||||||
articlesByLayout,
|
articlesByLayout,
|
||||||
|
@ -47,9 +46,7 @@ export const HomeView = (props: HomeProps) => {
|
||||||
shouts: props.shouts
|
shouts: props.shouts
|
||||||
})
|
})
|
||||||
|
|
||||||
const { topTopics } = useTopicsStore({
|
const { topTopics } = useTopicsStore()
|
||||||
randomTopics: props.randomTopics
|
|
||||||
})
|
|
||||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
||||||
const { topAuthors } = useTopAuthorsStore()
|
const { topAuthors } = useTopAuthorsStore()
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import styles from './PageLayout.module.scss'
|
||||||
import { Meta } from '@solidjs/meta'
|
import { Meta } from '@solidjs/meta'
|
||||||
import { Topic } from '../../graphql/types.gen'
|
import { Topic } from '../../graphql/types.gen'
|
||||||
|
|
||||||
type PageLayoutProps = {
|
type Props = {
|
||||||
headerTitle?: string
|
headerTitle?: string
|
||||||
slug?: string
|
slug?: string
|
||||||
articleBody?: string
|
articleBody?: string
|
||||||
|
@ -20,10 +20,9 @@ type PageLayoutProps = {
|
||||||
class?: string
|
class?: string
|
||||||
withPadding?: boolean
|
withPadding?: boolean
|
||||||
scrollToComments?: (value: boolean) => void
|
scrollToComments?: (value: boolean) => void
|
||||||
randomTopics?: Topic[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PageLayout = (props: PageLayoutProps) => {
|
export const PageLayout = (props: Props) => {
|
||||||
const isHeaderFixed = props.isHeaderFixed === undefined ? true : props.isHeaderFixed
|
const isHeaderFixed = props.isHeaderFixed === undefined ? true : props.isHeaderFixed
|
||||||
const [scrollToComments, setScrollToComments] = createSignal<boolean>(false)
|
const [scrollToComments, setScrollToComments] = createSignal<boolean>(false)
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ export const PageLayout = (props: PageLayoutProps) => {
|
||||||
cover={props.articleBody}
|
cover={props.articleBody}
|
||||||
isHeaderFixed={isHeaderFixed}
|
isHeaderFixed={isHeaderFixed}
|
||||||
scrollToComments={(value) => setScrollToComments(value)}
|
scrollToComments={(value) => setScrollToComments(value)}
|
||||||
randomTopics={props.randomTopics}
|
|
||||||
/>
|
/>
|
||||||
<main
|
<main
|
||||||
class={clsx('main-content', {
|
class={clsx('main-content', {
|
||||||
|
|
|
@ -18,7 +18,7 @@ export const AllTopicsPage = (props: PageProps) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout randomTopics={props.randomTopics}>
|
<PageLayout>
|
||||||
<Show when={isLoaded()} fallback={<Loading />}>
|
<Show when={isLoaded()} fallback={<Loading />}>
|
||||||
<AllTopicsView topics={props.allTopics} />
|
<AllTopicsView topics={props.allTopics} />
|
||||||
</Show>
|
</Show>
|
||||||
|
|
|
@ -4,13 +4,12 @@ import type { PageProps } from './types'
|
||||||
import { PRERENDERED_ARTICLES_COUNT, RANDOM_TOPICS_COUNT } from '../components/Views/Home'
|
import { PRERENDERED_ARTICLES_COUNT, RANDOM_TOPICS_COUNT } from '../components/Views/Home'
|
||||||
|
|
||||||
export const onBeforeRender = async (_pageContext: PageContext) => {
|
export const onBeforeRender = async (_pageContext: PageContext) => {
|
||||||
const randomTopics = await apiClient.getRandomTopics({ amount: RANDOM_TOPICS_COUNT })
|
|
||||||
const homeShouts = await apiClient.getShouts({
|
const homeShouts = await apiClient.getShouts({
|
||||||
filters: { visibility: 'public' },
|
filters: { visibility: 'public' },
|
||||||
limit: PRERENDERED_ARTICLES_COUNT
|
limit: PRERENDERED_ARTICLES_COUNT
|
||||||
})
|
})
|
||||||
|
|
||||||
const pageProps: PageProps = { randomTopics, homeShouts }
|
const pageProps: PageProps = { homeShouts }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageContext: {
|
pageContext: {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { useLocalize } from '../context/localize'
|
||||||
import { ReactionsProvider } from '../context/reactions'
|
import { ReactionsProvider } from '../context/reactions'
|
||||||
|
|
||||||
export const HomePage = (props: PageProps) => {
|
export const HomePage = (props: PageProps) => {
|
||||||
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeShouts) && Boolean(props.randomTopics))
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeShouts))
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
@ -27,11 +27,11 @@ export const HomePage = (props: PageProps) => {
|
||||||
onCleanup(() => resetSortedArticles())
|
onCleanup(() => resetSortedArticles())
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout randomTopics={props.randomTopics} withPadding={true}>
|
<PageLayout withPadding={true}>
|
||||||
<ReactionsProvider>
|
<ReactionsProvider>
|
||||||
<Title>{t('Discours')}</Title>
|
<Title>{t('Discours')}</Title>
|
||||||
<Show when={isLoaded()} fallback={<Loading />}>
|
<Show when={isLoaded()} fallback={<Loading />}>
|
||||||
<HomeView randomTopics={props.randomTopics} shouts={props.homeShouts || []} />
|
<HomeView shouts={props.homeShouts || []} />
|
||||||
</Show>
|
</Show>
|
||||||
</ReactionsProvider>
|
</ReactionsProvider>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
|
|
|
@ -3,7 +3,6 @@ import type { Author, Chat, Shout, Topic } from '../graphql/types.gen'
|
||||||
|
|
||||||
// all the things (she said) that could be passed from the server
|
// all the things (she said) that could be passed from the server
|
||||||
export type PageProps = {
|
export type PageProps = {
|
||||||
randomTopics?: Topic[]
|
|
||||||
article?: Shout
|
article?: Shout
|
||||||
layoutShouts?: Shout[]
|
layoutShouts?: Shout[]
|
||||||
authorShouts?: Shout[]
|
authorShouts?: Shout[]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user