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:
Anders Ytterström 2019-04-23 14:58:20 +02:00
parent c11b1d4653
commit 60e70f4b34
3 changed files with 28 additions and 1 deletions

View file

@ -2,6 +2,8 @@ export const SET_VISIBILITY_FILTER = 'SET_VISIBILITY_FILTER';
export const SET_SORT_KEY = 'SET_SORT_KEY'; export const SET_SORT_KEY = 'SET_SORT_KEY';
export const LOAD_ALBUMS = 'LOAD_ALBUMS'; export const LOAD_ALBUMS = 'LOAD_ALBUMS';
export const LOAD_ALBUMS_OK = 'LOAD_ALBUMS_OK'; export const LOAD_ALBUMS_OK = 'LOAD_ALBUMS_OK';
export const SELECT_ALBUM = 'SELECT_ALBUM';
export const UNSELECT_ALBUM = 'UNSELECT_ALBUM';
export const setVisibilityFilter = filter => ({ export const setVisibilityFilter = filter => ({
type: SET_VISIBILITY_FILTER, type: SET_VISIBILITY_FILTER,
@ -22,4 +24,15 @@ export const albumsLoadedOk = albums => ({
payload: { payload: {
albums, albums,
}, },
}) })
export const selectAlbum = album => ({
type: SELECT_ALBUM,
payload: {
album
},
});
export const unselectAlbum = () => ({
type: UNSELECT_ALBUM,
});

View file

@ -2,9 +2,11 @@ import { combineReducers } from 'redux';
import albums from './albums'; import albums from './albums';
import visibilityFilter from './visibility-filter'; import visibilityFilter from './visibility-filter';
import sortKey from "./sort-key"; import sortKey from "./sort-key";
import selectedAlbum from './selected-album';
export default combineReducers({ export default combineReducers({
albums, albums,
visibilityFilter, visibilityFilter,
sortKey, sortKey,
selectedAlbum,
}); });

View 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;
}
};