-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
279cd6b
commit 6c3c790
Showing
5 changed files
with
98 additions
and
72 deletions.
There are no files selected for viewing
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
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,65 @@ | ||
import { | ||
LOAD_DECKS, | ||
NEW_DECK, | ||
ADD_CARD, | ||
DELETE_DECK, | ||
DELETE_CARD | ||
} from '../actions'; | ||
|
||
function decks(state = {}, action) { | ||
const { type } = action; | ||
const decks = state; | ||
|
||
switch (type) { | ||
case LOAD_DECKS: { | ||
const decks = action.decks; | ||
|
||
return decks; | ||
} | ||
case NEW_DECK: { | ||
const deck = action.deck; | ||
const freshDecks = { | ||
...decks, | ||
[deck.name]: deck | ||
} | ||
|
||
return freshDecks; | ||
} | ||
case DELETE_DECK: { | ||
const { deckKey } = action; | ||
|
||
const refreshedDecks = Object.assign({}, decks); | ||
delete refreshedDecks[deckKey]; | ||
return refreshedDecks; | ||
} | ||
case ADD_CARD: { | ||
const { card, deckKey } = action; | ||
const freshDeck = decks[deckKey]; | ||
|
||
freshDeck.cards.push(card); | ||
|
||
const freshDecks = { | ||
...decks, | ||
[deckKey]: freshDeck | ||
} | ||
return freshDecks; | ||
} | ||
case DELETE_CARD: { | ||
const { deckKey, cardName } = action; | ||
const freshDecks = { | ||
...decks, | ||
[deckKey]: { | ||
...decks[deckKey], | ||
cards: decks[deckKey].cards.filter(card => card.question !== cardName) | ||
} | ||
}; | ||
|
||
return freshDecks; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} | ||
|
||
export default decks; |
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,72 +1,6 @@ | ||
import { | ||
LOAD_DECKS, | ||
NEW_DECK, | ||
ADD_CARD, | ||
DELETE_DECK, | ||
DELETE_CARD | ||
} from '../actions'; | ||
import { combineReducers } from 'redux'; | ||
|
||
function decks(state = { decks: {} }, action) { | ||
const { type } = action; | ||
const { decks } = state; | ||
import decks from './decks'; | ||
import scores from './scores'; | ||
|
||
switch (type) { | ||
case LOAD_DECKS: { | ||
const decks = action.decks; | ||
|
||
return { | ||
decks | ||
}; | ||
} | ||
case NEW_DECK: { | ||
const deck = action.deck; | ||
const freshDecks = { | ||
...decks, | ||
[deck.name]: deck | ||
} | ||
|
||
return { | ||
decks: freshDecks | ||
} | ||
} | ||
case DELETE_DECK: { | ||
const { deckKey } = action; | ||
delete decks[deckKey]; | ||
|
||
const refreshedDecks = decks; | ||
return { | ||
decks: refreshedDecks | ||
} | ||
} | ||
case ADD_CARD: { | ||
const { card, deckKey } = action; | ||
const freshDeck = decks[deckKey]; | ||
|
||
freshDeck.cards.push(card); | ||
|
||
const freshDecks = { | ||
...decks, | ||
[deckKey]: freshDeck | ||
} | ||
return { | ||
decks: freshDecks | ||
} | ||
|
||
} | ||
case DELETE_CARD: { | ||
const { deckKey, cardName } = action; | ||
const freshDecks = decks; | ||
|
||
freshDecks[deckKey].cards = freshDecks[deckKey].cards.filter(card => card.question !== cardName); | ||
|
||
return { | ||
decks: freshDecks | ||
} | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} | ||
|
||
export default decks; | ||
export default combineReducers({ decks, scores }); |
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,17 @@ | ||
import { UPDATE_SCORE } from '../actions'; | ||
|
||
function scores(state = [], action) { | ||
const { type } = action; | ||
const scores = state; | ||
|
||
switch (type) { | ||
case UPDATE_SCORE: { | ||
return action.scores; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} | ||
|
||
export default scores; |