From 3e0d5bf49ab25f648bb6ca235a82cc56d78a9a7d Mon Sep 17 00:00:00 2001 From: knowankit <44323532+knowankit@users.noreply.github.com> Date: Fri, 30 Apr 2021 17:50:08 +0530 Subject: [PATCH] feat: adds card in column --- .../columns/buttons/add-column-button.tsx | 30 +++++ src/components/board/columns/index.tsx | 106 ++++++++++-------- 2 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 src/components/board/columns/buttons/add-column-button.tsx diff --git a/src/components/board/columns/buttons/add-column-button.tsx b/src/components/board/columns/buttons/add-column-button.tsx new file mode 100644 index 0000000..b78bc81 --- /dev/null +++ b/src/components/board/columns/buttons/add-column-button.tsx @@ -0,0 +1,30 @@ +import React, { FC } from 'react'; +import { Box, Button } from '@chakra-ui/react'; +import PropTypes from 'prop-types'; + +type Props = { + addColumn: () => void; +}; + +const AddColumnButton: FC = ({ addColumn }) => { + return ( + + + + ); +}; + +AddColumnButton.propTypes = { + addColumn: PropTypes.func +}; + +export default AddColumnButton; diff --git a/src/components/board/columns/index.tsx b/src/components/board/columns/index.tsx index b246399..85d1a31 100644 --- a/src/components/board/columns/index.tsx +++ b/src/components/board/columns/index.tsx @@ -1,67 +1,85 @@ import React, { useState } from 'react'; import { Box, Button, Heading } from '@chakra-ui/react'; +import AddColumnButton from '@/src/components/board/columns/buttons/add-column-button'; const BoardColumns = () => { const tempData = [ - { columnName: 'To-Do' }, - { columnName: 'In Progress' }, - { columnName: 'PR Raised' }, - { columnName: 'Done' } + { columnName: 'To-Do', cards: [] }, + { columnName: 'In Progress', cards: [] }, + { columnName: 'PR Raised', cards: [] }, + { columnName: 'Done', cards: [] } ]; const [columns, setColumns] = useState(tempData); const loadColumns = (column, index) => { - if (columns.length - 1 !== index) { - return ( - - - {column.columnName} - - - - ); - } - return ( - + + + {column.columnName} + + {column.cards.map((card, index) => ( + {card.title} + ))} + + ); }; const addColumn = () => { - setColumns([...columns, { columnName: 'Test' }]); + setColumns([...columns, { columnName: 'Test', cards: [] }]); - console.log('test', columns); + // Scroll to the right when column is added + // const parentOfColumns = document.getElementById('parent-of-columns') + // parentOfColumns.scrollLeft = 300 }; - // const addCard = () => {}; + const addCard = (index: number) => { + // Fetch particular column + const column = columns[index]; + + // Push the card details + column.cards.push({ title: 'Card title' }); + + // Fetch all the columns + const temp = columns; + + // Delete the old list and add the new list + temp.splice(index, 1, column); + setColumns([...temp]); + }; return ( - - {columns.map((column, index) => ( - - {loadColumns(column, index)} - - ))} + + + {columns.map((column, index) => ( + + {loadColumns(column, index)} + + ))} + + ); };