import React, {useState} from 'react'; import Modal from './Modal'; import PickerButton from './PickerButton'; import RecordHarvestModal from './RecordHarvestModal'; import SaveSeedsModal from './SaveSeedsModal'; // What can be done to a planting from a page that is not about one planting, // like the home page: the question to ask, and the dialog that does it. const ACTIONS = { harvest: {title: 'What did you harvest?', Dialog: RecordHarvestModal}, seeds: {title: 'Which plant are you saving seeds from?', Dialog: SaveSeedsModal}, }; // A button that asks which of your plantings you mean, then opens the usual // dialog for that planting (recording a harvest, or saving seeds); once saved // the page reloads. // // plantings: [{id, url, planted_at, ready, crop: {name}}], what is growing, with // what is ready to pick first. export default function PlantingPicker({action, label, sublabel, buttonClass, plantings}) { const [open, setOpen] = useState(false); const [planting, setPlanting] = useState(null); const {title, Dialog} = ACTIONS[action]; function close() { setOpen(false); setPlanting(null); } return ( <> setOpen(true)} /> {open && !planting && (
{plantings.length === 0 ? (

You have nothing growing yet. Plant something first.

) : (
Your plantings {plantings.map((candidate) => ( ))}
)}
)} {open && planting && ( window.location.reload()} /> )} ); }