Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1211 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1211 Rev 1212
Línea 1... Línea 1...
1
import React, { useMemo } from 'react'
1
import React, { useMemo } from 'react'
2
import Pagination from 'react-bootstrap/Pagination'
2
import { Pagination } from '@mui/material'
3
import styled from 'styled-components'
3
import styled from 'styled-components'
Línea 4... Línea 4...
4
 
4
 
5
const StyledPagination = styled(Pagination)`
5
const StyledPagination = styled(Pagination)`
6
  display: flex;
6
  display: flex;
Línea 19... Línea 19...
19
}) => {
19
}) => {
20
  const currentPage = useMemo(
20
  const currentPage = useMemo(
21
    () => Number(currentActivePage) || 1,
21
    () => Number(currentActivePage) || 1,
22
    [currentActivePage]
22
    [currentActivePage]
23
  )
23
  )
24
  const maxPages = Math.min(pages, 5)
-
 
25
 
-
 
26
  const generatePageNumbers = (start, end) => {
-
 
27
    return Array.from({ length: end - start + 1 }, (_, index) => start + index)
-
 
28
  }
-
 
29
 
-
 
30
  const previousPages = generatePageNumbers(
-
 
31
    Math.max(1, currentPage - 1 - maxPages),
-
 
32
    currentPage - 1
-
 
33
  )
-
 
34
  const nextPages = generatePageNumbers(
-
 
35
    currentPage + 1,
-
 
36
    Math.min(pages, currentPage + maxPages)
-
 
37
  )
-
 
38
 
-
 
39
  const handlePageChange = (page) => {
-
 
40
    onChangePage(page)
-
 
41
  }
-
 
Línea 42... Línea 24...
42
 
24
 
43
  if (pages <= 1) {
25
  if (pages <= 1) {
44
    return null
26
    return null
Línea 45... Línea 27...
45
  }
27
  }
46
 
28
 
47
  return (
29
  return (
48
    <StyledPagination>
30
    <StyledPagination
49
      <Pagination.Prev
31
      count={pages}
50
        disabled={currentPage <= 1}
-
 
51
        onClick={() => handlePageChange(currentPage - 1)}
-
 
52
      />
-
 
53
 
-
 
54
      {previousPages.map((page) => (
-
 
55
        <Pagination.Item key={page} onClick={() => handlePageChange(page)}>
32
      page={currentPage}
56
          {page}
-
 
57
        </Pagination.Item>
-
 
58
      ))}
-
 
59
 
-
 
60
      <Pagination.Item active>{currentPage}</Pagination.Item>
-
 
61
 
-
 
62
      {nextPages.map((page) => (
-
 
63
        <Pagination.Item key={page} onClick={() => handlePageChange(page)}>
33
      onChange={(_, page) => onChangePage(page)}
64
          {page}
-
 
65
        </Pagination.Item>
-
 
66
      ))}
34
      variant='outlined'
67
 
-
 
68
      <Pagination.Next
-
 
69
        onClick={() => handlePageChange(currentPage + 1)}
35
      shape='rounded'
70
        disabled={currentPage >= pages}
-
 
71
      />
36
      isRow={isRow}
72
    </StyledPagination>
37
    />
Línea 73... Línea 38...
73
  )
38
  )