From 76e7a7e9bb90173787f8bc7508dca5ec3d3da3f4 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 24 Feb 2020 02:29:01 +0300 Subject: [PATCH] collective page card style changed; pass common card data to grid --- pages/collective.tsx | 63 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/pages/collective.tsx b/pages/collective.tsx index 95345efa..98cc04c9 100644 --- a/pages/collective.tsx +++ b/pages/collective.tsx @@ -4,24 +4,27 @@ import { App } from 'src/components/App' import { Meta } from 'src/components/Meta' import { CollectiveImage } from 'src/components/CollectiveImage' import { meta } from 'src/lib/meta' -import { IMeta, IImage } from 'src/types' +import { IMeta, Person } from 'src/types' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage, NextPageContext } from 'next' import { CardGrid } from 'src/components/CardGrid' import { Card } from 'src/components/Card' +import { Block } from 'src/components/Block' -interface IPerson { - url: string - name: string - position: string - picture: IImage +type CardData = { + title: string + caption?: string + imageSrc: string + imageAlt: string + imageSrcSet: string + href: string } type Props = { title: string image: string meta: IMeta - data: IPerson[] + data: CardData[] } const Page: NextPage = props => { @@ -52,24 +55,26 @@ const Page: NextPage = props => { - {props.data.map((item, index) => ( + {props.data.map(item => ( -

- {item.name[0]} {item.name[1]} {item.name[2]} -

- {item.position} + + {item.title} + + {item.caption} + +
))}
@@ -78,14 +83,24 @@ const Page: NextPage = props => { } export const unstable_getStaticProps = async (ctx: NextPageContext) => { - // const pageUrl = ctx.req.url - - const res = await requestGet>(createApiUrl('/api/persons'), null) - const data = res?.items || [] + const res = await requestGet>(createApiUrl('/api/persons'), null) const title = 'Преподаватели Шлиссельбургской ДХШ' const imageFile = 'Images/HudozkaCollective2017.jpg' const resImage = await requestGet(createApiUrl(`/api/image?file=${imageFile}`), null) const image = get(resImage, 'artifacts.large', null) + const data: CardData[] = (res?.items || []) + .map(x => { + const title = `${x.name[0]} ${x.name[1]} ${x.name[2]}` + return { + title, + caption: x.position, + href: x.url, + imageSrc: x.picture.src, + imageAlt: title, + imageSrcSet: '', + } + }) + return { props: {