src/entities/MoviesCardsGrid/index.tsx   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 0

Size

Lines of Code 64
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 49
mnd 6
bc 6
fnc 0
dl 0
loc 64
rs 10
bpm 0
cpm 0
noi 26
c 0
b 0
f 0
1
import { FC } from 'react'
2
import { useQuery } from 'react-query'
3
import { Helmet } from 'react-helmet'
4
import { fetchMoviesList } from './model'
5
import { Grid, LoadingTape, Thumb } from 'shared/ui'
6
import { IMAGE_THUMB } from 'shared/config/images'
7
8
import NoImage from 'shared/assets/images/no_image.jpg'
9
10
interface IProps {
11
  currentPage: number
12
}
13
14
const MoviesCardsGrid: FC<IProps> = ({ currentPage }) => {
0 ignored issues
show
introduced by
Function component is not a function declaration
Loading history...
15
  const { isLoading, error, data } = useQuery(
0 ignored issues
show
introduced by
'error' is assigned a value but never used.
Loading history...
16
    ['moviesList', currentPage],
17
    () => fetchMoviesList(currentPage),
18
    {
19
      keepPreviousData: true,
20
    },
21
  )
22
23
  const IMAGE_URL = import.meta.env.APP_IMAGE_URL
24
25
  const imageLinksPreload = data?.movies?.map(({ poster_path }) => ({
26
    href: `${IMAGE_URL}/${IMAGE_THUMB.L}${poster_path}`,
27
    rel: 'preload',
28
    as: 'image',
29
  }))
30
31
  const renderedMoviesCards = data?.movies?.map(
32
    ({ genre_ids, id, title, poster_path, release_date, vote_average }) => {
33
      const moviePoster = poster_path
34
        ? `${IMAGE_URL}/${IMAGE_THUMB.L}${poster_path}`
35
        : NoImage
36
37
      return (
38
        <Thumb
0 ignored issues
show
introduced by
Expected indentation of 10 space characters but found 8.
Loading history...
introduced by
JSX not allowed in files with extension '.tsx'
Loading history...
39
          clickable
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
40
          key={id}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
41
          alt={title}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
42
          movieId={id}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
43
          title={title}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
44
          release={release_date}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
45
          genres={genre_ids.join(', ')}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
46
          rating={vote_average}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
47
          image={moviePoster}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
48
          isLazy
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
49
        />
50
      )
51
    },
52
  )
53
54
  return isLoading ? (
55
    <LoadingTape />
0 ignored issues
show
introduced by
Expected indentation of 6 space characters but found 4.
Loading history...
56
  ) : (
57
    <>
0 ignored issues
show
introduced by
Expected indentation of 6 space characters but found 4.
Loading history...
58
      <Helmet link={imageLinksPreload} />
0 ignored issues
show
introduced by
Expected indentation of 8 space characters but found 6.
Loading history...
59
      <Grid>{renderedMoviesCards}</Grid>
0 ignored issues
show
introduced by
Expected indentation of 8 space characters but found 6.
Loading history...
introduced by
JSX element should start in a new line
Loading history...
introduced by
{renderedMoviesCards} must be placed on a new line
Loading history...
60
    </>
61
  )
62
}
63
64
export { MoviesCardsGrid }
65