modules/home/components/Project.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 78
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 2
eloc 69
mnd 2
bc 2
fnc 0
dl 0
loc 78
ccs 8
cts 14
cp 0.5714
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import React, { useState, useCallback } from 'react'
2
import { Translate } from 'react-localize-redux'
3
import Container from '~/modules/home/components/project/Container'
4
import Header from '~/modules/home/components/common/section/Header'
5
import Content from '~/modules/home/components/project/Content'
6
import SelectedImage from '~/modules/home/components/project/SelectedImage'
7
import { PROJECTS } from '~/modules/home/consts/pages'
8
import Anchor, {
9
  ANCHOR_DISTANCE_TO_TOP_OF_SECTION
10
} from '~/modules/home/components/common/Anchor'
11
import Gallery from 'react-photo-gallery'
12
import Carousel, { Modal, ModalGateway } from 'react-images'
13
import { photos } from '~/modules/home/consts/photos.js'
14
import useWindowDimensions from '~/modules/core/utils/useWindowDimensions'
15
16 1
const Project = () => {
17 1
  const { width } = useWindowDimensions()
18 1
  const [currentImage, setCurrentImage] = useState(0)
19 1
  const [viewerIsOpen, setViewerIsOpen] = useState(false)
20
21 1
  const openLightbox = useCallback(index => {
22
    setCurrentImage(index)
23
    setViewerIsOpen(true)
24
  }, [])
25
26 1
  const closeLightbox = () => {
27
    setCurrentImage(0)
28
    setViewerIsOpen(false)
29
  }
30 1
  const imageRenderer = useCallback(({ index, key, photo }) => (
31
    <SelectedImage
32
      key={key}
33
      margin={'2px'}
34
      index={index}
35
      photo={photo}
36
      onClick={openLightbox}
37
    />
38
  ))
39
40 1
  return (
41
    <Container>
42
      <Anchor id={PROJECTS} top={ANCHOR_DISTANCE_TO_TOP_OF_SECTION} />
43
      <Header>
44
        <h2>
45
          <Translate id="Project: Title" />
46
        </h2>
47
        <h4>
48
          <Translate id="Project: SubTitle" />
49
        </h4>
50
      </Header>
51
      <Content>
52
        <Gallery
53
          photos={photos}
54
          direction={width < 768 ? 'column' : 'row'}
55
          renderImage={imageRenderer}
56
        />
57
        <ModalGateway>
58
          {viewerIsOpen ? (
59
            <Modal onClose={closeLightbox}>
60
              <Carousel
61
                currentIndex={currentImage}
62
                views={photos.map(x => ({
63
                  ...x,
64
                  src: `${x.src}.jpg`,
65
                  srcSet: `${x.src}.jpg`,
66
                  caption: x.title
67
                }))}
68
              />
69
            </Modal>
70
          ) : null}
71
        </ModalGateway>
72
      </Content>
73
    </Container>
74
  )
75
}
76
77
export default Project
78