From 926477fe4565522f47d19acac114d444780f04b1 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Wed, 5 Aug 2020 23:13:49 -0500 Subject: [PATCH] Added group_categories model file, redux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - group_categories model file, redux --- .../gabsocial/actions/group_categories.js | 27 +++++++++++++ .../gabsocial/reducers/group_categories.js | 39 +++++++++++++++++++ app/javascript/gabsocial/reducers/index.js | 2 + app/models/group_categories.rb | 12 ++++++ 4 files changed, 80 insertions(+) create mode 100644 app/javascript/gabsocial/actions/group_categories.js create mode 100644 app/javascript/gabsocial/reducers/group_categories.js create mode 100644 app/models/group_categories.rb diff --git a/app/javascript/gabsocial/actions/group_categories.js b/app/javascript/gabsocial/actions/group_categories.js new file mode 100644 index 00000000..242bc8fb --- /dev/null +++ b/app/javascript/gabsocial/actions/group_categories.js @@ -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, +}) \ No newline at end of file diff --git a/app/javascript/gabsocial/reducers/group_categories.js b/app/javascript/gabsocial/reducers/group_categories.js new file mode 100644 index 00000000..620c0b46 --- /dev/null +++ b/app/javascript/gabsocial/reducers/group_categories.js @@ -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 + } +} diff --git a/app/javascript/gabsocial/reducers/index.js b/app/javascript/gabsocial/reducers/index.js index 2879359a..11c97ff6 100644 --- a/app/javascript/gabsocial/reducers/index.js +++ b/app/javascript/gabsocial/reducers/index.js @@ -9,6 +9,7 @@ import custom_emojis from './custom_emojis' import filters from './filters' import gab_trends from './gab_trends' import groups from './groups' +import group_categories from './group_categories' import group_editor from './group_editor' import group_lists from './group_lists' import group_relationships from './group_relationships' @@ -51,6 +52,7 @@ const reducers = { filters, gab_trends, groups, + group_categories, group_editor, group_lists, group_relationships, diff --git a/app/models/group_categories.rb b/app/models/group_categories.rb new file mode 100644 index 00000000..d1273f5f --- /dev/null +++ b/app/models/group_categories.rb @@ -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