浏览代码

paginar plazas

amenpunk 2 年之前
父节点
当前提交
616da515dd
共有 4 个文件被更改,包括 59 次插入15 次删除
  1. 4 0
      src/App.css
  2. 4 3
      src/Components/Puestos/GridMode.jsx
  3. 2 2
      src/Components/Puestos/ListMode.jsx
  4. 49 10
      src/Pages/Puestos.jsx

+ 4 - 0
src/App.css

@@ -215,4 +215,8 @@
215 215
 .btn_plaza_common:hover{
216 216
     color:var(--second) !important;
217 217
 }
218
+.center_pagination_puestos{
219
+    display :flex;
220
+    flex-direction :row;
221
+}
218 222
 

+ 4 - 3
src/Components/Puestos/GridMode.jsx

@@ -12,13 +12,14 @@ import { Row, Col } from 'react-bootstrap'
12 12
 
13 13
 export function GridMode(props){
14 14
 
15
-    let { setEdit, setDelete, setShow, setPuesto, data } = props;
15
+    let { setEdit, setDelete, setShow, setPuesto, data ,index} = props;
16
+    console.log('data reci', data,index)
16 17
 
17 18
     return(
18 19
         <React.Fragment> 
19 20
             {
20 21
                 data.length ? 
21
-                    data.map( plaza => {
22
+                    data[index].map( plaza => {
22 23
                         return(
23 24
                             <Col key={plaza.id} lg="4" md="6" sm="6" xs="12" >
24 25
                                 <div className="panel">
@@ -76,7 +77,7 @@ export function GridMode(props){
76 77
                                 </div>
77 78
                             </Col>
78 79
                         )
79
-                    }) : <h1>no hay data</h1>
80
+                }) : <div>no hay ni mierda</div>
80 81
             }
81 82
         </React.Fragment>
82 83
     )

+ 2 - 2
src/Components/Puestos/ListMode.jsx

@@ -3,7 +3,7 @@ import {  Col, Button, Table } from 'react-bootstrap'
3 3
 export function ListMode(props) {
4 4
     
5 5
     const opciones = { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' };
6
-    let { setEdit, setDelete, setShow, setPuesto, data } = props;
6
+    let { setEdit, setDelete, setShow, setPuesto, data, index } = props;
7 7
 
8 8
     return(
9 9
         <Col md="12">
@@ -21,7 +21,7 @@ export function ListMode(props) {
21 21
 
22 22
                         {
23 23
                             data.length ? 
24
-                                data.slice( 0,23 ).map( (plaza) => {
24
+                                data[index].map( (plaza) => {
25 25
                                     return (
26 26
                                         <tr key={plaza.id}>
27 27
                                             <td className="text-center">{ plaza.nombre }</td>

+ 49 - 10
src/Pages/Puestos.jsx

@@ -2,7 +2,13 @@ import React, { useState, useEffect }  from 'react';
2 2
 import { Row, Col } from 'react-bootstrap'
3 3
 import toast, { Toaster } from 'react-hot-toast';
4 4
 
5
-import { ToggleButton, ToggleButtonGroup, Box, Paper } from '@mui/material';
5
+import { 
6
+    ToggleButton, 
7
+    ToggleButtonGroup, 
8
+    Box,
9
+    Paper,
10
+    Pagination,
11
+} from '@mui/material';
6 12
 
7 13
 import { ViewList as ViewListIcon, ViewModule as ViewModuleIcon, } from '@mui/icons-material';
8 14
 
@@ -24,11 +30,29 @@ import { Add as AddIcon, } from '@mui/icons-material/'
24 30
 const Success =  () => toast.success('Plaza Agregada!!')
25 31
 const Error =  () => toast.error('Ups creo que ocurrio un error, intentalo nuevamente')
26 32
 
33
+function Divide(arregloOriginal){
34
+    const LONGITUD_PEDAZOS = 9;
35
+    let arregloDeArreglos = [];
36
+    for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
37
+        let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
38
+        arregloDeArreglos.push(pedazo);
39
+    }
40
+    return arregloDeArreglos
41
+}
42
+
27 43
 export function Puestos() {
28 44
 
29 45
     const auth = useAuth();
30
-    const [data, setData] = useState({});
46
+    const [data, setData] = useState([]);
47
+    const [page, setPage] = useState(1);
31 48
     const token = auth.getToken();
49
+    
50
+    const changePage = ( _ , value) => {
51
+        let page_numer = value;
52
+        // let divided =  Divide(data)
53
+        setPage(page_numer);
54
+        // setData(divided)
55
+    };
32 56
 
33 57
     useEffect(() => {
34 58
 
@@ -46,7 +70,7 @@ export function Puestos() {
46 70
                     data: e
47 71
                 };
48 72
             })
49
-            setData(entries)
73
+            setData(Divide(entries))
50 74
         })
51 75
         .catch((error) => {
52 76
             console.log('error fetching data  ', error );
@@ -54,12 +78,10 @@ export function Puestos() {
54 78
 
55 79
     },[token])
56 80
 
57
-    const [alignment, setAlignment] = React.useState('list');
81
+    // const [alignment, setAlignment] = React.useState('list');
82
+    const [alignment, setAlignment] = React.useState('grid');
58 83
 
59
-    const handleChange = (_event, newAlignment) => {
60
-        console.log("new alignment :: ", newAlignment );
61
-        setAlignment(newAlignment)
62
-    } ;
84
+    const handleChange = (_event, newAlignment) => setAlignment(newAlignment)
63 85
 
64 86
     const children = [
65 87
         <ToggleButton value="list" key="list">
@@ -78,7 +100,7 @@ export function Puestos() {
78 100
 
79 101
     let [puesto, setPuesto] = React.useState(false);
80 102
 
81
-    let [manual, setManual] = React.useState(true);
103
+    let [manual, setManual] = React.useState(false);
82 104
     let [expres, setExpress] = React.useState(false);
83 105
 
84 106
     let [edit, setEdit] = React.useState(false);
@@ -89,7 +111,7 @@ export function Puestos() {
89 111
         <div className="content-section">
90 112
             <div className="main">
91 113
                 <Box sx={{ width: '100%' }}>
92
-                    <Paper sx={{ width: '100%', mb: 2, padding : 2, height: '95vh' }}>
114
+                    <Paper sx={{ width: '100%', mb: 2, padding : 2, height: '100%', minHeight:'95vh' }}>
93 115
 
94 116
                         <Row style={{paddingBottom : 15}}>
95 117
                             <Col md="2" sm="2" xs="2">
@@ -118,6 +140,7 @@ export function Puestos() {
118 140
                             <Row>
119 141
                                 <GridMode
120 142
                                     data={data}
143
+                                    index={page - 1}
121 144
                                     setPuesto={setPuesto}
122 145
                                     setEdit={setEdit}
123 146
                                     setDelete={setDelete}
@@ -129,6 +152,7 @@ export function Puestos() {
129 152
                             <Row>
130 153
                                 <ListMode 
131 154
                                     data={data}
155
+                                    index={page -1}
132 156
                                     setPuesto={setPuesto}
133 157
                                     setEdit={setEdit}
134 158
                                     setDelete={setDelete}
@@ -137,6 +161,21 @@ export function Puestos() {
137 161
                             </Row>
138 162
                         </div>
139 163
 
164
+                            <Pagination 
165
+                                sx={{
166
+                                    "& ul" :{
167
+                                        "padding-top" : "20px",
168
+                                        "justify-content": "center"
169
+                                    }
170
+                                }}
171
+                                siblingCount={2} 
172
+                                boundaryCount={2}
173
+                                shape='rounded' 
174
+                                count={data.length} 
175
+                                page={page} 
176
+                                onChange={changePage} 
177
+                            />
178
+
140 179
                     </Paper>
141 180
                 </Box>
142 181