Help me, help you, by helping me, so I don't ask so many questions(yep?)

Here's the site: https://anglian-online.netlify.app/ Here's the code: https://github.com/callum-laing/shopping-site My question? glad you asked. See image for a detailed explanation. I created a grid with 3 columns, I was expecting each column to host 1 image/card, however it appears each column is hosting 3 image/cards. First time attempting this, and I googled 99.95% of it, so I'm sure the code is wrong in probably the app/components/Card.js, but I can't figure out what is wrong.
No description
57 Replies
Matt
Mattā€¢8mo ago
I'm not a professional by any means
majkl
majklā€¢8mo ago
Look where you have div..page_cards__DAsUi.
Matt
Mattā€¢8mo ago
but I'm 99% sure you're only suppose to have 1 main tag per page. You can achieve what youre looking to do with one grid not having multiples. Also why did you nest grids? (main > div)
majkl
majklā€¢8mo ago
You are using the same class with grid-template-columns:repeat(3,1fr) on parent and child.
CDL
CDLā€¢8mo ago
I'm as confused as you both are I think I've combined 2 solutions into 1 with my googling
MarkBoots
MarkBootsā€¢8mo ago
your shop/page.jsx is mapping over all posts to create a card component, but the card component is mapping over all posts as well. so you're doing it double
No description
majkl
majklā€¢8mo ago
No description
CDL
CDLā€¢8mo ago
hmm I might need to rip it down and try it again then seems it's quite messy
majkl
majklā€¢8mo ago
I second that idea. šŸ˜„
CDL
CDLā€¢8mo ago
It's my first A) proper react app, B) nextjs app and C) attempting this layout lol
majkl
majklā€¢8mo ago
Sure thing, that is how one learns.
CDL
CDLā€¢8mo ago
uff, I've actually no idea how to do this now haha What I'm trying to do: take the id from the data.js file, and create a card for every id in the data.js file's array, but have it show as a 3 column grid, so item | item | item and I'm extremely confused
majkl
majklā€¢8mo ago
How does it generate the classes? For starters, just make them different (ir do not generate that div twice).
CDL
CDLā€¢8mo ago
well this is part of the issue, I really don't know, at all, how to do this, the entire thing is brand new to me lol. I think I map through the array and create a new card for every item in items, but how to put that into the correct positions in grid is what' sconfusing me most
majkl
majklā€¢8mo ago
I mean, Matt was right, the main is present in great abundance.
CDL
CDLā€¢8mo ago
yea I've removed basically all of it, so I'm back to the basics on shop
majkl
majklā€¢8mo ago
I bet it is going to be some very stupid omission. It just happens. šŸ˜„
CDL
CDLā€¢8mo ago
I probably should've tried doing this in vanilla first I went straight into nextjs and now my brain is on fire lol
vince
vinceā€¢8mo ago
I didn't read most of this but add complexity after you get things working Like, make the page that you want using regular html css js (inside next) and then start adding the logic and components after
CDL
CDLā€¢8mo ago
right now I'm just trying to figure out how I create a list of arrays in a data.js file, and then map that list of arrays into their own cards, and I'm struggling even there lol
b1mind
b1mindā€¢8mo ago
rofl now I need the code se
// shop/page
<main className={Styles.shopContainer}>
{posts.map((post) => (

<div key={post.id} className={Styles.card}>
<img className="imgCard" src={`/cleats.jpg`} alt={post.name} />
<h2>{post.name}</h2>
<p>${post.price}</p>
<button>Add to Cart</button>
</div>
))}
</main>
// shop/page
<main className={Styles.shopContainer}>
{posts.map((post) => (

<div key={post.id} className={Styles.card}>
<img className="imgCard" src={`/cleats.jpg`} alt={post.name} />
<h2>{post.name}</h2>
<p>${post.price}</p>
<button>Add to Cart</button>
</div>
))}
</main>
Ok so we need the .card child err no .cards parent
CDL
CDLā€¢8mo ago
evanescance - bring me to life, just came on, so we can't mess this up
b1mind
b1mindā€¢8mo ago
and it needs to be where? You need to add .cards based on your css. I'll let you try first
CDL
CDLā€¢8mo ago
the css is based on the previous answer from googling, so it might need re-doing
b1mind
b1mindā€¢8mo ago
I mean its fine
CDL
CDLā€¢8mo ago
as there's no card.js file anymore
b1mind
b1mindā€¢8mo ago
lets get there first we are in CSS land this is only from what I see in /stores
CDL
CDLā€¢8mo ago
ah ok ok
b1mind
b1mindā€¢8mo ago
sry shop/***.css and .jsx only two files we are working with šŸ˜‰
CDL
CDLā€¢8mo ago
I think cards could be shopContainer tbh?
b1mind
b1mindā€¢8mo ago
yea if you wanna make that refactor do it to it
CDL
CDLā€¢8mo ago
cards was just a wrapper to add a grid
b1mind
b1mindā€¢8mo ago
then you wont have to add another div šŸ˜‰ you got this
CDL
CDLā€¢8mo ago
yea doesn't make sense to ahve a main, then a div wrapper inside that I think that actually fixed it, yknow.
b1mind
b1mindā€¢8mo ago
so you are combining .shoping container into .cards? then what (missing one step)
CDL
CDLā€¢8mo ago
.shopContainer {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-content: center;
gap: 20px;
height: 100vh;
}
.shopContainer {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-content: center;
gap: 20px;
height: 100vh;
}
CDL
CDLā€¢8mo ago
No description
b1mind
b1mindā€¢8mo ago
boom!
CDL
CDLā€¢8mo ago
just had to remove cards, move grid-template-columns into .shopContainer, and done
b1mind
b1mindā€¢8mo ago
<div className={Styles.cards}> hint to the one more step one letter fix šŸ˜‚ ok two hints bad teacher
CDL
CDLā€¢8mo ago
where are you seeing that?
b1mind
b1mindā€¢8mo ago
in the code above, that I got you started with. I can only see past code remember so I'm working off only that block of code and teh css file actually
CDL
CDLā€¢8mo ago
I have
import React from "react";
import Styles from "./page.module.css";
import posts from "../data";

const Shop = () => {
return (
<main className={Styles.shopContainer}>
{posts.map((post) => (
<div key={post.id} className={Styles.card}>
<img className="imgCard" src={`/cleats.jpg`} alt={post.name} />
<h2>{post.name}</h2>
<p>${post.price}</p>
<button>Add to Cart</button>
</div>
))}
</main>
);
};

export default Shop;
import React from "react";
import Styles from "./page.module.css";
import posts from "../data";

const Shop = () => {
return (
<main className={Styles.shopContainer}>
{posts.map((post) => (
<div key={post.id} className={Styles.card}>
<img className="imgCard" src={`/cleats.jpg`} alt={post.name} />
<h2>{post.name}</h2>
<p>${post.price}</p>
<button>Add to Cart</button>
</div>
))}
</main>
);
};

export default Shop;
b1mind
b1mindā€¢8mo ago
yup you got it
CDL
CDLā€¢8mo ago
with
.shopContainer {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-content: center;
gap: 20px;
height: 100vh;
}


.card {
border: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
}

.imgCard {
width: 100%;
height: auto;
}

.btn {
background-color: #4caf50;
color: white;
padding: 10px;
border: none;
cursor: pointer;
}

.btn:hover {
background-color: #45a049;
}
.shopContainer {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-content: center;
gap: 20px;
height: 100vh;
}


.card {
border: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
}

.imgCard {
width: 100%;
height: auto;
}

.btn {
background-color: #4caf50;
color: white;
padding: 10px;
border: none;
cursor: pointer;
}

.btn:hover {
background-color: #45a049;
}
b1mind
b1mindā€¢8mo ago
looks good mate! šŸ‘ NOW make a Card component šŸ¤£
CDL
CDLā€¢8mo ago
-.-
b1mind
b1mindā€¢8mo ago
no really and make another ugly module file and put that .card {} css in it and learn how to use a component proper <,<;; But remember if its not used anywhere else its a hasty abstraction and you are doing cause I told you only for practice.
CDL
CDLā€¢8mo ago
I mean would i not just cut the code in shop, into the card component, then just import the card component into shop, and use props?
b1mind
b1mindā€¢8mo ago
but you do need to understand it and this is good as place as any cause you have "just html" working Idk thats on you šŸ˜„ I don't wanna think that hard
CDL
CDLā€¢8mo ago
lmao
b1mind
b1mindā€¢8mo ago
hey I got my own shit šŸ¤£ working on my project too atm
CDL
CDLā€¢8mo ago
damn svelte brain šŸ˜›
b1mind
b1mindā€¢8mo ago
Also I never said couldn't write React.. Just I rather have it easy with :svelte: šŸ˜‚ without all the ugly boiler plate bs (nd jsx, and all the wrappers needed just to use it.. "ecosystem of trash wrappers on the ground" All these concepts are the same, learning components, reactivity(or what passes for it in React), page/component life cycles. Its all transferable really šŸ˜„ gah I'm spicy today >.>;
CDL
CDLā€¢8mo ago
yeah I'm still picking up react, but ill jump back to svelte once ive buitl 3-4 things and am comfortable until then.. embracing the pain
b1mind
b1mindā€¢8mo ago
Marks as solved. šŸ––
CDL
CDLā€¢8mo ago
I can actually sleep now, this is great thanks all šŸ‘Œ
Want results from more Discord servers?
Add your server