diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..d9d5b38562 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +package-lock.json +package.json +node_modules \ No newline at end of file diff --git a/labecommerce-frontend/.gitignore b/labecommerce-frontend/.gitignore new file mode 100644 index 0000000000..3ded075ae4 --- /dev/null +++ b/labecommerce-frontend/.gitignore @@ -0,0 +1,25 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +package-lock.json +package.json diff --git a/labecommerce-frontend/README.md b/labecommerce-frontend/README.md new file mode 100644 index 0000000000..58beeaccd8 --- /dev/null +++ b/labecommerce-frontend/README.md @@ -0,0 +1,70 @@ +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can't go back!** + +If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. + +You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `npm run build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/labecommerce-frontend/public/index.html b/labecommerce-frontend/public/index.html new file mode 100644 index 0000000000..aa069f27cb --- /dev/null +++ b/labecommerce-frontend/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/labecommerce-frontend/public/toys/abajur.jpg b/labecommerce-frontend/public/toys/abajur.jpg new file mode 100644 index 0000000000..f0a9552862 Binary files /dev/null and b/labecommerce-frontend/public/toys/abajur.jpg differ diff --git a/labecommerce-frontend/public/toys/foguete.jpg b/labecommerce-frontend/public/toys/foguete.jpg new file mode 100644 index 0000000000..c55596215f Binary files /dev/null and b/labecommerce-frontend/public/toys/foguete.jpg differ diff --git a/labecommerce-frontend/public/toys/jogo.jpg b/labecommerce-frontend/public/toys/jogo.jpg new file mode 100644 index 0000000000..4f8258d2e5 Binary files /dev/null and b/labecommerce-frontend/public/toys/jogo.jpg differ diff --git a/labecommerce-frontend/public/toys/kitnave.jpg b/labecommerce-frontend/public/toys/kitnave.jpg new file mode 100644 index 0000000000..5d957c94cf Binary files /dev/null and b/labecommerce-frontend/public/toys/kitnave.jpg differ diff --git a/labecommerce-frontend/public/toys/sistemasolar.jpg b/labecommerce-frontend/public/toys/sistemasolar.jpg new file mode 100644 index 0000000000..9824a9350e Binary files /dev/null and b/labecommerce-frontend/public/toys/sistemasolar.jpg differ diff --git a/labecommerce-frontend/public/toys/telescopio.jpg b/labecommerce-frontend/public/toys/telescopio.jpg new file mode 100644 index 0000000000..fb675116da Binary files /dev/null and b/labecommerce-frontend/public/toys/telescopio.jpg differ diff --git a/labecommerce-frontend/src/App.js b/labecommerce-frontend/src/App.js new file mode 100644 index 0000000000..c9e7ca1537 --- /dev/null +++ b/labecommerce-frontend/src/App.js @@ -0,0 +1,57 @@ +import Home from "./components/home/Home" +import Filter from "./components/filter/Filter" +import Cart from "./components/cart/Cart" +import { useEffect, useState } from "react" +import styled from "styled-components" + +const MainContainer = styled.div` + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + background-color: black; + color: white; +` + +function App() { + const [cart, setCart] = useState([]) + const [order, setOrder] = useState("crescente") + const [valueMax, setValueMax] = useState(0) + const [valueMin, setValueMin] = useState(0) + const [searchName, setSearchName] = useState("") + + useEffect(() => { + if (cart.length > 0) { + localStorage.setItem("cart", JSON.stringify(cart)) + } + }, [cart]) + useEffect(() => { + const cartLocalStorage = localStorage.getItem("cart") + if (cartLocalStorage) { + setCart(JSON.parse(cartLocalStorage)) + } + }, []) + + return ( + + + + + + ) +} + +export default App \ No newline at end of file diff --git a/labecommerce-frontend/src/components/cart/Cart.js b/labecommerce-frontend/src/components/cart/Cart.js new file mode 100644 index 0000000000..f2be797d82 --- /dev/null +++ b/labecommerce-frontend/src/components/cart/Cart.js @@ -0,0 +1,31 @@ +import { CartContainer } from "./styles" + +const Cart = ({ cart, setCart }) => { + const removeProduct = (product) => { + const newCart = cart.map((item) => + item.name === product.name ? { ...item, quantity: item.quantity - 1 } : item + ).filter((item) => item.quantity > 0) + setCart(newCart) + } + const total = cart.reduce((acumulator, product) => { + return acumulator + product.valor * product.quantity + }, 0) + + return ( + +

Carrinho

+ {cart.map((item) => { + return ( +
+

Nome: {item.nome}

+

Quantidade: {item.quantity}

+ +
+ ) + })} +

Total: {total}

+
+ ) +} + +export default Cart \ No newline at end of file diff --git a/labecommerce-frontend/src/components/cart/styles.js b/labecommerce-frontend/src/components/cart/styles.js new file mode 100644 index 0000000000..c8c18825ef --- /dev/null +++ b/labecommerce-frontend/src/components/cart/styles.js @@ -0,0 +1,8 @@ +import styled from "styled-components" + +export const CartContainer = styled.div` + display: flex; + justify-content: center; + flex-direction: column; + align-self: flex-start; +` \ No newline at end of file diff --git a/labecommerce-frontend/src/components/filter/Filter.js b/labecommerce-frontend/src/components/filter/Filter.js new file mode 100644 index 0000000000..a4d224843b --- /dev/null +++ b/labecommerce-frontend/src/components/filter/Filter.js @@ -0,0 +1,33 @@ +import { InputContainer } from "./styles" + +const Filter = ({ order, setOrder, setValueMin, setValueMax, setSearchName }) => { + return ( + +
+

Filtro

+ + + + + setValueMin(e.target.value)} /> + setValueMax(e.target.value)} /> + setSearchName(e.target.value)} /> + + +
+ ) +} + +export default Filter \ No newline at end of file diff --git a/labecommerce-frontend/src/components/filter/styles.js b/labecommerce-frontend/src/components/filter/styles.js new file mode 100644 index 0000000000..0bac0208c3 --- /dev/null +++ b/labecommerce-frontend/src/components/filter/styles.js @@ -0,0 +1,13 @@ +import styled from "styled-components" + +export const InputContainer = styled.div` + display: flex; + flex-direction: column; + margin-top: 12px; + height: 120px; + justify-content: space-evenly; + padding: 12px 12px; + background-color: black; + color: black; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +` \ No newline at end of file diff --git a/labecommerce-frontend/src/components/home/Home.js b/labecommerce-frontend/src/components/home/Home.js new file mode 100644 index 0000000000..66d1e8ebd9 --- /dev/null +++ b/labecommerce-frontend/src/components/home/Home.js @@ -0,0 +1,62 @@ +import toys from "../../toys.json" +import { Image, ProductsContainer } from "./styles" + +const Home = ({ cart, setCart, order, valueMin, valueMax, searchName }) => { + const addProduct = (product) => { + const productCard = cart.find( + (item) => item.name === product.name + ) + + if (productCard) { + const newCart = cart.map(item => + productCard.name === item.name ? { ...item, quantity: item.quantity + 1 } : item + ) + setCart(newCart) + } else { + setCart([...cart, { ...product, quantity: 1 }]); + } + } + + return ( + +

Produtos

+ {toys + .sort((prod1, prod2) => { + return order === "crescente" + ? + prod1.name.localeCompare(prod2.name) + : + prod2.name.localeCompare(prod1.name) + }) + .filter((product) => { + return valueMin + ? + product.value >= valueMin + : + product + }) + .filter((product) => { + return valueMax + ? + product.value <= valueMax + : + product + }) + .filter((product) => { + return product.name.toLowerCase().includes(searchName.toLowerCase()) + }) + .map((product) => { + return ( + + {product.name} +

Nome: {product.name}

+

Preço: {product.value}

+ +
+ ) + })} +
+ ) +}; + +export default Home \ No newline at end of file diff --git a/labecommerce-frontend/src/components/home/styles.js b/labecommerce-frontend/src/components/home/styles.js new file mode 100644 index 0000000000..34b148818a --- /dev/null +++ b/labecommerce-frontend/src/components/home/styles.js @@ -0,0 +1,16 @@ +import styled from 'styled-components' + +export const ProductsContainer = styled.div` + padding: 15px 30px; + min-height: 20vh; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + flex: 2 +` + +export const Image = styled.img` + width: 300px; + height: 300px; +` \ No newline at end of file diff --git a/labecommerce-frontend/src/index.css b/labecommerce-frontend/src/index.css new file mode 100644 index 0000000000..ec2585e8c0 --- /dev/null +++ b/labecommerce-frontend/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/labecommerce-frontend/src/index.js b/labecommerce-frontend/src/index.js new file mode 100644 index 0000000000..42002dce16 --- /dev/null +++ b/labecommerce-frontend/src/index.js @@ -0,0 +1,13 @@ +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +const root = ReactDOM.createRoot(document.getElementById('root')); +root.render( + + + +); +reportWebVitals(); \ No newline at end of file diff --git a/labecommerce-frontend/src/reportWebVitals.js b/labecommerce-frontend/src/reportWebVitals.js new file mode 100644 index 0000000000..5253d3ad9e --- /dev/null +++ b/labecommerce-frontend/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/labecommerce-frontend/src/setupTests.js b/labecommerce-frontend/src/setupTests.js new file mode 100644 index 0000000000..8f2609b7b3 --- /dev/null +++ b/labecommerce-frontend/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/labecommerce-frontend/src/toys.json b/labecommerce-frontend/src/toys.json new file mode 100644 index 0000000000..83f8ea153f --- /dev/null +++ b/labecommerce-frontend/src/toys.json @@ -0,0 +1,38 @@ +[ + { + "id": 1, + "name": "Iluminador Astronauta", + "value": 350, + "image": "../toys/abajur.jpg" + }, + { + "id": 2, + "name": "Foguete", + "value": 400, + "image": "../toys/foguete.jpg" + }, + { + "id": 3, + "name": "Jogo Astronauta", + "value": 190, + "image": "../toys/jogo.jpg" + }, + { + "id": 4, + "name": "Kit Nave Espacial", + "value": 250, + "image": "../toys/kitnave.jpg" + }, + { + "id": 5, + "name": "Planetas do Sistema Solar", + "value": 220, + "image": "../toys/sistemasolar.jpg" + }, + { + "id": 6, + "name": "Telescópio", + "value": 500, + "image": "../toys/telescopio.jpg" + } +] \ No newline at end of file