Test Failed
Pull Request — master (#397)
by Huu-Phat
06:07 queued 02:18
created

modules/home/components/Project.js   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 76
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 57.14%

Importance

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