From bd6398afb26c7175b09a72f350ad21ed9e96b02d Mon Sep 17 00:00:00 2001 From: Anastasia Kostyukova Date: Sun, 24 Jul 2016 19:42:33 +0300 Subject: [PATCH] rename cards --- components/Board.jsx | 26 +++++++++++++++++++++++++- components/Card.jsx | 16 ++++++++++++++++ components/List.jsx | 10 ++++++++-- components/Lists.jsx | 2 +- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/components/Board.jsx b/components/Board.jsx index 8609bc1..18b0ed9 100644 --- a/components/Board.jsx +++ b/components/Board.jsx @@ -21,6 +21,22 @@ function deleteCard(lists, listName, cardName) { }); } +function renameCard(lists, listName, newCardName, oldCardName) { + return lists.map((l)=> { + if (l.name === listName) { + return { ...l, + cards: l.cards.map((c) => { + if (c === oldCardName) { + return newCardName; + } + return c; + }) + }; + } + return l; + }); +} + export default class Board extends React.Component { state = { lists: [], @@ -59,6 +75,13 @@ export default class Board extends React.Component { }) } + onRenameCard = (listName, newCardName, oldCardName) => { + console.log(`${listName} ${newCardName} ${oldCardName}`); + this.setState({ + lists: renameCard(this.state.lists, listName, newCardName, oldCardName), + }) + } + maxCountPages = () => { return Math.floor(this.state.lists.length / 4); } @@ -74,13 +97,14 @@ export default class Board extends React.Component { pageNum: this.state.maxPages >= this.state.pageNum ? this.state.pageNum + 1 : this.state.pageNum, }) } + render() { return (
); diff --git a/components/Card.jsx b/components/Card.jsx index eb2afc5..537c5f2 100644 --- a/components/Card.jsx +++ b/components/Card.jsx @@ -3,15 +3,31 @@ import Input from './Input'; import Button from './Button'; export default class Card extends React.Component { + state = { + cardNameChanged: '' + } + onDeleteCard = () => { this.props.onDeleteCardinList(this.props.name); } + onRenameCardNameChanged = (e) => { + this.setState({ + cardNameChanged: e.target.value, + }); + } + + onRenameCard = () => { + this.props.onRenameCardinList(this.state.cardNameChanged, this.props.name); + } + render() { return (

{this.props.name}

+ +
) } diff --git a/components/List.jsx b/components/List.jsx index 266e684..93c7c6e 100644 --- a/components/List.jsx +++ b/components/List.jsx @@ -22,9 +22,14 @@ export default class List extends React.Component { this.props.onNewCard(this.props.name, this.state.newCardName); } - onDeleteCardinList = (cardName) => { + onDeleteCard = (cardName) => { this.props.onDeleteCard(this.props.name, cardName); } + + onRenameCard = (newCardName, oldCardName) => { + this.props.onRenameCard(this.props.name, newCardName, oldCardName); + } + render() { const listStyle = { display: 'table-cell', @@ -34,7 +39,8 @@ export default class List extends React.Component { } let cards = null; if (this.props.cards) - cards = this.props.cards.map(c => () ); + cards = this.props.cards.map(c => () ); return (

{this.props.name}

diff --git a/components/Lists.jsx b/components/Lists.jsx index f62d386..c1d3916 100644 --- a/components/Lists.jsx +++ b/components/Lists.jsx @@ -40,7 +40,7 @@ export default class Lists extends React.Component { if ((i >= pageNum * offset) && (i < (pageNum + 1) * offset)) { return () + onRenameCard={this.props.onRenameCard} cards={l.cards}/>) } })}