forked from AdaGold/inspiration-board
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Karinna Iniguez - Inspiration Board - Octos #31
Open
karinnainiguez
wants to merge
13
commits into
Ada-C9:master
Choose a base branch
from
karinnainiguez:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
00633a3
npm install and add boiler plate to NewCardForm component
karinnainiguez bd272fc
add functionality for board to read hardcoded data and render card co…
karinnainiguez ab988a2
Add styles to return elements in card and board
karinnainiguez 6a7d2dc
Add helper methods to render text and emoji ONLY when provided, inste…
karinnainiguez 0173717
Refactor helper methods
karinnainiguez a266449
Add button to card. It does nothing yet
karinnainiguez f44008c
Add functionality for adding a new card to api and to state
karinnainiguez cd36a4b
Add functionality for the delete request in axios and remove from state
karinnainiguez 3651b19
Add Status file and make sure it renders in App. Not working yet
karinnainiguez c870785
add status
karinnainiguez 18a17a8
Refactor status component
karinnainiguez 83c20f5
Add drop down to change board
karinnainiguez a414570
adding test files
karinnainiguez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,66 @@ | ||
import React, { Component } from 'react'; | ||
import './App.css'; | ||
import Board from './components/Board'; | ||
import Status from './components/Status'; | ||
import BoardSelection from './components/BoardSelection'; | ||
|
||
class App extends Component { | ||
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`} | ||
/> | ||
</section> | ||
); | ||
} | ||
|
||
constructor(){ | ||
super(); | ||
|
||
this.state = { | ||
status: { | ||
message: "this is a message", | ||
type: "and a type" | ||
}, | ||
board: 'karinna', | ||
url: "https://inspiration-board.herokuapp.com/boards" | ||
} | ||
|
||
} | ||
|
||
updateStatus = (mess, typ) => { | ||
this.setState({ | ||
status: { | ||
message: mess, | ||
type: typ | ||
} | ||
}) | ||
} | ||
|
||
updateBoard = (name) => { | ||
this.setState({ | ||
board: name | ||
}); | ||
} | ||
|
||
|
||
render() { | ||
return ( | ||
<section> | ||
<header className="header"> | ||
<h1 className="header__h1"><span className="header__text">Inspiration Board</span></h1> | ||
</header> | ||
|
||
<BoardSelection | ||
updateBoardCallback={this.updateBoard} | ||
url={this.state.url} | ||
/> | ||
|
||
<Status | ||
message={this.state.status.message} | ||
type={this.state.status.type} | ||
/> | ||
|
||
<Board | ||
url={this.state.url} | ||
name={this.state.board} | ||
updateStatusCallback={this.updateStatus} | ||
/> | ||
</section> | ||
); | ||
} | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,125 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import axios from 'axios'; | ||
import emoji from 'emoji-dictionary'; | ||
|
||
|
||
import './Board.css'; | ||
import Card from './Card'; | ||
import NewCardForm from './NewCardForm'; | ||
import CARD_DATA from '../data/card-data.json'; | ||
|
||
|
||
class Board extends Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
cards: [], | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
Board | ||
</div> | ||
) | ||
} | ||
|
||
} | ||
static propTypes = { | ||
updateStatusCallback: PropTypes.func, | ||
url: PropTypes.string, | ||
name: PropTypes.string | ||
} | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
cards: [], | ||
}; | ||
|
||
} | ||
|
||
|
||
|
||
componentDidMount(){ | ||
axios.get(`${this.props.url}/${this.props.name}/cards`) | ||
.then((response) =>{ | ||
this.props.updateStatusCallback("Successfully loaded board", "success") | ||
|
||
this.setState({ | ||
cards: response.data | ||
}) | ||
}) | ||
.catch((error) => { | ||
this.props.updateStatusCallback(`Failed to load: ${error.message}`, "failure") | ||
}); | ||
|
||
} | ||
|
||
componentDidUpdate(prop, state) { | ||
if (prop.name !== this.props.name) { | ||
axios.get(`${this.props.url}/${prop.name}/cards`) | ||
.then((response) =>{ | ||
this.props.updateStatusCallback("Successfully loaded board", "success") | ||
|
||
Board.propTypes = { | ||
this.setState({ | ||
cards: response.data, | ||
name: prop.name | ||
}) | ||
}) | ||
.catch((error) => { | ||
this.props.updateStatusCallback(`Failed to load: ${error.message}`, "failure") | ||
}); | ||
} | ||
} | ||
|
||
addCard = (card) => { | ||
card.emoji = emoji.getName(card.emoji) | ||
|
||
axios.post(`${this.props.url}/${this.props.name}/cards`, card) | ||
|
||
.then((response) => { | ||
let updatedCards = this.state.cards; | ||
updatedCards.push({card}); | ||
this.setState({ cards: updatedCards }); | ||
this.props.updateStatusCallback(`Successfully added card`, "success") | ||
}) | ||
.catch((error) => { | ||
this.props.updateStatusCallback(`Failed to add Card: ${error.message}`, "failure") | ||
}); | ||
|
||
} | ||
|
||
deleteCard = (card) => { | ||
console.log(card); | ||
axios.delete(`${this.props.url}/${this.props.name}/cards/${card.props.id}`) | ||
.then((response) => { | ||
this.props.updateStatusCallback("Successfully Deleted Card", "success") | ||
let updatedCards = this.state.cards; | ||
updatedCards.splice(card.props.index,1) | ||
this.setState({ | ||
cards: updatedCards | ||
}) | ||
}) | ||
.catch((error) => { | ||
this.props.updateStatusCallback(`Failed to add card: ${error.message}`, "failure") | ||
}); | ||
} | ||
|
||
render() { | ||
|
||
const cardCollection = this.state.cards.map((obj, index) =>{ | ||
return <Card key={index} | ||
text={obj.card.text} | ||
emoji={obj.card.emoji} | ||
id={obj.card.id} | ||
index={index} | ||
deleteCardCallback={this.deleteCard} | ||
/> | ||
}); | ||
|
||
return ( | ||
<section> | ||
<div className="new-card-form"> | ||
<NewCardForm | ||
addCardCallback={this.addCard} | ||
/> | ||
</div> | ||
<div className="board"> | ||
{cardCollection} | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
} | ||
|
||
}; | ||
|
||
export default Board; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import Board from './Board'; | ||
import {shallow} from 'enzyme'; | ||
|
||
describe('Board', () => { | ||
|
||
test('shallow mount', () => { | ||
const board = shallow(<Board | ||
url="something" | ||
name="me" | ||
updateStatusCallback={() => {}} | ||
/>); | ||
expect(board).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.selection { | ||
font-family: 'Raleway', sans-serif; | ||
font-size: 1.25em; | ||
text-align: center; | ||
margin-left: 40%; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're adding the card, but not using the ID from the API.
Instead you should do: