index page updated; ArticleGrid -> PageGrid

This commit is contained in:
tmshv committed 2020-03-03 02:31:42 +03:00
1 parent 85d2f7cc45
commit 970bdce53d
4 files changed
+40 -50

No files matched your search

+25 -9
View File
@@ -1,19 +1,19 @@
import Head from 'next/head'
import { App } from 'src/components/App'
import { Meta } from 'src/components/Meta'
import { ArticleGrid } from 'src/components/ArticleGrid'
import { PageGrid } from 'src/components/PageGrid'
import { HudozkaTitle } from 'src/components/HudozkaTitle'
import { meta, MetaBuilder } from 'src/lib/meta'
import { MetaBuilder } from 'src/lib/meta'
import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
import { NextPage } from 'next'
import { IArticle } from 'src/types'
import { IPage } from 'src/types'
interface IProps {
title: string
meta: any
prevPage: number
nextPage: number
articles: any[]
items: any[]
}
const Page: NextPage<IProps> = props => (
@@ -32,8 +32,8 @@ const Page: NextPage<IProps> = props => (
}}
/>
<ArticleGrid
articles={props.articles}
<PageGrid
items={props.items}
prevPage={props.prevPage}
nextPage={props.nextPage}
/>
@@ -42,10 +42,26 @@ const Page: NextPage<IProps> = props => (
export const unstable_getStaticProps = async () => {
const page = 1
const pageSize = process.env.APP_ARTICLES_PAGE_SIZE
const res = await requestGet<IResponseItems<IArticle>>(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), null)
// const pageSize = parseInt(process.env.APP_ARTICLES_PAGE_SIZE)
const pageSize = 300
const limit = pageSize
const skip = (page - 1) * pageSize
const tags = [
'event',
'album',
'post',
]
const tagQuery = tags
.map(x => `tag=${x}`)
.join('&')
const url = `/api/pages/tags?${tagQuery}&skip=${skip}&limit=${limit}&sortBy=-date`
const res = await requestGet<IResponseItems<IPage>>(createApiUrl(url), null)
const articles = (res.items || [])
const nextPage = res.nextPage
// const nextPage = res.nextPage
const nextPage = 2
const prevPage = res.prevPage
const title = 'Шлиссельбургская ДХШ'
const meta = (new MetaBuilder())
File renamed without changes.
@@ -1,4 +1,4 @@
import { IArticle, ImageDefinition } from 'src/types'
import { ImageDefinition, IPage } from 'src/types'
import { Pager } from '../Pager'
import { CardGrid } from '../CardGrid'
import { Card, CardLayout } from '../Card'
@@ -47,13 +47,13 @@ function getImage(image?: ImageDefinition) {
}
}
export type ArticleGridProps = {
articles: IArticle[]
export type PageGridProps = {
items: IPage[]
nextPage: number | null
prevPage: number | null
}
export const ArticleGrid: React.FC<ArticleGridProps> = ({ articles, nextPage, prevPage, ...props }) => {
export const PageGrid: React.FC<PageGridProps> = ({ items, nextPage, prevPage, ...props }) => {
const nextHref = nextPage ? `/articles/${nextPage}` : null
let prevHref = prevPage ? `/articles/${prevPage}` : null
if (prevPage === 1) {
@@ -67,32 +67,32 @@ export const ArticleGrid: React.FC<ArticleGridProps> = ({ articles, nextPage, pr
marginBottom: 'var(--size-m)',
}}
>
{articles.map((article, i) => {
const gridColumn = article.featured ? 'span 2' : 'auto'
const layout: CardLayout = article.featured ? 'featured' : 'simple'
const { src, srcSet } = getImage(article.preview)
{items.map((item, i) => {
const gridColumn = item.featured ? 'span 2' : 'auto'
const layout: CardLayout = item.featured ? 'featured' : 'simple'
const { src, srcSet } = getImage(item.preview)
const content = !article.featured
const content = !item.featured
? (
<Block
direction={'vertical'}
>
{article.title}
{item.title}
<Spacer />
<Date style={{
marginTop: 'var(--size-m)',
}}>{article.date}</Date>
}}>{item.date}</Date>
</Block>
) : (
article.title
item.title
)
return (
<Card
key={i}
href={article.url}
href={item.url}
img={{
alt: article.title,
alt: item.title,
src,
srcSet,
}}
+1 -27
View File
@@ -19,6 +19,7 @@ export interface IPage {
tokens: any[]
tags: ITag[]
breadcrumb?: IBreadcumbsPart[]
featured: boolean
}
export interface IDocument {
@@ -60,33 +61,6 @@ export interface ITag {
href: string
}
export interface IArticle {
id: string
date: string
tags: ITag[]
post:string
featured: boolean
url: string
title: string
preview: ImageDefinition
}
export type Person = {
id: string
position: string
name: [string, string, string]
post: string
diploma: string
edu: string
file: string
hash: string
shortName: string
status: string
url: string
picture: ImageArtifact
preview: ImageDefinition
}
export type ImageArtifact = {
width: number
height: number