Repository navigation
Expand file tree
/
Copy pathForm.js
More file actions
111 lines (100 loc) · 2.83 KB
/
Copy pathForm.js
File metadata and controls
111 lines (100 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React from "react";
import { applyMiddleware, createStore } from "redux";
import logger from "redux-logger";
import thunk from "redux-thunk";
import axios from "axios";
const estadoInicial = {
trayendo: false,
traido: false,
usuarios: [],
error: null
};
const tagNumeral = /#/g;
const saltoLinea = /\n/g;
const arroba = /@/g;
const entidadUrlNumeral = "%23";
const entidadUrlSaltoLinea = "%5Cn";
const entidadUrlArroba = "%40";
export default class Form extends React.Component {
state = {
codigoTags: "",
codigoHtmlProcesado: ""
};
cambiarEstado = e => {
this.setState({
[e.target.name]: e.target.value
});
};
procesarUrl = e => {
var url = "http://localhost:8080/api/procesartag?datosTag=";
var arrayCodigoTags = this.state.codigoTags.split(" ");
for(var indice = 0; indice < arrayCodigoTags.length; indice++) {
url += arrayCodigoTags[indice] + "%20";
}
url = url.replace(tagNumeral, entidadUrlNumeral);
url = url.replace(saltoLinea, entidadUrlSaltoLinea);
url = url.replace(arroba, entidadUrlArroba);
return url;
};
enviarDatos = url => {
axios.get(url)
.then((respuesta) => {
//dispatch({type: "RECEIVE_USERS", payload: response.data })
console.log("Al recibir los datos.");
console.log(respuesta.data);
this.state.codigoHtmlProcesado = respuesta.data;
this.setState({
["codigoHtmlProcesado"]: respuesta.data
});
})
.catch((err) => {
// dispatch({type: "FETCH_USERS_ERROR", payload: err })
console.log('An error has ocurred.');
})
};
enviar = e => {
e.preventDefault();
console.log(this.state);
console.log(this.state.tagsCode);
var url = this.procesarUrl();
console.log(url);
url = url.replace(tagNumeral, entidadUrlNumeral);
url = url.replace(saltoLinea, entidadUrlSaltoLinea);
console.log(url);
this.enviarDatos(url);
};
render() {
return (
<div>
<h2>Tag Processor App</h2>
<br/>
<div>
<h3>Introduce el codigo de tags deseado</h3>
<form>
<textarea
name="codigoTags" rows="4" cols="50"
value={this.state.codigoTags}
onChange={e => this.cambiarEstado(e)}>
Hola!!!!
</textarea>
<br/>
<br/>
<button onClick={e => this.enviar(e)}>Submit</button>
</form>
</div>
<br/>
<div>
<h3>Resultado del codigo ejecutado en HTML</h3>
<form>
<textarea
name="codigoHtmlProcesado" rows="4" cols="50"
value={this.state.codigoHtmlProcesado}
onChange={e => this.cambiarEstado(e)}>
Html code
</textarea>
</form>
</div>
</div>
);
}
}