Passed
Push — feature/full-redesign ( 15f409...5bcc0f )
by Kevin Van
04:11
created

src/templates/NewsOverview.tsx   A

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 112
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 79
mnd 3
bc 3
fnc 0
dl 0
loc 112
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { graphql, Link } from "gatsby"
2
import React from "react"
3
import { CardTeaser } from "../components/Card"
4
import { Seo } from "../components/Seo"
5
import Layout from "../layouts"
6
import { NewsOverviewQuery } from "../Types/Article"
7
import "./NewsOverview.scss"
8
9
const NewsOverviewPage = ({ pageContext, data }: NewsOverviewQuery) => {
10
  const { group, index, first, last, pathPrefix } = pageContext
11
  const { categoryTags } = data
12
13
  const previousUrl = index - 1 === 1 ? `/${pathPrefix}/` : `/${pathPrefix}/${(index - 1).toString()}`
14
  const nextUrl = `/${pathPrefix}/${(index + 1).toString()}`
15
16
  return (
17
    <Layout>
18
      <header className="page_header__wrapper">
19
        <div className="page_header">
20
          <h1>Nieuwsarchief KCVV Elewijt</h1>
21
        </div>
22
      </header>
23
24
      <div className="newsoverview__wrapper page__wrapper">
25
        <section className={`archive__filter_wrapper`}>
26
          <h5>Filter op categorie</h5>
27
          <section className={`archive__filter_filters`}>
28
            <Link to={`/news/`} className={`btn btn--small`}>
29
              Alles
30
            </Link>
31
            {categoryTags.edges.map(({ node }) => (
32
              <Link to={node.path.alias} className={`btn btn--small`} key={node.name}>
33
                {node.name}
34
              </Link>
35
            ))}
36
          </section>
37
        </section>
38
        <main className={`newsoverview__content__wrapper newsoverview__content__wrapper--archive`}>
39
          {group.map(({ node }) => (
40
            <CardTeaser
41
              key={node.id}
42
              title={node.title}
43
              picture={
44
                node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
45
                  .gatsbyImageData
46
              }
47
              link={node.path.alias}
48
              tags={node.relationships?.field_tags}
49
              createTime={node.created}
50
            />
51
          ))}
52
        </main>
53
        <footer className={`archive__navigation_wrapper cell`}>
54
          <div className={`archive__navigation--previous`}>
55
            <NavLink test={first} url={previousUrl} text="&laquo; Vorige" />
56
          </div>
57
          <div className={`archive__navigation--next`}>
58
            <NavLink test={last} url={nextUrl} text="Volgende &raquo;" />
59
          </div>
60
        </footer>
61
      </div>
62
    </Layout>
63
  )
64
}
65
66
export default NewsOverviewPage
67
68
export const Head = ({ pageContext }: NewsOverviewQuery) => {
69
  const { index, pathPrefix } = pageContext
70
  const pathName = `/${pathPrefix}/${index}`
71
  return <Seo title={`Nieuwsarchief - Pagina ${index}`} path={pathName} />
72
}
73
74
export const query = graphql`
75
  query {
76
    categoryTags: allTaxonomyTermCategory(
77
      sort: { fields: name, order: ASC }
78
      filter: {
79
        status: { eq: true }
80
        relationships: { node__article: { elemMatch: { drupal_internal__nid: { gte: 1 } } } }
81
      }
82
    ) {
83
      edges {
84
        node {
85
          path {
86
            alias
87
          }
88
          name
89
        }
90
      }
91
    }
92
  }
93
`
94
95
interface NavLinkProps {
96
  test: boolean
97
  url: string
98
  text: string
99
}
100
101
const NavLink = ({ test, url, text }: NavLinkProps) => {
102
  if (!test) {
103
    return (
104
      <Link to={url} className="rich-link-center">
105
        {text}
106
      </Link>
107
    )
108
  } else {
109
    return <span>{text}</span>
110
  }
111
}
112