bigbuffet-rw/app/soapbox/reducers/carousels.ts

39 lines
858 B
TypeScript
Raw Normal View History

2022-06-22 05:55:42 -07:00
import { AnyAction } from 'redux';
import {
CAROUSEL_AVATAR_REQUEST,
CAROUSEL_AVATAR_SUCCESS,
CAROUSEL_AVATAR_FAIL,
} from '../actions/carousels';
type Avatar = {
account_id: string
account_avatar: string
username: string
}
type CarouselsState = {
2022-06-23 06:26:13 -07:00
avatars: Avatar[]
2022-06-22 05:55:42 -07:00
isLoading: boolean
2022-06-23 06:26:13 -07:00
error: boolean
2022-06-22 05:55:42 -07:00
}
const initialState: CarouselsState = {
avatars: [],
isLoading: false,
2022-06-23 06:26:13 -07:00
error: false,
2022-06-22 05:55:42 -07:00
};
export default function rules(state: CarouselsState = initialState, action: AnyAction): CarouselsState {
switch (action.type) {
case CAROUSEL_AVATAR_REQUEST:
return { ...state, isLoading: true };
case CAROUSEL_AVATAR_SUCCESS:
return { ...state, isLoading: false, avatars: action.payload };
case CAROUSEL_AVATAR_FAIL:
2022-06-23 06:26:13 -07:00
return { ...state, isLoading: false, error: true };
2022-06-22 05:55:42 -07:00
default:
return state;
}
}