src/feature/pagination/Pagination.tsx   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 96
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 79
mnd 4
bc 4
fnc 0
dl 0
loc 96
rs 10
bpm 0
cpm 0
noi 60
c 0
b 0
f 0
1
import { FC } from 'react'
2
import { useStore } from 'effector-react'
3
import { useQueryClient } from 'react-query'
4
import { prevPage, nextPage, setPage, $page, $isAscending } from './model'
5
import { usePagination, DOTS } from './usePagination'
6
import { useCustomEventDetail } from 'shared/hooks/useCustomEventDetail'
7
import { fetchMoviesList } from 'entities/MoviesCardsGrid/model'
8
import { Text } from 'shared/ui'
9
10
import { IPagination } from './types'
11
12
import clsx from 'clsx'
13
import styles from './Pagination.module.scss'
14
15
const Pagination: FC<IPagination> = ({ siblingCount = 1 }) => {
0 ignored issues
show
introduced by
Function component is not a function declaration
Loading history...
16
  const isAscending = useStore($isAscending)
17
  const currentPage = useStore($page)
18
19
  const totalPages = useCustomEventDetail('gotTotalPages')
20
21
  const queryClient = useQueryClient()
22
23
  const prefetchPage = async (pageParam: number) => {
24
    await queryClient.prefetchQuery(['moviesList', pageParam], () =>
25
      fetchMoviesList(pageParam),
26
    )
27
  }
28
29
  const paginationRange = usePagination({
30
    currentPage,
31
    totalPages,
32
    siblingCount,
33
  }) as number[]
34
35
  if (currentPage === 0 || paginationRange?.length < 2) {
36
    return null
37
  }
38
39
  return (
40
    <div className={styles.paginationWrapper}>
0 ignored issues
show
introduced by
Expected indentation of 6 space characters but found 4.
Loading history...
introduced by
JSX not allowed in files with extension '.tsx'
Loading history...
41
      <ul className={styles.pagination}>
0 ignored issues
show
introduced by
Expected indentation of 8 space characters but found 6.
Loading history...
42
        <li
0 ignored issues
show
introduced by
Visible, non-interactive elements with click handlers must have at least one keyboard listener.
Loading history...
introduced by
Non-interactive elements should not be assigned mouse or keyboard event listeners.
Loading history...
introduced by
Expected indentation of 10 space characters but found 8.
Loading history...
43
          className={clsx(styles.paginationItem, {
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
44
            [styles['disabled']]: currentPage === 1,
45
          })}
46
          onClick={() => prevPage()}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
47
          onMouseEnter={() => prefetchPage(currentPage - 1)}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
48
          onMouseDownCapture={() => prefetchPage(currentPage - 1)}
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...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
49
        >
50
          <span className={styles.arrow}>&#10094;</span>
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
&#10094; must be placed on a new line
Loading history...
51
        </li>
52
        {paginationRange?.map((pageNumber: number, idx) => {
0 ignored issues
show
introduced by
Expected indentation of 10 space characters but found 8.
Loading history...
introduced by
JSX element should start in a new line
Loading history...
53
          if (pageNumber === DOTS) {
54
            return (
55
              <li
0 ignored issues
show
introduced by
Expected indentation of 16 space characters but found 14.
Loading history...
56
                key={`pagination-${idx}`}
0 ignored issues
show
introduced by
Expected indentation of 18 space characters but found 16.
Loading history...
introduced by
Do not use Array index in keys
Loading history...
57
                className={clsx(styles.paginationItem, styles.dots)}
0 ignored issues
show
introduced by
Expected indentation of 18 space characters but found 16.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
58
              >
0 ignored issues
show
introduced by
Expected indentation of 18 space characters but found 16.
Loading history...
59
                ...
60
              </li>
61
            )
62
          }
63
64
          return (
65
            <li
0 ignored issues
show
introduced by
Visible, non-interactive elements with click handlers must have at least one keyboard listener.
Loading history...
introduced by
Non-interactive elements should not be assigned mouse or keyboard event listeners.
Loading history...
introduced by
Expected indentation of 14 space characters but found 12.
Loading history...
66
              key={`pagination-${idx}`}
0 ignored issues
show
introduced by
Expected indentation of 16 space characters but found 14.
Loading history...
introduced by
Do not use Array index in keys
Loading history...
67
              className={clsx(styles.paginationItem, {
0 ignored issues
show
introduced by
Expected indentation of 16 space characters but found 14.
Loading history...
introduced by
Props should be sorted alphabetically
Loading history...
68
                [styles['paginationForward']]:
69
                  pageNumber > 1 && pageNumber < totalPages && isAscending,
70
                [styles['paginationBackward']]:
71
                  pageNumber > 1 && pageNumber < totalPages && !isAscending,
72
                [styles['selected']]: pageNumber === currentPage,
73
              })}
74
              onClick={() => setPage(pageNumber)}
0 ignored issues
show
introduced by
Expected indentation of 16 space characters but found 14.
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
75
              onMouseEnter={() => prefetchPage(pageNumber)}
0 ignored issues
show
introduced by
Expected indentation of 16 space characters but found 14.
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
76
            >
77
              <Text tag="span">{pageNumber}</Text>
0 ignored issues
show
introduced by
Expected indentation of 16 space characters but found 14.
Loading history...
introduced by
{pageNumber} must be placed on a new line
Loading history...
78
            </li>
79
          )
80
        })}
81
        <li
0 ignored issues
show
introduced by
Visible, non-interactive elements with click handlers must have at least one keyboard listener.
Loading history...
introduced by
Non-interactive elements should not be assigned mouse or keyboard event listeners.
Loading history...
introduced by
Expected indentation of 10 space characters but found 8.
Loading history...
introduced by
JSX element should start in a new line
Loading history...
82
          className={clsx(styles.paginationItem, {
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
83
            [styles['disabled']]: currentPage === totalPages,
84
          })}
85
          onClick={() => nextPage()}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
86
          onMouseEnter={() => prefetchPage(currentPage + 1)}
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
87
          onMouseDownCapture={() => prefetchPage(currentPage + 1)}
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...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
88
        >
89
          <span className={styles.arrow}>&#10095;</span>
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
&#10095; must be placed on a new line
Loading history...
90
        </li>
91
      </ul>
92
    </div>
93
  )
94
}
95
96
export { Pagination }
97