all-authors-dummy

This commit is contained in:
Untone 2024-07-01 16:41:22 +03:00
parent a8d7a28297
commit b855e1c11f
2 changed files with 71 additions and 3 deletions

63
src/routes/authors.tsx Normal file
View File

@ -0,0 +1,63 @@
import { RouteDefinition, RouteLoadFuncArgs, type RouteSectionProps, createAsync } from '@solidjs/router'
import { Suspense, createEffect } from 'solid-js'
import { AllAuthors } from '~/components/Views/AllAuthors'
import { useAuthors } from '~/context/authors'
import { Author, QueryLoad_Authors_ByArgs } from '~/graphql/schema/core.gen'
import { loadAuthors } from '~/lib/api'
import { Loading } from '../components/_shared/Loading'
import { PageLayout } from '../components/_shared/PageLayout'
import { useLocalize } from '../context/localize'
import { ReactionsProvider } from '../context/reactions'
const fetchData = async () => {
const opts: QueryLoad_Authors_ByArgs = {
by: {
after: undefined,
created_at: undefined,
last_seen: undefined,
name: undefined,
order: undefined,
slug: undefined,
stat: undefined,
topic: undefined
}
}
const topicsFetcher = loadAuthors(opts)
return await topicsFetcher()
}
const AUTHORS_PER_PAGE = 20
export const route = {
load: (_args: RouteLoadFuncArgs) => {
const opts: QueryLoad_Authors_ByArgs = {
by: {
after: undefined,
created_at: undefined,
last_seen: undefined,
name: undefined,
order: undefined,
slug: undefined,
stat: undefined,
topic: undefined
},
limit: AUTHORS_PER_PAGE,
offset: 0
}
return loadAuthors(opts)
}
} satisfies RouteDefinition
export default function AllTopicsPage(props: RouteSectionProps<{ authors: Author[] }>) {
const { t } = useLocalize()
const authors = createAsync<Author[]>(async () => props.data.authors || (await fetchData()) || [])
const { addAuthors } = useAuthors()
createEffect(() => addAuthors(authors() || []))
return (
<PageLayout withPadding={true} title={`${t('Discours')}:${t('All topics')}`}>
<ReactionsProvider>
<Suspense fallback={<Loading />}>
<AllAuthors authors={authors() || []} isLoaded={Boolean(authors?.())} />
</Suspense>
</ReactionsProvider>
</PageLayout>
)
}

View File

@ -11,7 +11,6 @@ import { LoadShoutsOptions, Shout, Topic } from '~/graphql/schema/core.gen'
import { loadShouts } from '~/lib/api'
import { SHOUTS_PER_PAGE } from '../(home)'
const fetchTopicShouts = async (slug: string) => {
const opts: LoadShoutsOptions = { filters: { topic: slug }, limit: SHOUTS_PER_PAGE }
const shoutsLoader = loadShouts(opts)
@ -23,7 +22,9 @@ export const route = {
}
export const TopicPage = (props: RouteSectionProps<{ articles: Shout[] }>) => {
const articles = createAsync(async () => props.data.articles || (await fetchTopicShouts(props.params.slug)) || [])
const articles = createAsync(
async () => props.data.articles || (await fetchTopicShouts(props.params.slug)) || []
)
const { topicEntities } = useTopics()
const { t } = useLocalize()
const topic = createMemo(() => topicEntities?.()[props.params.slug])
@ -52,7 +53,11 @@ export const TopicPage = (props: RouteSectionProps<{ articles: Shout[] }>) => {
cover={topic()?.pic || ''}
>
<ReactionsProvider>
<TopicView topic={topic() as Topic} topicSlug={props.params.slug} shouts={articles() as Shout[]}/>
<TopicView
topic={topic() as Topic}
topicSlug={props.params.slug}
shouts={articles() as Shout[]}
/>
</ReactionsProvider>
</PageLayout>
</Suspense>