Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Commit

Permalink
updatedAt value with teams page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuboczoch committed Oct 7, 2021
1 parent f7f80b8 commit 61898d9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/components/elements/Layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import React from 'react'
import format from 'date-fns/format'

import Page from '../../blocks/Page'
import { LayoutProps } from './index'
import Container from '../Container'
import theme from '../../../assets/theme'
import Columns from '../Columns'

const Footer = (props: Omit<Omit<LayoutProps, 'title'>, 'children'>) => (
export interface IFooter {
updatedAt?: Date
}

const Footer = (props: IFooter) => (
<Page.Footer {...props}>
<Page.Footer.Nav>
<Container>
Expand All @@ -30,15 +33,14 @@ const Footer = (props: Omit<Omit<LayoutProps, 'title'>, 'children'>) => (
</a>
</div>
<div />
{props.contentPage.sys.updatedAt && (
{props.updatedAt && (
<div>
<span
className={css`
opacity: 0.5;
`}
>
Last modified:{' '}
{format(new Date(props.contentPage.sys.updatedAt), 'dd.MM.yyyy kk:mm')}
Last modified: {format(new Date(props.updatedAt), 'dd.MM.yyyy kk:mm')}
</span>
</div>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/components/elements/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import Head from 'next/head'
import Providers from './Providers'
import Page from '../../blocks/Page'
import Header from './Header'
import Footer from './Footer'
import Footer, { IFooter } from './Footer'

import { ILayoutData } from '../../../utils/contentful/models/getLayoutData'
import { IMetaTag } from '../../../../@types/generated/contentful'
import { IContentPageData } from '../../../utils/contentful/models/getContentPageData'

export interface LayoutProps extends ILayoutData, IContentPageData {
export interface LayoutProps extends ILayoutData, IContentPageData, IFooter {
children: ReactChild
title?: string
metaTags?: IMetaTag[]
Expand All @@ -27,7 +27,7 @@ const Layout = ({ title, children, metaTags, ...props }: LayoutProps) => (
<Page>
<Header {...props} />
<Page.Content {...props} children={children} />
<Footer {...props} />
<Footer {...props} updatedAt={props.updatedAt ?? new Date(props.contentPage.sys.updatedAt)} />
</Page>
</Providers>
)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { GetStaticPaths, GetStaticProps } from 'next'
import React from 'react'

import Layout from '../components/elements/Layout'
import getLayoutData, { ILayoutData } from '../utils/contentful/models/getLayoutData'
Expand Down
3 changes: 2 additions & 1 deletion src/pages/coordinates-calculation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GetStaticProps } from 'next'
import React from 'react'

import Layout from '../components/elements/Layout'
Expand All @@ -21,7 +22,7 @@ const CoordinatesCalculation = (props: ICoordinatesCalculationPageProps) => (
</Layout>
)

export const getStaticProps = async (): Promise<{ props: ICoordinatesCalculationPageProps }> => {
export const getStaticProps: GetStaticProps<ICoordinatesCalculationPageProps> = async () => {
const layout = await getLayoutData()
const contentPage = await getContentPageData('coordinates-calculation')
const coordinatesData = await getCoordinatesData()
Expand Down
3 changes: 2 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GetStaticProps } from 'next'
import React from 'react'

import Layout from '../components/elements/Layout'
Expand All @@ -17,7 +18,7 @@ const Home = (props: IHomePageProps) => (
</Layout>
)

export const getStaticProps = async (): Promise<{ props: IHomePageProps }> => {
export const getStaticProps: GetStaticProps<IHomePageProps> = async () => {
const layout = await getLayoutData()
const contentPage = await getContentPageData('')

Expand Down
13 changes: 12 additions & 1 deletion src/pages/teams.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GetStaticProps } from 'next'
import React from 'react'

import Layout from '../components/elements/Layout'
Expand All @@ -20,12 +21,22 @@ const CoordinatesCalculation = (props: IWarTeamsPageProps) => (
{...props}
title={`${props.contentPage?.fields.title} | ${props.layout.fields.projectNameShort}`}
metaTags={props.contentPage.fields.metaTags}
updatedAt={
new Date(
[...props.warTeamsPage.fields.groupA, ...props.warTeamsPage.fields.groupB].sort(
(groupA, groupB) =>
new Date(groupA.sys.updatedAt).getTime() < new Date(groupB.sys.updatedAt).getTime()
? 1
: -1
)?.[0].sys.updatedAt ?? props.contentPage.sys.updatedAt
)
}
>
<WarTeamsPage {...props} />
</Layout>
)

export const getStaticProps = async (): Promise<{ props: IWarTeamsPageProps }> => {
export const getStaticProps: GetStaticProps<IWarTeamsPageProps> = async () => {
const layout = await getLayoutData()
const contentPage = await getContentPageData('teams')
const coordinatesData = await getCoordinatesData()
Expand Down

0 comments on commit 61898d9

Please sign in to comment.