React JS shopping cart add functions - reactjs

Hi guys and privet from Russia :)
I am trying to build a shopping cart but struggling to add certain functionalities by using React JS only (not redux or node)
This is my code so far:
App.js
import React from "react";
import Navbar from "./components/Navbar";
import Home from "./components/Home";
import "./App.css";
function App() {
return (
<div className="App">
<Navbar />
<Home />
</div>
);
}
export default App;
Home.js*components*
import React, { useState } from "react";
const Home = () => {
const [basketNumbers, setBasketNumbers] = useState(0);
const addToBasket = () => {
setBasketNumbers(setBasketNumbers + 1);
};
return (
<div className="container">
<div className="image">
<img
src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTVWhIi-Mq_A6psrTdfOuElSh7p8y5AzevI7cLWnSLAr0BkQlT0&usqp=CAU"
alt="A green Beautiful dress"
/>
<h3>Green Dress</h3>
<h3>15€</h3>
<a onClick={addToBasket} className="addToCart cart1" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAQDxANDw8QDw4QDhAOEA8QDw8PDw8QFhEWFhYRFRUYHSggGBolGxYVITEhJSkrLi4uFyAzODMtNygtLisBCgoKDg0OGxAQGC0lIB8tLSstLS0tLS0tLS0rLS0tLS0tLS0tLSstKy0tLS0rLS0tLS0tLS0tLS0tLS0rLS0tLf/AABEIARMAtwMBEQACEQEDEQH/xAAbAAACAgMBAAAAAAAAAAAAAAAAAQIFAwQGB//EAEMQAAIBAgQCCAMECAQFBQAAAAECAAMRBBIhMQVBBhMiUWFxgZEyobEjUnLBB0JigqKy0fAUJJLxFTNT4eIWY5Ozwv/EABoBAQEAAwEBAAAAAAAAAAAAAAABAgMEBQb/xAA1EQEAAgIABAMFBwQBBQAAAAAAAQIDEQQSITEFQVEiMmFxwRNCgZGx4fAzUqHRIxUkQ2Lx/9oADAMBAAIRAxEAPwDs7TS3HaBICAwIDtAdoDAgO0AtAdoFR0i49TwaC9mqsOxTva/ifD6yTOmURt59xLpPjiBV64orNZVQBBfuA3t5zG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5Gbi4/wDHC1XgNNXVlGVVAGQbEjmTvMotqNNVeNyVpNPXzSxtJlBYKSB3AmYy49RKt4Vwj4qjnPUa57Ouu5J8z/e85IibS6MmStO07XuAwRpZiAczEFiRbYWHlpynRWuocd7c87lcYTFssyapqt8Pj77yaYzDep1LyIzAwETIEYRa5ZVIrKI5IESkKxPTgaddJVUHHsPTeketAZUOcKwBBexVd/FpLTqst+G9q29nz6KvhCW05ATjq67SzU0NWu5vdKaFQOWY/wDab8UdWjLPaEqXAsO6IzUUuUUkgZbm2+lp0VtOu7ZXi81Y1F5Z6fBaK/BRQHvy3PudZeaUtxWW/S15Zv8AhJPKTbVzJDhJHKNpzJJwvvkSbNqnw1RvG2PMzf4VZEQOBU8oEDwteUJtNMABIxbNOlaGLLeYoJQQLi0BWgFoCtCkUl2MNemLHS+mwjY8+x3ERVurdgguSgB+EWsAGF9cy6jc3tpvzWtM93o1w0jrWfxSVQFsAyVCSFuG6t7G2htv3DW8kRPklrxSesxK74Fw3LTYupvUNyGBBt3943M30jUOXJfmttZ0cIiqEUaKABcljYd5OpmbHbItIDlKbGWQPJCkUgLqpQ+rgHVwh5ZEPLCArAAsjEdXARpwLZoETAcBwFARgYWwlInMadMtrqUUk/KELqEW+VFX8KhfpDKGMqJVRIhStCoiA4DtCiEBgAEILQFCCEAkQGALA//Z"
alt="A beautiful Hot Pink Dress"
/>
<h3>Pink Dress</h3>
<h3>350€</h3>
<a onClick={addToBasket} className="addToCart cart2" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="https://m.media-amazon.com/images/I/71dAgPUbwKL._SR500,500_.jpg"
alt="A beautiful Black Dress"
/>
<h3>Black Dress</h3>
<h3>400€</h3>
<a onClick={addToBasket} className="addToCart cart3" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="https://ae01.alicdn.com/kf/He938e0d8636a44c9a4440109bf998d67j/Off-Shoulder-Elegant-Backless-Long-Royal-Blue-Evening-Dresses-2019-Lace-Up-Party-Maxi-Dress-Formal.jpg_640x640q70.jpg"
alt="A Beautiful Blue Dress"
/>
<h3>Blue Dress</h3>
<h3>250€</h3>
<a onClick={addToBasket} className="addToCart cart 4" href="#">
Add To Cart
</a>
</div>
<div className="image">
<img
src="https://ae01.alicdn.com/kf/HTB1Lpp9XAPoK1RjSZKbq6x1IXXaf/Summer-Sexy-Spaghetti-Strap-Ruffle-Women-Dress-Backless-A-Line-Formal-Evening-Party-Dress-Short-Front.jpg_640x640q70.jpg"
alt="A beautiful Red Dress"
/>
<h3>Red Dress</h3>
<h3>150€</h3>
<a onClick={addToBasket} className="addToCart cart5" href="#">
Add To Cart
</a>
</div>
<h1>Current Number In Cart {basketNumbers}</h1>
</div>
);
};
export default Home;
Navbar.js *components*
import React from "react";
function Navbar() {
return (
<header>
<div className="overly" />
<nav>
<h2>Shop</h2>
<ul>
<li>
Home
</li>
<li classname="cart">
{" "}
<a href="#">
<ion-icon name="cart" />
Cart<span> 0 </span>
</a>
</li>
</ul>
</nav>
</header>
);
}
export default Navbar;
This is my CSS just in case:
li a {
padding: 5px;
background-color: white;
text-decoration: none;
}
.cart ion-icon {
vertical-align: bottom;
font-size: 20px;
padding-right: 5px;
}
.cart a {
background-color: royalblue;
color: white;
cursor: pointer;
text-decoration: none;
}
.container {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin-top: 50px;
padding-bottom: 100px;
}
.img {
margin-right: 20px;
margin-left: 20px;
position: relative;
overflow: hidden;
}
.addToCart {
position: absolute;
width: 100%;
background-color: darkgray;
transition: all 0.3s ease-in-out;
opacity: 0;
cursor: pointer;
text-align: center;
}
.image:hover .cart1,
.image:hover .cart2,
.image:hover .cart3,
.image:hover .cart4,
.image:hover .cart5 {
bottom: 50px;
opacity: 1;
padding: 10px;
text-decoration: none;
}
What I would like to add to this code:
Add to cart click will add the product to the cart and not just show it on the bottom part of the page
Add a total which changes whenever a new item is added to the cart
Add a free shipping for a car above 500 EUR, else having a message saying you're not entitled to a free shipping.
Thank you so much :)

well i can't actually do all what you want bcs... you shouldn't actually ask people here to add those features for you bcs i think they take so much lines, you should try to add them yourself and then if your code doesnt work, you just ask here, anyways i found a mistake in your code and i'm gonna correct it for ya:
Home.jscomponents
import React, { useState } from "react";
const Home = () => {
const [basketNumbers, setBasketNumbers] = useState(0);
const addToBasket = () => {
setBasketNumbers(oldBasketNum => oldBasketNum + 1); //this is the correct way to update the state on click, bcs u wrote setBasketNumbers +1 which won't work
};
return (//the rest of your code here)
Hope this was helpfull, thanks
**
Edit:
**
You also should add more components to save you some space in your render method like this:
Item component:
import React from "react";
const Item = (props) => {
return (
<div className="image">
<img src={props.img} alt={props.alt} />
<h3>props.name</h3>
<h3>props.price</h3>
<a onClick={props.addToBasket} className="addToCart cart1" href="#">
Add To Cart
</a>
</div>
);
};
export default Item;
Home.js component:
import React, { useState } from "react";
import Item from "./item.js";
const Home = () => {
const [basketNumbers, setBasketNumbers] = useState(0);
const addToBasket = () => {
setBasketNumbers((oldBasketNum) => oldBasketNum + 1); //this is the correct way to update the state on click, bcs u wrote setBasketNumbers +1 which won't work
};
return (
<div className="container">
<Item name="" price="" img="" alt="" /> //you fill this props as you want
the items to be
<Item name="" price="" img="" alt="" /> //you could also make this more
dynamic using arrays
</div>
);
};

Related

How can I do conditional rendering on a styled component?

I am using conditional rendering to make toggle function. But I think there is a problem with the method because I did conditional rendering on the styled component but it doesn't work. Can you tell me how to fix it? I'd appreciate it if you let me know thanks
my.jsx:
If I click on another image, the value of the profile becomes false, and if I click on the profile image, the value of the profile becomes true. And according to the value of the profile, I gave the value of the display by conditional rendering the tag whose className is IconWrap6True. But now, the display value of IconWrap6Trued keeps coming out as block, and 'none' is not applied. The cord is long, so I skipped the parts that I didn't need
import React, { useState } from 'react'
import styled from 'styled-components';
import defaultProfile from '../resources/images/img/defaultprofile.jpg'
const NavigationBarWrap1 = styled.div`
position: fixed;
flex-direction: column;
box-sizing: border-box;
display: flex;
flex-shrink: 0;
align-items: stretch;
.IconWrap6True {
${props => props.profile ? "block" : "none"};
box-sizing: border-box;
border-bottom-left-radius: 50%;
top: 50%;
border-top-right-radius: 50%;
left: 50%;
border: 2px solid rgb(38,38,38);
transform: translate(-50%,-50%);
}
`
function NavigationBar() {
//state
const[home, setHome] = useState(true);
const[profile,setProfile] = useState(true);
//true
const setTrueHome = () => {
setHome(true)
}
const setTrueProfile = () => {
setProfile(true)
}
//false
const setFalseHome = () => {
setHome(false)
}
const setFalseProfile = () => {
setProfile(false)
}
//handle
const forHome = (e) => {
setTrueHome();
setFalseProfile();
}
const forProfile = (e) => {
setFalseHome();
setTrueProfile();
}
return (
<NavigationBarWrap1>
<div className='IconWrap'>
<div className='IconWrap4'>
<div onClick={forHome} className='IconWrap5'>
<div>
<div className='IconWrap6'>
<div className='IconWrap7'>
{home===true?
<>
<img/>
</>:
<>
<img/>
</>}
</div>
</div>
</div>
</div>
</div>
</div>
<div className='IconWrap'>
<div className='IconWrap2'>
<div>
<div className='IconWrap6'>
<div profile={profile} className='IconWrap6True'/>
<div onclick={forProfile} className='IconWrap7'>
<img src={defaultProfile}/>
</div>
</div>
</div>
<div className='textWrap'>
<div className='textWrap2'>
<div className='textWrap3'>
프로필
</div>
</div>
</div>
</div>
</div>
</NavigationBarWrap1>
)
}
export default NavigationBar;
pass the profile prop to NavigationBarWrap1
<NavigationBarWrap1 profile={profile}>

I want to make components with two buttons aligned vertically in react

I want to make a component with increment and decrement functionality. Increment and decrement arrow buttons are aligned vertically and a text on the right side of those buttons which is the counter and a reset button under it.
Here is the component that I want:
i made a simple code that is quite similar to what you want :
Here is the Code i wrote in App.js ( you can move the code later to in independant component ) :
import React from "react";
import "./App.css";
import { useState } from "react";
function App() {
const [counter, setCounter] = useState(0);
return (
<div class="grid-container">
<div class="grid-item" onClick={() => setCounter(counter + 1)}>
<i class="fas fa-2x fa-angle-up"></i>
</div>
<div class="grid-item">{counter}</div>
<div class="grid-item" onClick={() => setCounter(counter - 1)}>
<i class="fas fa-2x fa-angle-down"></i>
</div>
<div class="grid-item" onClick={() => setCounter(0)}>
Reset
</div>
</div>
);
}
export default App;
Now here is the App.css content ( for styling ) :
.grid-container {
display: grid;
grid-template-columns: auto auto;
background-color: #50404d;
height: 200px;
width: 200px;
}
.grid-item {
border: 1px solid #fff;
color: #fff;
padding: 30px 0;
font-size: 20px;
text-align: center;
}
Note: for the icons to work you need to add this piece of code in "public/index.html" inside the <header> tag :
<script
src="https://kit.fontawesome.com/a076d05399.js"
crossorigin="anonymous"
></script>
I hope this simple solution helps you get an idea .

footer page end distance

I added a footer to my page. When it is a page length it covers the content.
There should be a distance between the end of the page and the footer.
It's ok when the page is 100 percent, but it happens when the page gets longer
But I want a distance between.This is scss.
.footer {
display: flex;
background-color: #222831;
min-height: 5vh;
justify-content: space-between;
padding: 10px;
align-items: center;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
This is my layout
import React from "react";
import Footer from "./footer";
import Header from "./header";
const Layout = ({ children }) => {
return (
<div className="layout">
<Header />
<div className="children">{children}</div>
<Footer></Footer>
</div>
);
};
export default Layout;
This is my footer
import {
AiFillLinkedin,
AiFillGithub,
AiFillInstagram,
AiOutlineMail,
} from "react-icons/ai";
export default function Footer() {
return (
<div className="footer">
<div className="logo">
<span className="bracket">{"<"}</span>
<p>Handcrafted by</p>
<span className="bracket">{"{"}</span>
<span className="name">{"ömer"}</span>
<span className="bracket">{"}"}</span>
<span className="bracket">{"/>"}</span>
</div>
<div className="icons">
<a href="https://www.linkedin.com/in/omersahin1/">
<AiFillLinkedin className="icon" size={20} />
</a>
<a href="https://github.com/1sahinomer1">
<AiFillGithub className="icon" size={20} />
</a>
<a href="https://github.com/shnomr">
<AiFillInstagram className="icon" size={20} />
</a>
<a href="mailto:1sahinomer1#gmail.com">
<AiOutlineMail className="icon" size={20} />
</a>
</div>
</div>
);
}
Thank you.

Next js font awesome and google fonts

Hoping to get some help on an issue I have been having in Next js. I am using Fontawesome-react package for icon imports which is working fine but when I attempt to load in a google font style sheet into the head of my main component, it changes the fonts but makes the font awesome icons disappear. I have tried a couple of different solutions such as loading the font locally and utilizing _document and _app components but none fix the issue I am having. Everything ends up changing the font but still gets rid of all the font awesome icons from every part of my app. I will copy in the Nav component I have and the Layout component that holds everything.
Thank you for any help!
import React from 'react'
import Nav from './nav/Nav'
import Head from 'next/head'
import Footer from './Footer'
type Props = {
title?: string
}
const Layout: React.FC<Props> = ({ children, title = 'Macros' }) => {
return (
<div>
<Head>
<title>{title}</title>
<link
href="https://fonts.googleapis.com/css?family=Darker+Grotesque&display=swap"
rel="stylesheet"
/>
</Head>
<Nav />
<div id="pageContent">{children}</div>
<Footer />
<style jsx global>{`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: lighter;
font-family: 'Darker Grotesque', sans-serif;
}
#pageContent {
padding: 8rem 1rem;
}
`}</style>
</div>
)
}
export default Layout
import React, { useState } from 'react'
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'
import { faBars, faSearch, faPlus } from '#fortawesome/free-solid-svg-icons'
import Link from 'next/link'
const NavBar: React.FC = () => {
const [navBarStatus, isOpen] = useState<Boolean>(false)
const toggleMenu = () => {
isOpen(navBarStatus ? false : true)
}
return (
<nav id="navContainer">
<div id="mobileNav">
<ul id="navBarTop">
<li>
<button type="button" className="navIcon" onClick={toggleMenu}>
<FontAwesomeIcon icon={faBars} />
</button>
</li>
<li>
<Link href="/">
<a>
<h3>Macro</h3>
</a>
</Link>
</li>
<li>
<button type="button" className="navIcon">
<FontAwesomeIcon icon={faSearch} />
</button>
</li>
</ul>
<ul id="navbarBottom">
<li>Top</li>
<li>New</li>
<li>Protein</li>
<li>Carbs</li>
<li>Fats</li>
</ul>
</div>
<div id="appDrawer">
<ul id="topIcons">
<li>
<button type="button" className="navIcon" onClick={toggleMenu}>
<FontAwesomeIcon icon={faBars} />
</button>
</li>
<li>
<button type="button" className="navIcon">
<FontAwesomeIcon icon={faPlus} />
</button>
</li>
</ul>
<nav>
<ul id="menuList">
<Link href="/">
<a>
<p>Home</p>
</a>
</Link>
<Link href="/">
<a>Favorites</a>
</Link>
<Link href="/">
<a>Notifications</a>
</Link>
<Link href="/">
<a>Login/Sign up</a>
</Link>
</ul>
</nav>
</div>
<style jsx>{`
#navContainer {
background-color: #504761;
color: white;
position: fixed;
width: 100%;
}
#navContainer a {
text-decoration: none;
color: white;
}
#mobileNav {
display: ${navBarStatus ? 'none' : ''};
}
#navBarTop {
color: white;
display: flex;
justify-content: space-between;
list-style: none;
padding: 1rem 1rem 0.5rem 1rem;
font-size: 1.5rem;
}
.navIcon {
color: white;
border: none;
background-color: #504761;
font-size: 1.5rem;
}
#navbarBottom {
display: flex;
list-style: none;
justify-content: space-evenly;
padding: 1rem 0;
}
#appDrawer {
display: ${navBarStatus ? 'block' : 'none'};
background-color: #504761;
height: 100vh;
}
#topIcons {
display: flex;
justify-content: space-between;
list-style: none;
padding: 1rem;
font-size: 1.5rem;
}
#menuList {
padding: 2rem 0 2rem 1rem;
display: flex;
flex-direction: column;
}
#menuList a {
font-size: 2rem;
margin: 1rem 0;
}
`}</style>
</nav>
)
}
export default NavBar

Unexpected white area below html in Reactjs

I use Reactjs and encounter an unexpected white area below the html tag:
I've checked all my .css files and cannot find any margin, padding or position attributes that might cause that problem. When I use Google Chrome inspector, I cannot inspect that white space since it's below my html tag (image above). There's no error messages indicate the cause.
My react app structure:
Here's the code:
App.js:
import React, {Component} from 'react';
import Wrapper from './components/Wrapper';
import SongCard from './components/SongCard';
import songs from './songs.json';
class App extends Component {
state = {
songs
};
render() {
return ([
<div key={0}>
<Wrapper>
{this.state.songs.map(song => (
<SongCard
key={song.id}
id={song.id}
name={song.name}
artist={song.artist}
src={song.src}
/>
))}
</Wrapper>
</div>
]);
}
}
export default App;
Wrapper.js:
import React from 'react';
import './Wrapper.css';
const Wrapper = props => (
<div className="row justify-content-center">
<div className="col-lg-8">{props.children}</div>
</div>
);
export default Wrapper;
Wrapper.css:
.row, .col-lg-8 {
margin: 0;
padding: 0;
color: white;
font-family: 'Amaranth', sans-serif;
}
SongCard.js:
import React from 'react';
import './SongCard.css';
const SongCard = props => (
<div className="song-card">
<div className="row">
<div className="col-auto spotify-player">
<iframe title={props.id} src={props.src} frameBorder="0" allowtransparency="true"></iframe>
</div>
<div className="col text-center song-info">
<div>{props.name}</div>
<div>{props.artist}</div>
</div>
</div>
<div className="song-card-divider"></div>
</div>
);
export default SongCard;
SongCard.css:
iframe {
width: 100%;
}
.col, .col-auto, .song-card {
margin: 0;
padding: 0;
background-color: #343a40;
}
.spotify-player {
width: 80px;
height: 80px;
}
.song-card-divider {
height: 0;
border-top: 1px solid #e9ecef;
}
I've looked for answers but couldn't find any answer.
I've found the cause of the problem:
It's the iframe height that causes the extra white area on the bottom of the page. I post my answer here so this question can be marked as answered and hopefully it helps people who have the same problem.

Resources