import { AppBar, Box, Button, DialogActions, DialogTitle, Grid2 as Grid, IconButton, Toolbar, Typography } from "@mui/material"; import { Close } from "@mui/icons-material"; import ResponsiveDialog from "common/ResponsiveDialog"; import { useMobile } from "hooks"; import { Bin, Component } from "models"; import { pond } from "protobuf-ts/pond"; import React, { useEffect, useState } from "react"; import BinComponents from "./BinComponents"; type Mode = "add" | "update" | "remove"; interface Props { open: boolean; onClose: (refresh?: boolean) => void; mode?: Mode; bin?: Bin; canEdit: boolean; openedBinYard?: string; userID: string; coords?: { longitude: number; latitude: number }; binYards?: pond.BinYardSettings[]; components?: Map; setComponents?: React.Dispatch>>; updateBinStatus?: (componentKeys: string[], removed?: boolean) => void; } export default function BinSensors(props: Props) { const isMobile = useMobile(); const { open, bin, onClose, mode, openedBinYard, components, setComponents, updateBinStatus } = props; const [initialized, setInitialized] = useState(false); useEffect(() => { if (open) { setInitialized(true); } else { setInitialized(false); } }, [bin, open, mode, openedBinYard]); const close = (refresh?: boolean) => { onClose(refresh); }; const titleText = () => { return "Add Sensors to " + (bin ? bin.name() : "Bin"); }; const title = () => { if (isMobile) { return ( close()} aria-label="close"> {titleText()} ); } return ( {titleText()} ); }; const componentsForm = () => { if (bin) { return ( ); } return null; }; const actions = () => { return ( {!isMobile && ( )} ); }; if (!open || !initialized) { return null; } return ( { onClose(); }}> {title()} {componentsForm()} {actions()} ); }