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

Luxi Lindsey - inspiration-board - Octos #21

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fd872fc
Copied repo and installed npm. Updated the Card and Board components …
Lindseyls Jun 11, 2018
1d7b438
Updated the Crad.js to show the emoji correctly
Lindseyls Jun 11, 2018
8c2493e
Added the styling to Board and Card.js
Lindseyls Jun 11, 2018
d5d0471
Updated the Board.js to render the URL using axios
Lindseyls Jun 11, 2018
718387d
Created Status.js. Updated App.js and Board.js for rendering updated …
Lindseyls Jun 12, 2018
53ff17a
Updated the NewCardForm.js to have text input box and a dropdown menu…
Lindseyls Jun 12, 2018
e503775
Updated the CSS for Status and NewCardForm. Modified addCard function…
Lindseyls Jun 12, 2018
d0de30b
Updated the CSS for card and added a delete button
Lindseyls Jun 12, 2018
6ccb23a
Working on the delete callback in the board and card components
Lindseyls Jun 12, 2018
f2dafdd
Updated the deleteCard function with axios to successfully delete cards
Lindseyls Jun 13, 2018
a812d81
Installed enzyme to json and updated package.json and setupTests.js. …
Lindseyls Jun 13, 2018
9d152cf
Created and updated the test.js files for NewCardForm, Board, and Car…
Lindseyls Jun 13, 2018
db37898
Updated the CSS a little bit on the form, created test for Status.js …
Lindseyls Jun 14, 2018
333003e
Updated the NewCardForm testing with the test that I know is not need…
Lindseyls Jun 14, 2018
55573d9
Changed the Card component into a functional stateless component, upd…
Lindseyls Jun 15, 2018
b2db4ea
Updated the emoji list again with awesome emojis and reran the test t…
Lindseyls Jun 15, 2018
1d57942
Set up github pages.
Lindseyls Nov 29, 2018
4a1abfc
Updated the api endpoint for the board. Also, updated the link for de…
Lindseyls Dec 27, 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
37 changes: 23 additions & 14 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion 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"
},
"homepage": "http://adagold.github.io/inspiration-board"
"homepage": "https://lindseyls.github.io/inspiration-board/",
"jest": {
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
}
39 changes: 35 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
import React, { Component } from 'react';
import './App.css';

import Board from './components/Board';
import Status from './components/Status';

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

this.state = {
status: {
messasge: 'loaded the page',
type: 'success'
}
}
}

updateStatus = (message, type) => {
this.setState({
status: {
message: message,
type: type
}
})
}

render() {

return (
<section>
<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`}
/>

<Status
message={this.state.status.message}
type={this.state.status.type}
/>

<Board
updateStatusCallback={this.updateStatus}
// url="https://inspiration-board.herokuapp.com/boards/"
// boardName={`Luxi-Lindsey`}
/>

</section>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Board.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
.validation-errors-display {
text-align: center;
margin-bottom: 2em;
font-family: 'Raleway', sans-serif;
font-size: 1.25em;
}

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

const CARDS_URL = "https://inspiration-board.herokuapp.com/boards/Luxi/cards";

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

componentDidMount() {
console.log('In componentsDidMount');

this.props.updateStatusCallback('Loading...', 'success');

axios.get(CARDS_URL)
.then((response) => {
console.log('Success!');

this.props.updateStatusCallback('Successfully loaded all cards!', 'success');

const cards = response.data;
this.setState({ cards: cards });
})
.catch((error) => {
// console.log('Error :(');
// console.log(error);

this.props.updateStatusCallback(error.message, 'error');
});
}

addCard = (cardInfo) => {
console.log('In addCard');

axios.post(CARDS_URL, cardInfo)
.then((response) => {

this.props.updateStatusCallback(`Successfully added card ${ response.data.card.id }!`, 'success');

let updateCards = this.state.cards;
updateCards.push(response.data);

this.setState({ cards: updateCards });
})
.catch((error) => {
console.log(error);

this.props.updateStatusCallback(`${error.message} - failed to add new card`, 'error');
});
}

deleteCard = (index, id) => {
console.log('In deleteCard')

let updateCards = this.state.cards;
updateCards.splice(index, 1)
this.setState({ cards: updateCards });

const DELETE_URL = `https://inspiration-board.herokuapp.com/cards/${id}`

axios.delete(DELETE_URL)
.then((response) => {
console.log('Deleted!');
console.log(response.data);

this.props.updateStatusCallback('Successfully deleted card!', 'success');

})
.catch((error) => {
// console.log('Error :(');
// console.log(error);

this.props.updateStatusCallback(error.message, 'error');
});
}

render() {

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

return (
<div>
Board
<section>
<NewCardForm addCardCallback={this.addCard}/>

<div className="board">
{ cards }
</div>
)
</section>
);
}

}

Board.propTypes = {

// cards: PropTypes.array.isRequired,
updateStatusCallback: PropTypes.func.isRequired
};

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

describe ('Board', () => {
test('deep mount', () => {
const boardComponent = mount(
<Board updateStatusCallback={() => {} } />
);

expect(boardComponent).toMatchSnapshot();

boardComponent.unmount();
});

test('shallow mount', () => {
const boardComponent = shallow(
<Board updateStatusCallback={() => {} } />
);

expect(boardComponent).toMatchSnapshot();

});
});
8 changes: 8 additions & 0 deletions src/components/Card.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@
.card__delete {
align-self: start;
font-family: 'Permanent Marker', Helvetica, sans-serif;
background-color: inherit;
border: none;
font-size: 1em;
}

.card__delete:hover {
font-size: 2rem;
color: orange;
}
37 changes: 28 additions & 9 deletions src/components/Card.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
import React, { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import emoji from 'emoji-dictionary';

import './Card.css';

class Card extends Component {
render() {
return (
<div className="card">
Card
</div>
)
const Card = (props) => {

let onClickHandler = () => {
props.deleteCallback(props.index, props.id);
}

return (
<section className="card">
<button
className="card__delete"
onClick={ onClickHandler }>X</button>

<div className="card__content">
<h1 className="card__content-text">
{props.text}
</h1>

<h1 className="card__content-emoji">
{emoji.getUnicode(`${props.emoji}`)}
</h1>
</div>
</section>
)
}

Card.propTypes = {

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

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

describe ('Card', () => {
test('shallow mount', () => {
const cardComponent = shallow(
<Card deleteCallback={()=> {} } />
);

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