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

Semret Nicodimos - Inspiration-board - Edges #21

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ h1, h2 {

transform: rotate(-3deg) skew(-3deg);
}

.board-container {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}

.board-contents {

}
11 changes: 7 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ class App extends Component {
<header className="header">
<h1 className="header__h1"><span className="header__text">Inspiration Board</span></h1>
</header>
<Board
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
/>
<section className="board-container">
<Board
className="board-contents"
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
/>
</section>
</section>
);
}
Expand Down
76 changes: 72 additions & 4 deletions src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,90 @@ class Board extends Component {
super();

this.state = {
cards: [],
cards: []
};
}
componentDidMount() {
axios.get('https://inspiration-board.herokuapp.com/boards/Semret/cards')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a good way to use the props url and boardName that the App component passes in for this (you'd need to change the boardName that App defines)

.then((response) => {
this.setState({
cards: response.data
});
})
.catch((error) => {
this.setState({
error: error.message
});
})
}
deleteThisCard = (id) => {
console.log("a specific card is being deleted");
const updatedCards = this.state.cards
console.log(updatedCards.length);
axios.delete(`https://inspiration-board.herokuapp.com/cards/${id}`)
.then((response) => {

const filteredCards = updatedCards.filter(({card}) => card.id !== id )
console.log(filteredCards.length);
this.setState({
cards: filteredCards
});
})
.catch((error) => {
this.setState({
error: error.message
});
})
}

addNewCard = (newCard) => {
console.log("adding new card", newCard);
const updateCards = [...this.state.cards, newCard]

axios.post(`https://inspiration-board.herokuapp.com/boards/Semret/cards?text=${newCard.card.text}&emoji=${newCard.card.emoji}`)
.then((response) => {
this.setState({
cards: updateCards
});
})
.catch((error) => {
this.setState({
error: error.message
});
})
}

render() {
const emoji = require("emoji-dictionary");

const messages = this.state.cards

const messageCollection = messages.map((message, i) => {
return <Card
key={i}
id={message.card.id}
text={message.card.text}
emoji={emoji.getUnicode(`${message.card.emoji}`)}
deleteCardCallback={this.deleteThisCard}
/>
});
return (
<div>
Board
<section className="form-section">
<NewCardForm
addNewCardToCollection={this.addNewCard}
/>
</section>
<section className="board">
{messageCollection}
</section>
</div>
)
}

}

Board.propTypes = {

cards: PropTypes.array,
};

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


describe('Board', () => {
test('that it matches an existing snapshot for deleting', () => {
const wrapper = shallow( <Board deleteThisCard={() => {} } />);
expect(wrapper).toMatchSnapshot();
});

test('that it matches an existing snapshot for adding', () => {
const wrapper = shallow( <Board addNewCard={() => {} } />);
expect(wrapper).toMatchSnapshot();
});
});
9 changes: 7 additions & 2 deletions src/components/Card.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
border-radius: 5px;

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

.card__content {
grid-column-start: 2;
grid-row-start: 2;

display: flex;
flex-direction: column;
Expand All @@ -42,6 +44,9 @@
}

.card__delete {
align-self: start;
grid-column-start: 3;
grid-row-start: 1;
justify-self: end;

font-family: 'Permanent Marker', Helvetica, sans-serif;
}
24 changes: 22 additions & 2 deletions src/components/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,37 @@ import emoji from 'emoji-dictionary';
import './Card.css';

class Card extends Component {

deleteCardClickHandler = (event) => {
console.log("The delete button was clicked");

this.props.deleteCardCallback(this.props.id);
}
render() {
return (
<div className="card">
Card
<section className="card__content">
<div className="card__content-text">
{this.props.text}
</div>
<div className="card__content-emoji">
{this.props.emoji}
</div>
</section>
<div className="card__delete">
<button
onClick={ this.deleteCardClickHandler }>
Delete
</button>
</div>
</div>
)
}
}

Card.propTypes = {

text: PropTypes.string.isRequired,
emoji: PropTypes.string,
};

export default Card;
10 changes: 9 additions & 1 deletion src/components/NewCardForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.new-card-form__header {
text-align: center;
text-transform: uppercase;
row-span: all;
}

.new-card-form__form {
Expand All @@ -34,7 +35,14 @@
}

.new-card-form__form-button {
background-color: inherit;
background-color: seashell;
border: 1px solid black;
font-size: 1em;
}

.form {
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: auto;
border: solid 2px red;
}
87 changes: 86 additions & 1 deletion src/components/NewCardForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,89 @@ import PropTypes from 'prop-types';
import emoji from 'emoji-dictionary';
import './NewCardForm.css';

const EMOJI_LIST = ["", "heart_eyes", "beer", "clap", "sparkling_heart", "heart_eyes_cat", "dog"]
const EMOJI_LIST = ["", "heart_eyes", "beer", "clap", "sparkling_heart", "heart_eyes_cat", "dog", "umbrella", "tada", "kissing_heart", "muscle", "brain", "sun_with_face", "spades", "gift_heart", "dog2", "trophy", "cocktail"]


class NewCardForm extends Component {

constructor(props) {
super(props);

this.state = {
text: "",
emoji: "",
}
}
onInputChange = (event) => {
console.log("I'm in the onInputChange funtion");

const field = event.target.name;
const value = event.target.value;

const newState = {};
newState[field] = value;
this.setState(newState);
}

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

const newCard = {
card: {
text: this.state.text,
emoji: this.state.emoji,
}

};

this.setState({
text: '',
emoji: '',
});

console.log("created a new card from input", newCard);
this.props.addNewCardToCollection(newCard);
}

emojiSelection = () => {
return EMOJI_LIST.map((item, i) => {
return <option
key={i}
value={item}>{emoji.getUnicode(item)}</option>
});
}

render() {
return (
<div className="new-card-form">
<div className="new-card-form__header">
<h2>New card Submission Form</h2>
</div>
<form className="new-card-form__form"
onSubmit={this.onFormSubmit}>
<label htmlFor="text">Your Message</label>
<textarea
className="new-card-form__form-textarea"
name="text"
value={this.state.text}
onChange={this.onInputChange}/>
<label htmlFor="emoji"> Emoji</label>
<select
className="new-card-form__form-select"
name="emoji"
value={this.state.emoji}
onChange={this.onInputChange}>
{this.emojiSelection()}
</select>
<input
type="submit"
value="Submit Message"
className="new-card-form__form-button"
/>
</form>
</div>
);
}
}

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


describe('NewCardForm', () => {
test('that it matches an existing snapshot for adding', () => {

const wrapper = shallow( <NewCardForm addNewCardToCollection={() => {} } />);

expect(wrapper).toMatchSnapshot();
});

test('that it matches an existing snapshot for delete', () => {

const wrapper = shallow( <NewCardForm deleteCardCallback={() => {} } />);

expect(wrapper).toMatchSnapshot();
});

test('that it matches an existing snapshot for delete', () => {

const wrapper = shallow( <NewCardForm deleteCardCallback={() => {} } />);

expect(wrapper).toMatchSnapshot();
});
});
Loading