Progress
Albums almost done, group, chat moderation, photo, video page updates
This commit is contained in:
59
app/javascript/gabsocial/reducers/album_lists.js
Normal file
59
app/javascript/gabsocial/reducers/album_lists.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
Map as ImmutableMap,
|
||||
List as ImmutableList,
|
||||
} from 'immutable'
|
||||
import { me } from '../initial_state'
|
||||
import {
|
||||
ALBUMS_FETCH_REQUEST,
|
||||
ALBUMS_FETCH_SUCCESS,
|
||||
ALBUMS_FETCH_FAIL,
|
||||
ALBUMS_EXPAND_REQUEST,
|
||||
ALBUMS_EXPAND_SUCCESS,
|
||||
ALBUMS_EXPAND_FAIL,
|
||||
} from '../actions/albums'
|
||||
|
||||
const initialState = ImmutableMap({})
|
||||
|
||||
const setListFailed = (state, id) => {
|
||||
return state.setIn([id], ImmutableMap({
|
||||
next: null,
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
}))
|
||||
}
|
||||
|
||||
const normalizeList = (state, id, albums, next) => {
|
||||
return state.setIn([id], ImmutableMap({
|
||||
next,
|
||||
items: ImmutableList(albums.map(item => item.id)),
|
||||
isLoading: false,
|
||||
}))
|
||||
}
|
||||
|
||||
const appendToList = (state, id, albums, next) => {
|
||||
return state.updateIn([id], (map) => {
|
||||
return map
|
||||
.set('next', next)
|
||||
.set('isLoading', false)
|
||||
.update('items', (list) => {
|
||||
return list.concat(albums.map(item => item.id))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default function album_lists(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case ALBUMS_FETCH_REQUEST:
|
||||
case ALBUMS_EXPAND_REQUEST:
|
||||
return state.setIn([action.accountId, 'isLoading'], true)
|
||||
case ALBUMS_FETCH_SUCCESS:
|
||||
return normalizeList(state, action.accountId, action.albums, action.next)
|
||||
case ALBUMS_EXPAND_SUCCESS:
|
||||
return appendToList(state, action.accountId, action.albums, action.next)
|
||||
case ALBUMS_FETCH_FAIL:
|
||||
case ALBUMS_EXPAND_FAIL:
|
||||
return setListFailed(state, action.accountId)
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { loadingBarReducer } from 'react-redux-loading-bar'
|
||||
import accounts from './accounts'
|
||||
import accounts_counters from './accounts_counters'
|
||||
import albums from './albums'
|
||||
import album_lists from './album_lists'
|
||||
import bookmark_collections from './bookmark_collections'
|
||||
import chats from './chats'
|
||||
import chat_conversation_lists from './chat_conversation_lists'
|
||||
@@ -55,6 +56,8 @@ import user_lists from './user_lists'
|
||||
const reducers = {
|
||||
accounts,
|
||||
accounts_counters,
|
||||
// albums,
|
||||
// album_lists,
|
||||
bookmark_collections,
|
||||
chats,
|
||||
chat_conversation_lists,
|
||||
|
||||
Reference in New Issue
Block a user