Added group_categories model file, redux
• Added: - group_categories model file, redux
This commit is contained in:
parent
c20f7adf6a
commit
926477fe45
|
@ -0,0 +1,27 @@
|
||||||
|
import api from '../api'
|
||||||
|
|
||||||
|
export const GROUP_CATEGORIES_FETCH_REQUEST = 'GROUP_CATEGORIES_FETCH_REQUEST'
|
||||||
|
export const GROUP_CATEGORIES_FETCH_SUCCESS = 'GROUP_CATEGORIES_FETCH_SUCCESS'
|
||||||
|
export const GROUP_CATEGORIES_FETCH_FAIL = 'GROUP_CATEGORIES_FETCH_FAIL'
|
||||||
|
|
||||||
|
export const fetchGroupCategories = () => (dispatch, getState) => {
|
||||||
|
dispatch(fetchGroupCategoriesRequest())
|
||||||
|
|
||||||
|
api(getState).get('/api/v1/group_categories')
|
||||||
|
.then(({ data }) => dispatch(fetchGroupCategoriesSuccess(data)))
|
||||||
|
.catch(err => dispatch(fetchGroupCategoriesFail(err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fetchGroupCategoriesRequest = () => ({
|
||||||
|
type: GROUP_CATEGORIES_FETCH_REQUEST,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const fetchGroupCategoriesSuccess = (categories) => ({
|
||||||
|
type: GROUP_CATEGORIES_FETCH_SUCCESS,
|
||||||
|
categories,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const fetchGroupCategoriesFail = (error) => ({
|
||||||
|
type: GROUP_CATEGORIES_FETCH_FAIL,
|
||||||
|
error,
|
||||||
|
})
|
|
@ -0,0 +1,39 @@
|
||||||
|
import {
|
||||||
|
GROUP_CATEGORIES_FETCH_REQUEST,
|
||||||
|
GROUP_CATEGORIES_FETCH_SUCCESS,
|
||||||
|
GROUP_CATEGORIES_FETCH_FAIL,
|
||||||
|
} from '../actions/group_categories'
|
||||||
|
import {
|
||||||
|
Map as ImmutableMap,
|
||||||
|
List as ImmutableList,
|
||||||
|
fromJS,
|
||||||
|
} from 'immutable'
|
||||||
|
|
||||||
|
const initialState = ImmutableMap({
|
||||||
|
items: ImmutableList(),
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default function groupCategoriesReducer(state = initialState, action) {
|
||||||
|
switch(action.type) {
|
||||||
|
case GROUP_CATEGORIES_FETCH_REQUEST:
|
||||||
|
return state.withMutations((map) => {
|
||||||
|
map.set('isLoading', true)
|
||||||
|
map.set('isError', false)
|
||||||
|
})
|
||||||
|
case GROUP_CATEGORIES_FETCH_SUCCESS:
|
||||||
|
return state.withMutations((map) => {
|
||||||
|
map.set('items', fromJS(action.categories.map((x => x))))
|
||||||
|
map.set('isLoading', false)
|
||||||
|
map.set('isError', false)
|
||||||
|
})
|
||||||
|
case GROUP_CATEGORIES_FETCH_FAIL:
|
||||||
|
return state.withMutations((map) => {
|
||||||
|
map.set('isLoading', false)
|
||||||
|
map.set('isError', true)
|
||||||
|
})
|
||||||
|
default:
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import custom_emojis from './custom_emojis'
|
||||||
import filters from './filters'
|
import filters from './filters'
|
||||||
import gab_trends from './gab_trends'
|
import gab_trends from './gab_trends'
|
||||||
import groups from './groups'
|
import groups from './groups'
|
||||||
|
import group_categories from './group_categories'
|
||||||
import group_editor from './group_editor'
|
import group_editor from './group_editor'
|
||||||
import group_lists from './group_lists'
|
import group_lists from './group_lists'
|
||||||
import group_relationships from './group_relationships'
|
import group_relationships from './group_relationships'
|
||||||
|
@ -51,6 +52,7 @@ const reducers = {
|
||||||
filters,
|
filters,
|
||||||
gab_trends,
|
gab_trends,
|
||||||
groups,
|
groups,
|
||||||
|
group_categories,
|
||||||
group_editor,
|
group_editor,
|
||||||
group_lists,
|
group_lists,
|
||||||
group_relationships,
|
group_relationships,
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: group_categories
|
||||||
|
#
|
||||||
|
# id :bigint(8) not null, primary key
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# text :string not null
|
||||||
|
#
|
||||||
|
|
||||||
|
class GroupCategories < ApplicationRecord
|
||||||
|
end
|
Loading…
Reference in New Issue