Add selected album actions and reducers
Default state is an empty object ({}).
SELECT_ALBUM will update state with an album.
UNSELECT_ALBUM resets state to default state.
This commit is contained in:
parent
c11b1d4653
commit
60e70f4b34
3 changed files with 28 additions and 1 deletions
|
|
@ -2,6 +2,8 @@ export const SET_VISIBILITY_FILTER = 'SET_VISIBILITY_FILTER';
|
|||
export const SET_SORT_KEY = 'SET_SORT_KEY';
|
||||
export const LOAD_ALBUMS = 'LOAD_ALBUMS';
|
||||
export const LOAD_ALBUMS_OK = 'LOAD_ALBUMS_OK';
|
||||
export const SELECT_ALBUM = 'SELECT_ALBUM';
|
||||
export const UNSELECT_ALBUM = 'UNSELECT_ALBUM';
|
||||
|
||||
export const setVisibilityFilter = filter => ({
|
||||
type: SET_VISIBILITY_FILTER,
|
||||
|
|
@ -22,4 +24,15 @@ export const albumsLoadedOk = albums => ({
|
|||
payload: {
|
||||
albums,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
export const selectAlbum = album => ({
|
||||
type: SELECT_ALBUM,
|
||||
payload: {
|
||||
album
|
||||
},
|
||||
});
|
||||
|
||||
export const unselectAlbum = () => ({
|
||||
type: UNSELECT_ALBUM,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ import { combineReducers } from 'redux';
|
|||
import albums from './albums';
|
||||
import visibilityFilter from './visibility-filter';
|
||||
import sortKey from "./sort-key";
|
||||
import selectedAlbum from './selected-album';
|
||||
|
||||
export default combineReducers({
|
||||
albums,
|
||||
visibilityFilter,
|
||||
sortKey,
|
||||
selectedAlbum,
|
||||
});
|
||||
|
|
|
|||
12
src/reducers/selected-album.js
Normal file
12
src/reducers/selected-album.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { SELECT_ALBUM, UNSELECT_ALBUM } from '../actions';
|
||||
|
||||
export default (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case SELECT_ALBUM:
|
||||
return action.payload.album;
|
||||
case UNSELECT_ALBUM:
|
||||
return {};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue