Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ampers: Kaitlin #36

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f3ced3b
added initial logic to board to create card components and what their…
kcforsman Jun 11, 2018
263702a
finished logic in Board and Card components to display a list of card…
kcforsman Jun 11, 2018
4ccf39b
added existing css class names to card component for styling
kcforsman Jun 11, 2018
98f56d3
added existing css classes to board component for styling aka 'board'…
kcforsman Jun 11, 2018
7fbc928
updated boardName and possible the url (though I think I ended up wit…
kcforsman Jun 11, 2018
b47531a
set up enzyme and test file to begin generating shallow tests for boa…
kcforsman Jun 12, 2018
18f4a72
completed basic shallow snaptests for card and board components, boar…
kcforsman Jun 12, 2018
5c23ba5
added jsx to render the basic elements for the new card form and rend…
kcforsman Jun 13, 2018
e0829f8
altered some styling for the form and board
kcforsman Jun 13, 2018
d8d4a3f
finished logic to add a new card to the api and update the board to d…
kcforsman Jun 15, 2018
16eb440
added shallow snapshot test for the NewCardForm and there is a new sn…
kcforsman Jun 15, 2018
5e2b54f
added delete button to the card component and adjusted styling to inc…
kcforsman Jun 15, 2018
dde324d
adjusted styling for the card form to utilize the css class available…
kcforsman Jun 15, 2018
096f85b
added a method to remove a card from the api as well as the board in …
kcforsman Jun 15, 2018
06f874c
finished implementing deleting card logic and still need to display a…
kcforsman Jun 15, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
"devDependencies": {
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.4",
"gh-pages": "^1.2.0"
},
"jest": {
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
},
"homepage": "http://adagold.github.io/inspiration-board"
}
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class App extends Component {
</header>
<Board
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
boardName="Katie-F"
/>
</section>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/Board.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.board {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}

.validation-errors-display {
Expand Down
72 changes: 69 additions & 3 deletions src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import axios from 'axios';
import './Board.css';
import Card from './Card';
import NewCardForm from './NewCardForm';
import CARD_DATA from '../data/card-data.json';

class Board extends Component {
constructor() {
Expand All @@ -16,18 +15,85 @@ class Board extends Component {
};
}

componentDidMount() {
axios.get(`${this.props.url}${this.props.boardName}/cards`)
.then((response) => {
const cards = this.state.cards;
response.data.forEach((card) => {
const newCard = {};
newCard.id = card.card.id;
newCard.text = card.card.text;
newCard.emoji = card.card.emoji;
cards.push(newCard);
})

this.setState({ cards })
})
.catch((error) => {
this.setState({ message: error.message})
});
}

createNewCard = (newCardData) => {
const cards = this.state.cards
axios.post(`${this.props.url}${this.props.boardName}/cards`, newCardData)
.then((response) => {
console.log(response.data.card);
cards.push(response.data.card);
this.setState({
cards,
message: `Sucessfully created Card ${response.data.card.id}`
})
})
.catch((error) => {
this.setState({ message: error.message})
});
};

deleteCard = (id, index) => {
const cards = this.state.cards
axios.delete(`${this.props.url}${this.props.boardName}/cards/${id}`)
.then((response) => {
cards.splice(index, 1)
this.setState({
cards,
message: `Sucessfully deleted Card ${response.data.card.id}`
})
})
.catch((error) => {
this.setState({ message: error.message})
});
};

render() {
const cardComponents = this.state.cards.map((card, index) => {
return<Card
key={index}
index={index}
id={card.id}
text={card.text}
emoji={card.emoji}
deleteCard={ this.deleteCard }
/>;
});

return (
<div>
Board
<div>
<NewCardForm submitNewCard={ this.createNewCard }/>
</div>
<div className="board">
{ cardComponents }
</div>
</div>
)
}

}

Board.propTypes = {

url: PropTypes.string.isRequired,
boardName: PropTypes.string.isRequired
};

export default Board;
15 changes: 15 additions & 0 deletions src/components/Board.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import Board from './Board.js';

describe('Board', () => {
test('that it renders Board with shallow rendering', () => {
const wrapper = shallow(<Board />);

expect(wrapper).toMatchSnapshot();

// wrapper.unmount();
});

});
11 changes: 7 additions & 4 deletions src/components/Card.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
padding: 1em 0;
margin: 0.5rem;

min-height: 250px;
min-height: 225px;
min-width: 225px;
flex-basis: 18%;

border-radius: 5px;

display: grid;
grid-template-columns: 1fr 5fr 1fr;
grid-template: 1fr 5fr 1fr / 1fr 5fr;
align-items: center;
}

Expand All @@ -24,12 +24,12 @@

text-align: center;
font-weight: 100;
overflow: hidden;
max-height: 150px;
}

.card__content-text {
text-overflow: ellipsis;
overflow: hidden;
overflow: scroll;
}

.card__content-emoji {
Expand All @@ -42,6 +42,9 @@
}

.card__delete {
grid-column-start: 3;
justify-content: left;
margin: 0 5px 0;
align-self: start;
font-family: 'Permanent Marker', Helvetica, sans-serif;
}
32 changes: 30 additions & 2 deletions src/components/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,45 @@ import emoji from 'emoji-dictionary';
import './Card.css';

class Card extends Component {
renderText = () => {
if (this.props.text) {
return(
<p className="card__content-text">{ this.props.text }</p>
)
}
}

renderEmoji = () => {
if (this.props.emoji) {
return(
<p className="card__content-emoji">{ emoji.getUnicode(this.props.emoji) }</p>
)
}
}

selectDelete = () => {
console.log(this.props.id, this.props.index)
this.props.deleteCard(this.props.id, this.props.index)
}
render() {
return (
<div className="card">
Card
<button type="button" className="card__delete" onClick={ this.selectDelete }>x</button>
<div className="card__content">
{ this.renderText() }
{ this.renderEmoji() }
</div>
</div>
)
}
}

Card.propTypes = {

text: PropTypes.string,
emoji: PropTypes.string,
index: PropTypes.number.isRequired,
id: PropTypes.number.isRequired,
deleteCard: PropTypes.func.isRequired
};

export default Card;
15 changes: 15 additions & 0 deletions src/components/Card.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';
import Card from './Card';

describe('Card', () => {
test('that it renders Card with shallow rendering', () => {
const wrapper = shallow(<Card />);

expect(wrapper).toMatchSnapshot();

wrapper.unmount();
});

});
6 changes: 6 additions & 0 deletions src/components/NewCardForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

.new-card-form {
width: 50%;
max-width: 350px;
min-width: 250px;
margin: auto;
padding-bottom: 4rem;
}
Expand Down Expand Up @@ -33,6 +35,10 @@
grid-row: auto;
}

.new-card-form__form-textarea{
height: 50px;
}

.new-card-form__form-button {
background-color: inherit;
border: 1px solid black;
Expand Down
74 changes: 74 additions & 0 deletions src/components/NewCardForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,77 @@ import emoji from 'emoji-dictionary';
import './NewCardForm.css';

const EMOJI_LIST = ["", "heart_eyes", "beer", "clap", "sparkling_heart", "heart_eyes_cat", "dog"]

class NewCardForm extends Component {
constructor() {
super();

this.state = {
text: '',
emoji: ''
};
}

static propTypes = {
submitNewCard: PropTypes.func.isRequired
};

onFieldChange = (event) => {
const fieldName = event.target.name;
const fieldValue = event.target.value;
const updateState = {};
updateState[fieldName] = fieldValue;
this.setState(updateState);
};

displayEmojiList = () => {
const options = EMOJI_LIST.map((keyword, index) => {
const unicode = emoji.getUnicode(keyword);
return <option key={ index } value={ keyword }>{ unicode }</option>
});
return options;
};

submitForm = (event) => {
event.preventDefault();

if (this.state.text || this.state.emoji ) {
this.props.submitNewCard({
text: this.state.text,
emoji: this.state.emoji
})
this.clearForm();
}
};

clearForm = () => {
this.setState({
text: '',
emoji: ''
})
}

seeState = () => {
console.log(this.state.text);
console.log(this.state.emoji);
}

render() {
return(
<section className="new-card-form">
<h3 className="new-card-form__header">Create a New Inspiration</h3>
<form onSubmit={ this.submitForm } className="new-card-form__form">
<label htmlFor="text" className="new-card-form__form-label">Message: </label>
<textarea name="text" value={this.state.text} onChange={ this.onFieldChange } className="new-card-form__form-textarea"/>
<label htmlFor="emoji" className="new-card-form__form-label">Emoji: </label>
<select name="emoji" value={this.state.emoji} onChange={ this.onFieldChange } className="new-card-form__form-select">
{ this.displayEmojiList()}
</select>
<input type="submit" value="create card" className="new-card-form__form-button"/>
</form>
</section>
)
}
}

export default NewCardForm;
Loading