EvilSpark

hackstrap

Mar 15th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from "react";
  2. import { connect } from "react-redux";
  3.  
  4. import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
  5. import styled from "styled-components";
  6. import List from "./sub-components/List";
  7. import ListAdder from "./sub-components/ListAdder";
  8. import { reorderList, reorderBoard } from "../../store/actions/TeamBoard";
  9.  
  10. const StyledBoard = styled.div`
  11.   display: flex;
  12.   flex-direction: column;
  13.   align-items: center;
  14.   height: calc(100vh - 111px);
  15.   overflow-x: auto;
  16.   overflow-y: auto;
  17.  
  18.   @media (max-width: 1436px) {
  19.     align-items: ${props => props.numLists > 3 && "self-start"};
  20.   }
  21.  
  22.   @media (max-width: 1152px) {
  23.     align-items: ${props => props.numLists > 2 && "self-start"};
  24.   }
  25.  
  26.   @media (max-width: 868px) {
  27.     align-items: ${props => props.numLists > 1 && "self-start"};
  28.   }
  29.  
  30.   @media (max-width: 768px) {
  31.     align-items: center;
  32.     height: 100%;
  33.   }
  34. `;
  35.  
  36. const BoardTitle = styled.div`
  37.   margin-top: 1rem;
  38.   padding: 0.5rem;
  39.   font-size: 1.5rem;
  40.   font-weight: 500;
  41.   color: white;
  42. `;
  43.  
  44. const BoardTitleWrapper = styled.div`
  45.   width: 100%;
  46.   display: flex;
  47.   justify-content: center;
  48. `;
  49.  
  50. class TeamBoard extends React.Component {
  51.   handleDragEnd = ({ draggableId, source, destination, type }) => {
  52.     // dropped outside the list
  53.     const { dispatch, boardId } = this.props;
  54.   };
  55.   render = () => {
  56.     const { lists, boardTitle, boardId } = this.props;
  57.     return (
  58.       <React.Fragment>
  59.         <BoardTitleWrapper>
  60.           <BoardTitle>{boardTitle}</BoardTitle>
  61.         </BoardTitleWrapper>
  62.         <StyledBoard numLists={lists.length}>
  63.           <DragDropContext onDragEnd={this.handleDragEnd}>
  64.             <Droppable
  65.               droppableId={boardId}
  66.               type="COLUMN"
  67.               direction="horizontal"
  68.             >
  69.               {droppableProvided => (
  70.                 <div className="lists-wrapper" ref={droppableProvided.innerRef}>
  71.                   {lists.map((list, index) => (
  72.                     <Draggable
  73.                       key={list._id}
  74.                       draggableId={list._id}
  75.                       index={index}
  76.                     >
  77.                       {provided => (
  78.                         <React.Fragment>
  79.                           <div
  80.                             ref={provided.innerRef}
  81.                             {...provided.draggableProps}
  82.                             {...provided.dragHandleProps}
  83.                             data-react-beautiful-dnd-draggable="0"
  84.                             data-react-beautiful-dnd-drag-handle="0"
  85.                           >
  86.                             <List
  87.                               list={list}
  88.                               boardId={boardId}
  89.                               style={{ height: "initial" }}
  90.                             />
  91.                           </div>
  92.                           {provided.placeholder}
  93.                         </React.Fragment>
  94.                       )}
  95.                     </Draggable>
  96.                   ))}
  97.                   {droppableProvided.placeholder}
  98.                   {lists.length < 5 && (
  99.                     <ListAdder
  100.                       boardId={boardId}
  101.                       numLeft={5 - lists.length}
  102.                       style={{ height: "initial" }}
  103.                     />
  104.                   )}
  105.                 </div>
  106.               )}
  107.             </Droppable>
  108.           </DragDropContext>
  109.         </StyledBoard>
  110.       </React.Fragment>
  111.     );
  112.   };
  113. }
  114.  
  115. const mapStateToProps = (state, ownProps) => {
  116.   const { boardId } = ownProps.match.params;
  117.  
  118.   const board = state.boardsById[boardId];
  119.   return {
  120.     lists: board.lists.map(listId => state.listsById[listId]),
  121.     boardTitle: board.title,
  122.     boardId
  123.   };
  124. };
  125.  
  126. export default connect(mapStateToProps)(TeamBoard);
Add Comment
Please, Sign In to add comment