diff --git a/src/components/SuggestCard.jsx b/src/components/SuggestCard.jsx index ad7feca..8a42087 100644 --- a/src/components/SuggestCard.jsx +++ b/src/components/SuggestCard.jsx @@ -1,18 +1,43 @@ import { Link } from 'react-router-dom'; import { motion } from 'framer-motion'; +import { config } from '../logic/constants'; +import { useState } from "react"; const SuggestCard = ({ name, imageUrl }) => { + const [plants, setPlants] = useState(JSON.parse(localStorage.getItem('plants'))); + + const createPlant = async () => { + var newPlants = plants; + let nextId = Math.max.apply(Math, plants.map(function(o) { return o.id; })) + 1; + let addedPlant = { + "id": nextId, + "img": imageUrl, + "type": name, + "age": 0, + "likes": 0, + "owned": true, + "name": name, + "user": "self", + "description": "self" + }; + newPlants.push(addedPlant); + setPlants(newPlants); + localStorage.setItem('plants', JSON.stringify(newPlants)); + + window.location.href = config.base + "/#/garden"; + }; + return (
{name}