Browse Source

home pagination fixes

amenpunk 3 years ago
parent
commit
0a2757c00e
6 changed files with 129 additions and 26 deletions
  1. 1 0
      .gitignore
  2. 1 1
      package.json
  3. 2 2
      src/Components/Home/Candidato.jsx
  4. 56 20
      src/Components/Home/Candidatos.js
  5. 9 3
      src/Pages/Login.jsx
  6. 60 0
      src/Utils/HTTP.js

+ 1 - 0
.gitignore

@@ -21,4 +21,5 @@
21 21
 npm-debug.log*
22 22
 yarn-debug.log*
23 23
 yarn-error.log*
24
+package-lock.json
24 25
 

+ 1 - 1
package.json

@@ -24,7 +24,7 @@
24 24
     "react-hot-toast": "^2.2.0",
25 25
     "react-router": "6.2.1",
26 26
     "react-router-dom": "6.2.1",
27
-    "react-scripts": "4.0.3",
27
+    "react-scripts": "^5.0.0",
28 28
     "web-vitals": "^1.0.1",
29 29
     "yup": "^0.32.11"
30 30
   },

+ 2 - 2
src/Components/Home/Candidato.jsx

@@ -1,13 +1,13 @@
1 1
 import React from 'react'
2 2
 
3 3
 export function Candidato (props) {
4
-    let { password,puesto,DPI, index , aplicacion,pendientes } = props.user
4
+    let { password,puesto,DPI, aplicacion,pendientes } = props.user
5 5
 
6 6
     return(
7 7
         <div className="data_candidato">
8 8
             <div className="row">
9 9
                 <div className="col20">
10
-                    <p>{index + " - " + password }</p>
10
+                    <p>{ password }</p>
11 11
                 </div>
12 12
                 <div className="col20">
13 13
                     <p>{ puesto }</p>

+ 56 - 20
src/Components/Home/Candidatos.js

@@ -1,4 +1,4 @@
1
-import React, { useState } from 'react';
1
+import React, { useState, useEffect } from 'react';
2 2
 
3 3
 import UpdateIcon from '@mui/icons-material/Update';
4 4
 import Typography from '@mui/material/Typography';
@@ -7,30 +7,65 @@ import Stack from '@mui/material/Stack';
7 7
 import { Row, Col } from 'react-bootstrap';
8 8
 
9 9
 import { Candidato } from './Candidato'
10
+const USER_LENGTH = 14
10 11
 
11
-export default function Candidatos () {
12 12
 
13
-    let list =  [{
14
-        password :'repartidor',
15
-        puesto : "Piloto Repartidor",
16
-        DPI : 1583266600501,
17
-        aplicacion : "27/12/2018 12:02 PM",
18
-        pendientes : "No"
19
-    }]
20
-
21
-    for( let _ of new Array(8)  ){
22
-        if(_) break
23
-        list.push( list[0] )
13
+function Divide(arregloOriginal){
14
+    const LONGITUD_PEDAZOS = 5;
15
+	let arregloDeArreglos = [];
16
+    for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
17
+        let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
18
+        arregloDeArreglos.push(pedazo);
24 19
     }
20
+    console.log(arregloDeArreglos)
21
+    return arregloDeArreglos
22
+}
23
+
24
+export default function Candidatos () {
25 25
 
26 26
     const [page, setPage] = useState(1);
27
-    // const [users, setUser] = useState(list);
28
-    // const [curret, setCurrent] = useState([]);
27
+    const [users, setUser] = useState([]);
29 28
 
30
-    const changePage = ( _ , value) => { if(_)
31
-        setPage(value);
29
+    const changePage = ( _ , value) => {
30
+
31
+        let page_numer = value;
32
+
33
+        Divide(users)
34
+        setPage(page_numer);
32 35
     };
33 36
 
37
+    useEffect(() => {
38
+
39
+        let list =  [{
40
+            password :'repartidor',
41
+            puesto : "Piloto Repartidor",
42
+            DPI : 0,
43
+            // aplicacion : "27/12/2018 12:02 PM",
44
+            aplicacion : new Date().toUTCString(),
45
+            pendientes : "No"
46
+        }]
47
+
48
+        let a = 1;
49
+        for( let _ of new Array(USER_LENGTH)  ){
50
+            if(_) break
51
+
52
+            let temp = {
53
+                ...list[0],
54
+                DPI : a * 1000
55
+            }
56
+
57
+            a=a+1;
58
+            list.push(temp)
59
+        }
60
+
61
+        let divided = Divide(list);
62
+        console.log('DIVDED 0 >> ',JSON.stringify( divided[0] ))
63
+
64
+        setUser(divided)
65
+
66
+    }, [])
67
+
68
+
34 69
 
35 70
     return (
36 71
         <div className="body_historial">
@@ -50,8 +85,9 @@ export default function Candidatos () {
50 85
                     </Row>
51 86
                 </div>
52 87
                 {
53
-                    list ?
54
-                    list.map( (user, index) => (<Candidato key={user.DPI + index} user={{ ...user, index }}/>)) 
88
+                    users.length ?
89
+                    users[page - 1]
90
+                    .map( user => (<Candidato key={user.DPI} user={user}/>)) 
55 91
                     : undefined
56 92
                 }
57 93
                 <Row style={{ padding : 5 }}>
@@ -61,7 +97,7 @@ export default function Candidatos () {
61 97
                             <Pagination 
62 98
                                 siblingCount={5} 
63 99
                                 shape='rounded' 
64
-                                count={list.length} 
100
+                                count={users.length} 
65 101
                                 page={page} 
66 102
                                 onChange={changePage} />
67 103
                         </Stack>

+ 9 - 3
src/Pages/Login.jsx

@@ -1,5 +1,6 @@
1 1
 import * as React from 'react';
2
-import toast, { Toaster } from 'react-hot-toast';
2
+// import toast, { Toaster } from 'react-hot-toast';
3
+import { Toaster } from 'react-hot-toast';
3 4
 
4 5
 import { 
5 6
     Paper, Box, Grid, Checkbox, FormControlLabel, Typography,
@@ -17,6 +18,8 @@ import useAuth from '../Auth/useAuth';
17 18
 import { useFormik } from 'formik';
18 19
 import * as Yup from 'yup';
19 20
 
21
+// import { HTTP } from '../Utils/HTTP.js'
22
+
20 23
 const LoginSchema = Yup.object().shape({
21 24
     email : Yup
22 25
     .string()
@@ -43,7 +46,10 @@ export function Login() {
43 46
         },
44 47
         validationSchema: LoginSchema,
45 48
         onSubmit: (values) => {
46
-            toast.success('Bienvenido!!')
49
+            // let { email, password } = values
50
+            // let request = new HTTP('/user?' + `user=${email}&password=${password}`)
51
+            // request.get()
52
+            // toast.success('Bienvenido!!')
47 53
             // toast.error("This didn't work.")
48 54
             // return navigate('/dashboard/home')
49 55
             auth.login(values)
@@ -90,7 +96,7 @@ export function Login() {
90 96
                             <PersonIcon />
91 97
                         </Avatar>
92 98
                         <Typography component="h1" variant="h5">
93
-                            Ingresar
99
+                            Ingresar 
94 100
                         </Typography>
95 101
 
96 102
                         <Box component="form" noValidate onSubmit={formik.handleSubmit} sx={{ mt: 1 }}>

+ 60 - 0
src/Utils/HTTP.js

@@ -0,0 +1,60 @@
1
+export class HTTP {
2
+
3
+    constructor(url){
4
+        this.base_url = 'http://204.48.25.93:8081'; 
5
+        this.url =  this.base_url + url
6
+    }
7
+
8
+    async post(body){
9
+        try{ 
10
+
11
+            let request = fetch(this.url , {
12
+                method: 'POST', 
13
+                mode: 'cors',
14
+                cache: 'no-cache',
15
+                headers: {
16
+                    "Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
17
+                    "Connection": "keep-alive",
18
+                    "Content-Type": "application/json",
19
+                    "Date": new Date().toUTCString(),
20
+                    "Expires": 0,
21
+                    "Keep-Alive": "timeout=60",
22
+                    "Pragma": "no-cache",
23
+                    "Transfer-Encoding": "chunked",
24
+                    "Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
25
+                    "X-Content-Type-Options": "nosniff",
26
+                    "X-Frame-Options": "DENY",
27
+                    "X-XSS-Protection": 1
28
+                },
29
+                // body: body
30
+            });
31
+
32
+            // let response = await request.json();
33
+            console.log(await request)
34
+
35
+        }catch(error)    {
36
+            console.log(error)
37
+            return {  status : 0, message  :  error.message }
38
+        }
39
+    }
40
+
41
+    async get() {
42
+
43
+        // POST request using fetch with async/await
44
+        const requestOptions = {
45
+            method: 'POST',
46
+            headers : new Headers({
47
+                'Content-Type': 'application/json', 
48
+                'Access-Control-Allow-Origin': '*',
49
+            }),
50
+            // body: JSON.stringify({ title: 'React POST Request Example' })
51
+        };
52
+        const response = await fetch(this.url, requestOptions);
53
+        // const data = 
54
+        console.log(response)
55
+        // this.setState({ postId: data.id });
56
+    }
57
+
58
+
59
+}
60
+