Skip to content
Snippets Groups Projects
Commit 794a03f5 authored by Karsch Lukas's avatar Karsch Lukas
Browse files

#54 - quick actions now working, need to refresh page after action. adjusted styling on plant cards

parent c7bff3f1
No related branches found
No related tags found
1 merge request!40Resolve "Pass "quick actions" to plant overview"
Pipeline #57455 passed
import {NavLink} from "react-router-dom"; import {NavLink} from "react-router-dom";
import "../stylesheets/Navbar.css"
function NavbarRegistrationAndLogin() { function NavbarRegistrationAndLogin() {
return ( return (
<nav> <nav>
<ul> <ul className="navBarList">
<li> <li>
<NavLink className="title" to="/"> <NavLink className="title" to="/">
GrowBros GrowBros
......
import "../stylesheets/PlantCard.css"; import "../stylesheets/PlantCard.css";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {Plant} from "../utils/schemas"; import {Plant} from "../utils/schemas";
import {QuickActionButtonProps} from "./QuickActionButton.tsx"; import {QuickActionButtonType} from "./QuickActionButton.tsx";
import QuickActions from "./QuickActions.tsx"; import QuickActions from "./QuickActions.tsx";
type PlantCardProps = { type PlantCardProps = {
plant: Plant, plant: Plant,
quickActions?: QuickActionButtonProps[] quickActions?: QuickActionButtonType[]
} }
export default function PlantCard({plant, quickActions}: PlantCardProps) { export default function PlantCard({plant, quickActions}: PlantCardProps) {
...@@ -19,7 +19,7 @@ export default function PlantCard({plant, quickActions}: PlantCardProps) { ...@@ -19,7 +19,7 @@ export default function PlantCard({plant, quickActions}: PlantCardProps) {
<h2>{plant.name}</h2> <h2>{plant.name}</h2>
</div> </div>
</Link> </Link>
<QuickActions quickActions={quickActions}/> <QuickActions quickActions={quickActions} plantId={plant.id}/>
</li> </li>
</> </>
); );
......
import PlantCard from "./PlantCard"; import PlantCard from "./PlantCard";
import {Plant} from "../utils/schemas"; import {Plant} from "../utils/schemas";
import {QuickActionButtonProps} from "./QuickActionButton.tsx"; import {QuickActionButtonType} from "./QuickActionButton.tsx";
type PlantsOverviewProps = { type PlantsOverviewProps = {
plants: Plant[], plants: Plant[],
quickActions?: QuickActionButtonProps[] quickActions?: QuickActionButtonType[]
} }
export default function PlantsOverview({plants, quickActions}: PlantsOverviewProps) { export default function PlantsOverview({plants, quickActions}: PlantsOverviewProps) {
......
import "../stylesheets/QuickActions.css" import "../stylesheets/QuickActions.css"
import useGrowbrosFetcher from "../utils/useGrowbrosFetcher.ts";
import HeartBrokenIcon from "@mui/icons-material/HeartBroken";
import AgricultureIcon from "@mui/icons-material/Agriculture";
export type QuickActionButtonProps = { export type QuickActionButtonProps = {
iconClassName: string, type: QuickActionButtonType,
tooltip: string, plantId: number
onClick: () => void
} }
function QuickActionButton({iconClassName, onClick, tooltip}: QuickActionButtonProps) { export type QuickActionButtonType = "ADD_TO_WISHLIST" | "REMOVE_FROM_WISHLIST" | "ADD_TO_GARDEN" | "REMOVE_FROM_GARDEN"
return (
<button onClick={onClick} className={iconClassName + " quickActionButton"} title={tooltip}/> function QuickActionButton({type, plantId}: QuickActionButtonProps) {
); const bc = useGrowbrosFetcher();
switch (type) {
case "ADD_TO_WISHLIST":
return <button onClick={() => bc.addToWishlist(plantId)} className={"fa fa-heart quickActionButton"}
title={"Add this plant to your wishlist"}/>
case "ADD_TO_GARDEN":
return <button onClick={() => bc.addToGarden(plantId)} className={"fa fa-leaf quickActionButton"}
title={"Add this plant to your garden"}/>
case "REMOVE_FROM_WISHLIST":
return (<button onClick={() => bc.removeFromWishlist(plantId)} className={"quickActionButton"}
title={"Remove this plant from your wishlist"}><HeartBrokenIcon sx={{fontSize: 19}}/>
</button>)
case "REMOVE_FROM_GARDEN":
return (<button onClick={() => bc.removeFromGarden(plantId)} className={"quickActionButton"}
title={"Remove this plant from your garden"}><AgricultureIcon/>
</button>)
}
} }
export default QuickActionButton; export default QuickActionButton;
\ No newline at end of file
import QuickActionButton, {QuickActionButtonProps} from "./QuickActionButton.tsx"; import QuickActionButton, {QuickActionButtonType} from "./QuickActionButton.tsx";
import "../stylesheets/QuickActions.css" import "../stylesheets/QuickActions.css"
type QuickActionsProps = { type QuickActionsProps = {
quickActions?: QuickActionButtonProps[]; quickActions?: QuickActionButtonType[];
plantId: number;
} }
function QuickActions({quickActions}: QuickActionsProps) { function QuickActions({quickActions, plantId}: QuickActionsProps) {
if (quickActions) { if (quickActions) {
return <div className="quickActions">{quickActions.map( return <div className="quickActions">{quickActions.map(
(action, index) => (action, index) =>
<QuickActionButton iconClassName={action.iconClassName} <QuickActionButton plantId={plantId}
tooltip={action.tooltip} type={action}
onClick={action.onClick}
key={index} key={index}
/> />
)} </div> )} </div>
......
...@@ -69,11 +69,7 @@ function Wunschliste() { ...@@ -69,11 +69,7 @@ function Wunschliste() {
/> />
<button onClick={handleClearWishList}>Wunschliste leeren</button> <button onClick={handleClearWishList}>Wunschliste leeren</button>
</div> </div>
<PlantsOverview plants={plants}quickActions={[{ <PlantsOverview plants={plants} quickActions={["ADD_TO_GARDEN", "REMOVE_FROM_WISHLIST"]}/>
iconClassName: "fa fa-heart",
onClick: () => console.log("clicked quick action"),
tooltip: "TOOLTIP!"
}]}/>
</> </>
); );
} }
......
.plantCard { .plantCard {
color: #ececec;
position: relative; position: relative;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
...@@ -20,9 +21,9 @@ ...@@ -20,9 +21,9 @@
padding: 1rem; padding: 1rem;
background: linear-gradient( background: linear-gradient(
to bottom, to bottom,
rgba(220, 220, 220, 0), rgba(20, 20, 20, 0),
rgba(220, 220, 220, 0.45), rgba(20, 20, 20, 0.3),
rgba(220, 220, 220, 0.65) rgba(0, 0, 0, 0.5)
); );
} }
...@@ -34,7 +35,7 @@ ...@@ -34,7 +35,7 @@
} }
.plantCard:hover { .plantCard:hover {
color: #4d5927; color: white;
border-color: black; border-color: black;
box-shadow: 0 12px 24px rgb(24 24 24 / 15%); box-shadow: 0 12px 24px rgb(24 24 24 / 15%);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment