Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] styling for clicked plant card #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions app/add-details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export default function Home() {
harvest_season: 'SPRING',
water_frequency: 'string',
weeding_frequency: 'string',
plant_seed_indoors_start: 'string',
plant_seed_indoors_end: 'string',
plant_seed_outdoors_start: 'string',
plant_seed_outdoors_end: 'string',
plant_transplant_start: 'string',
plant_transplant_end: 'string',
indoors_start: 'string',
indoors_end: 'string',
outdoors_start: 'string',
outdoors_end: 'string',
transplant_start: 'string',
transplant_end: 'string',
harvest_start: 'string',
harvest_end: 'string',
beginner_friendly: true,
Expand All @@ -42,12 +42,12 @@ export default function Home() {
harvest_season: 'SPRING',
water_frequency: 'string',
weeding_frequency: 'string',
plant_seed_indoors_start: 'string',
plant_seed_indoors_end: 'string',
plant_seed_outdoors_start: 'string',
plant_seed_outdoors_end: 'string',
plant_transplant_start: 'string',
plant_transplant_end: 'string',
indoors_start: 'string',
indoors_end: 'string',
outdoors_start: 'string',
outdoors_end: 'string',
transplant_start: 'string',
transplant_end: 'string',
harvest_start: 'string',
harvest_end: 'string',
beginner_friendly: true,
Expand Down
23 changes: 22 additions & 1 deletion app/view-plants/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function Page() {

const [plants, setPlants] = useState<Plant[]>([]);
const [userPlants, setUserPlants] = useState<Plant[]>([]);
const [selectedPlants, setSelectedPlants] = useState<Plant[]>([]);
const user_id: UUID = 'e72af66d-7aae-45f6-935a-187197749d9f';
const userState = 'TENNESSEE';
async function fetchUserPlants(user_id: UUID) {
Expand Down Expand Up @@ -52,6 +53,18 @@ export default function Page() {
};
fetchData();
}, []);
function excludeElement<T>(array: T[], element: T): T[] {
return array.filter(item => item !== element);
}

function addPlant(plant: Plant) {
if (selectedPlants.includes(plant)) {
setSelectedPlants(excludeElement(selectedPlants, plant));
} else {
setSelectedPlants([...selectedPlants, plant]);
}
console.log(selectedPlants);
}

return (
<div className="main">
Expand Down Expand Up @@ -80,8 +93,16 @@ export default function Page() {
{viewingOption === 'all' &&
(inAddMode ? (
<div>
{selectedPlants.length === 0 ? (
<h3>Select Plants</h3>
) : (
<h3>{selectedPlants.length} Plants Selected</h3>
)}

{plants.map((plant, key) => (
<PlantCard key={key} plant={plant} canSelect={true} />
<div key={key} onClick={() => addPlant(plant)}>
<PlantCard key={key} plant={plant} canSelect={true} />
</div>
))}
<div className="footer">
<button onClick={() => setInAddMode(false)}>
Expand Down
104 changes: 0 additions & 104 deletions components/PlantCard/PlantCardStyles.module.css

This file was deleted.

67 changes: 47 additions & 20 deletions components/PlantCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React from 'react';
import { Plant } from '@/types/schema';
import styles from './PlantCardStyles.module.css';
import {
Attribute,
Card,
CardContent,
CardPic,
PlantAttributes,
RoundCheck,
TopRight,
} from './styles';

export default function PlantCard({
plant,
Expand All @@ -9,35 +17,54 @@
plant: Plant;
canSelect: boolean;
}) {
console.log(canSelect);
function toggle() {
// Toggle the green border on the Card
const elem = document.getElementById(plant.id);
elem!.classList.toggle('greenBorder');

// Toggle the checkbox state
const checkBox = document.getElementById(
plant.id + 'check',
) as HTMLInputElement;
checkBox.checked = !checkBox.checked;
}
function toggleCheck() {
const checkBox = document.getElementById(
plant.id + 'check',
) as HTMLInputElement;
checkBox.checked = !checkBox.checked;
}

return (
<div className={styles.Card}>
<div className={styles.CardPic}>
<img alt={plant.plant_name}></img>
</div>
<div className={styles.CardContent}>
<Card onClick={toggle} id={plant.id}>
{canSelect && (
<TopRight>
<RoundCheck onClick={toggleCheck} id={plant.id + 'check'} />
</TopRight>
)}
<CardPic>
<img alt={plant.plant_name} />

Check warning on line 46 in components/PlantCard/index.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element

Check warning on line 46 in components/PlantCard/index.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
</CardPic>
<CardContent>
<h2>{plant.plant_name}</h2>
<div className={styles.PlantAttributes}>
<div className={styles.Attribute}>
{/* icon */}
<PlantAttributes>
<Attribute>
<p>{plant.harvest_start + ' - ' + plant.harvest_end}</p>
</div>
<div className={styles.Attribute}>
{/* icon */}
</Attribute>
<Attribute>
<p>{plant.water_frequency}</p>
</div>
<div className={styles.Attribute}>
{/* icon */}
</Attribute>
<Attribute>
<p>
{plant.sunlight_min_hours}
{plant.sunlight_max_hours
? ' - ' + plant.sunlight_max_hours
: ''}{' '}
hours/day
</p>
</div>
</div>
</div>
</div>
</Attribute>
</PlantAttributes>
</CardContent>
</Card>
);
}
97 changes: 97 additions & 0 deletions components/PlantCard/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import styled from 'styled-components';

export const Card = styled.div`
position: relative;
height: 40vh;
width: 20vw;
display: flex;
flex-direction: column;
align-items: start;
border-radius: 12px;
background-color: white;
box-shadow:
0 24px 38px 3px rgba(0, 0, 0, 0.14),
0 9px 46px 8px rgba(0, 0, 0, 0.12),
0 11px 15px -7px rgba(0, 0, 0, 0.2);

&.greenBorder {
border: 1px solid #95b509;
}
`;

export const CardPic = styled.div`
height: 60%;
width: 100%;
background-color: #f5f6f6;
display: flex;
justify-content: center;
align-items: center;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
`;

export const CardContent = styled.div`
display: flex;
flex-direction: column;
padding-left: 1vw;
height: 40%;
row-gap: 1vh;

> * {
margin: 0;
}

> h2 {
font-size: 1.5vw;
margin-top: 1vh;
}
`;

export const PlantAttributes = styled.div`
display: flex;
flex-direction: column;
gap: 1vh;
`;

export const Attribute = styled.div`
display: flex;
flex-direction: row;

> * {
margin: 0;
font-size: 1vw;
}
`;

export const RoundCheck = styled.input.attrs({ type: 'checkbox' })`
width: 1.3em;
height: 1.3em;
background-color: white;
border-radius: 50%;
vertical-align: middle;
border: 1px solid #95b509;
-webkit-appearance: none;
outline: none;
cursor: pointer;

&:checked {
background-color: #95b509;
}

&:checked::before {
content: '✓';
color: white;
font-size: 0.9em;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
`;

export const TopRight = styled.div`
position: absolute;
top: 0;
right: 0;
padding: 10px 10px;
`;