index page update; rest module
This commit is contained in:
1 parent
5e8ee6eec9
commit
087a4b6172
2 files changed
+36
-31
No files matched your search
+10
-31
@@ -4,19 +4,17 @@ import { Meta } from 'src/components/Meta'
|
||||
import { PageGrid } from 'src/components/PageGrid'
|
||||
import { HudozkaTitle } from 'src/components/HudozkaTitle'
|
||||
import { MetaBuilder } from 'src/lib/meta'
|
||||
import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
||||
import { getPagesCardsByTags } from 'src/rest'
|
||||
import { NextPage } from 'next'
|
||||
import { IPage } from 'src/types'
|
||||
import { IPage, IMeta } from 'src/types'
|
||||
|
||||
interface IProps {
|
||||
title: string
|
||||
meta: any
|
||||
prevPage: number
|
||||
nextPage: number
|
||||
items: any[]
|
||||
meta: IMeta
|
||||
items: IPage[]
|
||||
}
|
||||
|
||||
const Page: NextPage<IProps> = props => (
|
||||
const Index: NextPage<IProps> = props => (
|
||||
<App
|
||||
showAuthor={true}
|
||||
wide={true}
|
||||
@@ -34,35 +32,18 @@ const Page: NextPage<IProps> = props => (
|
||||
|
||||
<PageGrid
|
||||
items={props.items}
|
||||
prevPage={props.prevPage}
|
||||
nextPage={props.nextPage}
|
||||
prevPage={null}
|
||||
nextPage={null}
|
||||
/>
|
||||
</App>
|
||||
)
|
||||
|
||||
export const unstable_getStaticProps = async () => {
|
||||
const page = 1
|
||||
// const pageSize = parseInt(process.env.APP_ARTICLES_PAGE_SIZE)
|
||||
const pageSize = 300
|
||||
|
||||
const limit = pageSize
|
||||
const skip = (page - 1) * pageSize
|
||||
|
||||
const tags = [
|
||||
const items = await getPagesCardsByTags([
|
||||
'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 items = (res.items || [])
|
||||
// const nextPage = res.nextPage
|
||||
const nextPage = 2
|
||||
const prevPage = res.prevPage
|
||||
])
|
||||
const title = 'Шлиссельбургская ДХШ'
|
||||
const meta = (new MetaBuilder())
|
||||
.setTitle(title)
|
||||
@@ -74,12 +55,10 @@ export const unstable_getStaticProps = async () => {
|
||||
return {
|
||||
props: {
|
||||
items,
|
||||
nextPage,
|
||||
prevPage,
|
||||
title,
|
||||
meta,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Page
|
||||
export default Index
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { createApiUrl, requestGet, IResponseItems } from './next-lib'
|
||||
import { IPage } from './types'
|
||||
|
||||
export type QuerySlice = {
|
||||
skip: number
|
||||
limit: number
|
||||
sortBy: string
|
||||
}
|
||||
|
||||
export async function getPagesByTags(tags: string[], { skip, limit, sortBy }: QuerySlice) {
|
||||
const tagQuery = tags
|
||||
.map(x => `tag=${x}`)
|
||||
.join('&')
|
||||
|
||||
const url = `/api/pages/tags?${tagQuery}&skip=${skip}&limit=${limit}&sortBy=${sortBy}`
|
||||
const res = await requestGet<IResponseItems<IPage>>(createApiUrl(url), null)
|
||||
|
||||
return res?.items
|
||||
}
|
||||
|
||||
export async function getPagesCardsByTags(tags: string[]) {
|
||||
const skip = 0
|
||||
const limit = 1000
|
||||
|
||||
return getPagesByTags(tags, { skip, limit, sortBy: '-date' })
|
||||
}
|
||||
Reference in new issue
Block a user