49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { api } from '@/api';
|
|
import { ArticlesList } from '@/components/pages/BlogPage/ArticlesList';
|
|
import { ArticlesPageActions } from '@/components/pages/BlogPage/ArticlesPageActions';
|
|
import { getQueryClient } from '@/lib/queryClient';
|
|
import { IArticle } from '@/types/IArticle';
|
|
import { IStory } from '@/types/IStory';
|
|
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|
|
|
export default async function BlogPage({
|
|
searchParams: { tags = [] },
|
|
}: {
|
|
searchParams: {
|
|
tags?: string[];
|
|
};
|
|
}) {
|
|
const queryClient = getQueryClient();
|
|
|
|
await queryClient.prefetchQuery({
|
|
queryKey: ['articles'],
|
|
queryFn: async () => await api.get('articles').json<IArticle[]>(),
|
|
});
|
|
|
|
await queryClient.prefetchQuery({
|
|
queryKey: ['articles', tags],
|
|
queryFn: async ({ queryKey: [, tags] }) =>
|
|
await api
|
|
.get(
|
|
`articles?${
|
|
Array.isArray(tags)
|
|
? tags.map((tag) => `tags=${tag}`).join('&')
|
|
: 'tags=' + tags
|
|
}`
|
|
)
|
|
.json<IArticle[]>(),
|
|
});
|
|
|
|
await queryClient.prefetchQuery({
|
|
queryKey: ['stories'],
|
|
queryFn: async () => await api.get('stories').json<IStory[]>(),
|
|
});
|
|
|
|
return (
|
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
|
<ArticlesPageActions tags={tags} />
|
|
<ArticlesList tags={tags} />
|
|
</HydrationBoundary>
|
|
);
|
|
}
|