Newer
Older
pokemon-go-trade / static / html / src / components / connect-modal.js
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Modal from '@material-ui/core/Modal';
import WantGroup from './want-group';

function getModalStyle() {
  const top = 50;
  const left = 50;

  return {
    top: `${top}%`,
    left: `${left}%`,
    transform: `translate(-${top}%, -${left}%)`,
  };
}

const useStyles = makeStyles(theme => ({
  paper: {
    position: 'absolute',
    width: '80%',
    height: '90%',
    backgroundColor: theme.palette.background.paper,
    border: '2px solid #000',
    boxShadow: theme.shadows[5],
    padding: theme.spacing(2, 4, 3),
    overflow: 'scroll',
  },
}));

export default function ConnectModal(props) {
  const classes = useStyles();
  // getModalStyle is not a pure function, we roll the style only on the first render
  const [modalStyle] = React.useState(getModalStyle);

  const {
    pokemonWantList, onDeselectPokemon, handleLinkWantAndNeed, linked, selectedId,
  } = props;

  let {
    open,
  } = props;

  const body = (
    <div style={modalStyle} className={classes.paper}>
      {
        pokemonWantList.map(wantGroup => (
          <WantGroup
            handleLinkWantAndNeed={handleLinkWantAndNeed}
            pokemonList={wantGroup.pokemons}
            groupId={wantGroup.id}
            groupName={wantGroup.group_name}
            linked={linked}
            selectedId={selectedId}
            connect
          />
        ))
      }
      <button type="button" style={{ fontSize: '10em', position: 'fixed', bottom: 0, right: 0 }} onClick={() => {
        open = false
      }}>Done</button>
    </div>
  );

  return (
    <div>
      <Modal
        open={open}
        onClose={onDeselectPokemon}
        aria-labelledby="simple-modal-title"
        aria-describedby="simple-modal-description"
      >
        {body}
      </Modal>
    </div>
  );
}