-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
225 lines (219 loc) · 8.29 KB
/
index.html
File metadata and controls
225 lines (219 loc) · 8.29 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Menú Restaurante</title>
<link rel="stylesheet" href="./src/index.css">
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div class="contain">
<header>
<div>
<h1>Food For Home</h1>
<img class="logo" src="./img/logo.png">
</div>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p>
</header>
<main>
<div id="slider"></div>
<div id="list"></div>
</main>
<footer>
<button onclick="location.href='./index2.html'" class="botonCarrito">
<img src="./img/bolsa.svg " class="imgboton"></img>
</button>
<div class="price"></div>
</footer>
</div>
<script src="./src/listaplatos.js"></script>
<script src="./src/categorias.js"></script>
<script type="text/babel">
const Category = (props) => {
return (
<div id={props.id} className="cardSlider">
<img src={props.img}/>
<p>{props.name}</p>
</div>
)}
const CategoryList = () =>{
return (
<div>
{listaCategorias.map((category, i) => {
return <Category key={i} id={category.nombreCategoria} img={category.imgCategoria} name={category.nombreCategoria}/>
})}
</div>
);
}
ReactDOM.render( CategoryList(), document.getElementById("slider"));
</script>
<script type="text/babel">
class Total extends React.Component {
constructor(props){
super(props)
this.state = {
subtotal: 0.00,
tasas: 0.10
}
}
render(){
Object.keys(localStorage).map((plate, id)=> {
return (
this.state.subtotal += listaPlatos[plate].precioPlato * localStorage.getItem(plate)
)
})
return (
<div className="footer">
<h2>TOTAL: </h2>
<p>{this.state.subtotal + (this.state.subtotal * this.state.tasas)}€</p>
</div>
)
}
}
ReactDOM.render( <Total />, document.querySelector(".price"));
</script>
<script type="text/babel">
class TotalSuma extends React.Component {
constructor(props){
super(props)
this.state = {
subtotal: 0,
tasas: 0.10
}
}
render(){
let array = []
Object.keys(localStorage).map((plate , element) =>{
return (
element = (listaPlatos[plate].precioPlato * localStorage.getItem(plate)),
this.state.subtotal = element,
array.push(element)
)
})
let total = 0
for (let i =0; i < array.length; i++){
total += array[i]
}
return (
<div className="footer">
<h2>TOTAL: </h2>
<p> {total + (total * this.state.tasas)}€</p>
</div>
)
}
}
class TotalResta extends React.Component {
constructor(props){
super(props)
this.state = {
subtotal: 0,
tasas: 0.10
}
}
render(){
let array = []
Object.keys(localStorage).map((plate , element) =>{
return (
element = (listaPlatos[plate].precioPlato * localStorage.getItem(plate)),
this.state.subtotal = element,
array.push(element)
)
})
let total = 0
for (let i =0; i < array.length; i++){
total += array[i]
}
return (
<div className="footer">
<h2>TOTAL: </h2>
<p>{Object.keys(localStorage).length == 0 ? 0 : total + (total * this.state.tasas)}€</p>
</div>
)
}
}
</script>
<script type="text/babel">
class Contador extends React.Component {
constructor(props){
super(props)
this.state = {
counter: JSON.parse(localStorage.getItem(this.props.index)) || this.props.counter
}
}
resta = () => {
ReactDOM.render( <TotalResta />, document.querySelector(".price"));
localStorage.setItem(this.props.index, this.state.counter - 1)
if (localStorage.getItem(this.props.index) >= 0){
this.setState((state) => {
return {counter: this.state.counter - 1}
})}
if (this.state.counter <= 1 ){
localStorage.removeItem(this.props.index)
}
}
suma = () => {
ReactDOM.render( <TotalSuma />, document.querySelector(".price"));
localStorage.setItem(this.props.index, this.state.counter + 1)
this.setState((state) => {
return {counter: state.counter + 1}
})
}
render(){
return (
<div className="contador" data-numero={this.props.index}>
<button onClick={this.resta} className="resta">-</button>
<p className="quantity">{localStorage.getItem(this.props.index) ||this.state.counter}</p>
<button onClick={this.suma} className="suma">+</button>
</div>
)
}
}
</script>
<script type="text/babel">
const Plate = (props) => {
return (
<div className="elemento">
<img src={props.img}/>
<div className="texto ">
<p>{props.precioPlato}€</p>
<h5>{props.nombrePlato}</h5>
<h6>{props.descripcionPlato}</h6>
</div>
<Contador index={props.id} counter={props.number}/>
</div>
)
}
class PlateList extends React.Component {
render(){
return (<div>{listaPlatos.map((plate, i) =>{
return <Plate key={i} img={plate.imgPLato} precioPlato={plate.precioPlato} nombrePlato={plate.nombrePlato} descripcionPlato={plate.descripcionPlato} id={listaPlatos[i].id} number={listaPlatos[i].cantidad}/>
})}</div>)
}
}
ReactDOM.render( <PlateList />, document.getElementById("list"));
const categorys = document.querySelectorAll(".cardSlider")
function NewList(x) {
let name = x.path[1].id
if (name == ""){
name = x.path[0].id
}
class NewList extends React.Component {
render(){
return (<div>{listaPlatos.map((plate, i) =>{
for (let j = 0; j < plate.nombreCategoria.length; j ++){
if (plate.nombreCategoria[j] == name){
return <Plate key={i} img={plate.imgPLato} precioPlato={plate.precioPlato} nombrePlato={plate.nombrePlato} descripcionPlato={plate.descripcionPlato} id={listaPlatos[i].id} number={listaPlatos[i].cantidad}/>
}
}
})}</div>)
}
}
ReactDOM.render( <NewList />, document.getElementById("list"));
}
categorys.forEach((category) => {category.addEventListener("click", NewList)})
</script>
</body>
</html>