import React from 'react'; import {isPlainClick} from '../events'; import ActionsMenu from './ActionsMenu'; import PlantingChip from './PlantingChip'; import PlantingRow from './PlantingRow'; // One garden, as a row that opens: its picture, name and how it is doing. Opened // it has a picture, then what is planted, as perennials (just names) and annuals // (each with its progress). The buttons and menus are for gardens you can change. export default function GardenCard({garden, defaultOpen, defaultIconUrl, onPlant, highlightedId, highlightKind, onPlantingUpdated, onEditPlanting, onHarvestPlanting, onSaveSeedsPlanting, onAddPhoto, onFinishPlanting, onEditGarden}) { const {id, name, url, image_url: imageUrl, layout_url: layoutUrl, owner, actions, plant_url: plantUrl, plantings_count: plantingsCount, harvesting_now: harvestingNow} = garden; const {perennials, annuals} = garden; const empty = perennials.length === 0 && annuals.length === 0; // What each planting's menu items open, for annuals and perennials alike. const handlers = { edit: onEditPlanting, harvest: onHarvestPlanting, seeds: onSaveSeedsPlanting, finish: onFinishPlanting, photo: onAddPhoto && ((planting, action) => onAddPhoto({label: `${planting.crop.name} planting`, href: action.href})), }; function plant(event) { if (onPlant && isPlainClick(event)) { event.preventDefault(); onPlant(garden); } } const summary = [ `${plantingsCount} ${plantingsCount === 1 ? 'planting' : 'plantings'}`, harvestingNow > 0 ? `harvesting now: ${harvestingNow}` : null, ].filter(Boolean).join(' · '); return (
{name}
{summary} {owner && · owner: {owner.login_name}}
{layoutUrl && (