Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from cleph01/jason-aviles
update
- Loading branch information
Showing
7 changed files
with
224 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let content = [ | ||
{ | ||
name: "Pha Ga", | ||
description: "Pha Ga description", | ||
}, | ||
{ | ||
name: "Tonkutsu 2.0", | ||
description: "Tonkutsu description", | ||
}, | ||
{ | ||
name: "Spicey Miso", | ||
description: "Spicey Miso description", | ||
}, | ||
] | ||
|
||
|
||
console.log(content.map(info=> info.name).indexOf("Spicey Miso")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,84 @@ | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import React, { useState, useEffect } from "react"; | ||
import styled from "styled-components"; | ||
|
||
const Container = styled.div` | ||
margin: 0px 20px; | ||
border-radius: 5px; | ||
margin: 0px 20px; | ||
border-radius: 5px; | ||
`; | ||
|
||
const Header = styled.div` | ||
padding: 20px; | ||
background-color:#445a82; | ||
color:#fff; | ||
padding: 20px; | ||
background-color: #445a82; | ||
color: #fff; | ||
`; | ||
|
||
const Cart = styled.div` | ||
padding:20px; | ||
text-align:center; | ||
background-color:#fff; | ||
padding: 20px; | ||
text-align: center; | ||
background-color: #fff; | ||
`; | ||
|
||
const ShoppingCart = (props) => { | ||
const maxChar = (str) => { | ||
let array = str.map((info) => info); | ||
let charMap = {}; | ||
|
||
console.log(array, "kknnk"); | ||
for (let char of str) { | ||
if (charMap[char]) { | ||
charMap[char]++; | ||
} else { | ||
charMap[char] = 1; | ||
} | ||
} | ||
let ster = []; | ||
for (const [key, value] of Object.entries(charMap)) { | ||
ster.push({ item: key, quantity: value }); | ||
} | ||
return ster; | ||
}; | ||
|
||
const cartData = props.cart.map((item) => item.name); | ||
|
||
const [filterCart, setFilterCart] = useState([]); | ||
|
||
const ShoppingCart = () => { | ||
useEffect(() => setFilterCart(maxChar(cartData)), []); | ||
const cartArray = maxChar(cartData); | ||
|
||
const [ items, setItems ] = useState([]); | ||
console.log(cartArray, "hhhee"); | ||
const getCartTotal = () => { | ||
return props.cart | ||
.reduce((acc, value) => { | ||
return acc + value.price; | ||
}, 0) | ||
.toFixed(2); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<Header> | ||
<div>Pick up</div> | ||
<div>Ready for pick up: 20 - 40m</div> | ||
</Header> | ||
<Cart> | ||
{items.length == 0 ? 'Your bag is empty' : 'Your bag is NOT empty'} | ||
</Cart> | ||
</Container> | ||
); | ||
const [items, setItems] = useState([]); | ||
console.log(cartArray.map((i) => i.quantity), "shoppingcart"); | ||
return ( | ||
<Container> | ||
<Header> | ||
<div>Pick up</div> | ||
<div>Ready for pick up: 20 - 40m</div> | ||
</Header> | ||
<Cart> | ||
{props.cart.length == 0 ? ( | ||
<h1>Your bag is empty</h1> | ||
) : ( | ||
<div> | ||
{cartArray.map((i, index) => ( | ||
<div key={index}> | ||
<h1>item: {i.item}</h1> <h2>quantity: {i.quantity}</h2>{" "} | ||
</div> | ||
))} | ||
<br /> | ||
Total: {getCartTotal()} | ||
</div> | ||
)} | ||
</Cart> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ShoppingCart; | ||
export default ShoppingCart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.