2020-05-04 19:44:37 +01:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'
|
2020-06-04 23:48:24 +01:00
|
|
|
import {
|
|
|
|
GROUPS_FETCH_REQUEST,
|
|
|
|
GROUPS_FETCH_SUCCESS,
|
|
|
|
GROUPS_FETCH_FAIL,
|
2020-07-25 03:41:05 +01:00
|
|
|
GROUP_SORT,
|
2020-08-06 04:59:12 +01:00
|
|
|
GROUP_TIMELINE_SORT,
|
|
|
|
GROUP_TIMELINE_TOP_SORT,
|
2020-09-11 23:27:00 +01:00
|
|
|
GROUP_CHECK_PASSWORD_RESET,
|
|
|
|
GROUP_CHECK_PASSWORD_REQUEST,
|
|
|
|
GROUP_CHECK_PASSWORD_SUCCESS,
|
|
|
|
GROUP_CHECK_PASSWORD_FAIL,
|
2020-09-14 23:12:45 +01:00
|
|
|
GROUPS_BY_CATEGORY_FETCH_REQUEST,
|
|
|
|
GROUPS_BY_CATEGORY_FETCH_SUCCESS,
|
|
|
|
GROUPS_BY_CATEGORY_FETCH_FAIL,
|
|
|
|
GROUPS_BY_TAG_FETCH_REQUEST,
|
|
|
|
GROUPS_BY_TAG_FETCH_SUCCESS,
|
|
|
|
GROUPS_BY_TAG_FETCH_FAIL,
|
2020-12-21 00:28:32 +00:00
|
|
|
GROUP_MEMBERS_SEARCH_SUCCESS,
|
|
|
|
CLEAR_GROUP_MEMBERS_SEARCH,
|
|
|
|
GROUP_REMOVED_ACCOUNTS_SEARCH_SUCCESS,
|
|
|
|
CLEAR_GROUP_REMOVED_ACCOUNTS_SEARCH,
|
2020-06-04 23:48:24 +01:00
|
|
|
} from '../actions/groups'
|
2020-08-06 04:59:12 +01:00
|
|
|
import {
|
|
|
|
GROUP_TIMELINE_SORTING_TYPE_TOP,
|
2020-08-07 23:28:10 +01:00
|
|
|
GROUP_TIMELINE_SORTING_TYPE_NEWEST,
|
2020-08-06 04:59:12 +01:00
|
|
|
GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_TODAY,
|
2020-11-25 21:22:37 +00:00
|
|
|
ACCEPTED_GROUP_TABS,
|
2020-08-06 04:59:12 +01:00
|
|
|
} from '../constants'
|
2020-09-14 23:12:45 +01:00
|
|
|
import slugify from '../utils/slugify'
|
2020-06-04 23:48:24 +01:00
|
|
|
|
2019-07-15 14:47:05 +01:00
|
|
|
const initialState = ImmutableMap({
|
2020-08-07 23:28:10 +01:00
|
|
|
sortByValue: GROUP_TIMELINE_SORTING_TYPE_NEWEST,
|
|
|
|
sortByTopValue: '',
|
2020-09-11 23:27:00 +01:00
|
|
|
passwordCheck: ImmutableMap(),
|
2020-06-04 23:48:24 +01:00
|
|
|
new: ImmutableMap({
|
2020-06-04 23:52:26 +01:00
|
|
|
isFetched: false,
|
|
|
|
isLoading: false,
|
2020-06-04 23:48:24 +01:00
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
|
|
|
featured: ImmutableMap({
|
2020-06-04 23:52:26 +01:00
|
|
|
isFetched: false,
|
|
|
|
isLoading: false,
|
2020-06-04 23:48:24 +01:00
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
|
|
|
member: ImmutableMap({
|
2020-06-04 23:52:26 +01:00
|
|
|
isFetched: false,
|
|
|
|
isLoading: false,
|
2020-06-04 23:48:24 +01:00
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
|
|
|
admin: ImmutableMap({
|
2020-06-04 23:52:26 +01:00
|
|
|
isFetched: false,
|
|
|
|
isLoading: false,
|
2020-06-04 23:48:24 +01:00
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
2020-09-14 23:12:45 +01:00
|
|
|
by_category: ImmutableMap(),
|
|
|
|
by_tag: ImmutableMap(),
|
2020-12-21 00:28:32 +00:00
|
|
|
member_search_accounts: ImmutableList(),
|
|
|
|
removed_search_accounts: ImmutableList(),
|
2020-05-04 19:44:37 +01:00
|
|
|
})
|
2019-07-15 14:47:05 +01:00
|
|
|
|
|
|
|
export default function groupLists(state = initialState, action) {
|
2020-08-07 05:19:18 +01:00
|
|
|
// if (tabs.indexOf(action.tab) === -1) return state
|
|
|
|
|
2019-07-15 14:47:05 +01:00
|
|
|
switch(action.type) {
|
2020-06-04 23:48:24 +01:00
|
|
|
case GROUPS_FETCH_REQUEST:
|
|
|
|
return state.withMutations((mutable) => {
|
2020-06-04 23:52:26 +01:00
|
|
|
mutable.setIn([action.tab, 'isLoading'], true)
|
2020-06-04 23:48:24 +01:00
|
|
|
});
|
2019-07-15 14:47:05 +01:00
|
|
|
case GROUPS_FETCH_SUCCESS:
|
2020-06-04 23:48:24 +01:00
|
|
|
return state.withMutations((mutable) => {
|
2020-07-14 06:22:15 +01:00
|
|
|
let list = ImmutableList(action.groups.map(item => item.id))
|
|
|
|
if (action.tab === 'featured') list = list.sortBy(Math.random)
|
|
|
|
mutable.setIn([action.tab, 'items'], list)
|
2020-06-04 23:52:26 +01:00
|
|
|
mutable.setIn([action.tab, 'isLoading'], false)
|
|
|
|
mutable.setIn([action.tab, 'isFetched'], true)
|
2020-06-04 23:48:24 +01:00
|
|
|
})
|
|
|
|
case GROUPS_FETCH_FAIL:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn([action.tab, 'items'], ImmutableList())
|
2020-06-04 23:52:26 +01:00
|
|
|
mutable.setIn([action.tab, 'isLoading'], false)
|
|
|
|
mutable.setIn([action.tab, 'isFetched'], true)
|
2020-06-04 23:48:24 +01:00
|
|
|
})
|
2020-07-25 03:41:05 +01:00
|
|
|
case GROUP_SORT:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn([action.tab, 'items'], ImmutableList(action.groupIds))
|
|
|
|
})
|
2020-08-06 04:59:12 +01:00
|
|
|
case GROUP_TIMELINE_SORT:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.set('sortByValue', action.sortValue)
|
|
|
|
if (action.sortValue === GROUP_TIMELINE_SORTING_TYPE_TOP) {
|
|
|
|
mutable.set('sortByTopValue', GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_TODAY)
|
|
|
|
} else {
|
|
|
|
mutable.set('sortByTopValue', '')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
case GROUP_TIMELINE_TOP_SORT:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.set('sortByValue', GROUP_TIMELINE_SORTING_TYPE_TOP)
|
|
|
|
mutable.set('sortByTopValue', action.sortValue)
|
|
|
|
})
|
2020-09-11 23:27:00 +01:00
|
|
|
|
|
|
|
case GROUP_CHECK_PASSWORD_RESET:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn(['passwordCheck', 'isError'], false)
|
|
|
|
mutable.setIn(['passwordCheck', 'isSuccess'], false)
|
|
|
|
mutable.setIn(['passwordCheck', 'isLoading'], false)
|
|
|
|
})
|
|
|
|
case GROUP_CHECK_PASSWORD_REQUEST:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn(['passwordCheck', 'isError'], false)
|
|
|
|
mutable.setIn(['passwordCheck', 'isSuccess'], false)
|
|
|
|
mutable.setIn(['passwordCheck', 'isLoading'], true)
|
|
|
|
})
|
|
|
|
case GROUP_CHECK_PASSWORD_SUCCESS:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn(['passwordCheck', 'isError'], false)
|
|
|
|
mutable.setIn(['passwordCheck', 'isSuccess'], true)
|
|
|
|
mutable.setIn(['passwordCheck', 'isLoading'], false)
|
|
|
|
})
|
|
|
|
case GROUP_CHECK_PASSWORD_FAIL:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn(['passwordCheck', 'isError'], true)
|
|
|
|
mutable.setIn(['passwordCheck', 'isSuccess'], false)
|
|
|
|
mutable.setIn(['passwordCheck', 'isLoading'], false)
|
|
|
|
})
|
|
|
|
|
2020-09-14 23:12:45 +01:00
|
|
|
case GROUPS_BY_CATEGORY_FETCH_REQUEST:
|
|
|
|
return state.setIn(['by_category', slugify(action.category), 'isLoading'], true)
|
|
|
|
case GROUPS_BY_CATEGORY_FETCH_SUCCESS:
|
|
|
|
return state.setIn(['by_category', slugify(action.category)], ImmutableMap({
|
|
|
|
items: ImmutableList(action.groups.map(item => item.id)),
|
|
|
|
isLoading: false,
|
|
|
|
}))
|
|
|
|
case GROUPS_BY_CATEGORY_FETCH_FAIL:
|
|
|
|
return state.setIn(['by_category', slugify(action.category)], ImmutableMap({
|
|
|
|
items: ImmutableList(),
|
|
|
|
isLoading: false,
|
|
|
|
}))
|
|
|
|
|
|
|
|
case GROUPS_BY_TAG_FETCH_REQUEST:
|
|
|
|
return state.setIn(['by_tag', slugify(action.tag), 'isLoading'], true)
|
|
|
|
case GROUPS_BY_TAG_FETCH_SUCCESS:
|
|
|
|
return state.setIn(['by_tag', slugify(action.tag)], ImmutableMap({
|
|
|
|
items: ImmutableList(action.groups.map(item => item.id)),
|
|
|
|
isLoading: false,
|
|
|
|
}))
|
|
|
|
case GROUPS_BY_TAG_FETCH_FAIL:
|
|
|
|
return state.setIn(['by_tag', slugify(action.tag)], ImmutableMap({
|
|
|
|
items: ImmutableList(),
|
|
|
|
isLoading: false,
|
|
|
|
}))
|
2020-12-21 00:28:32 +00:00
|
|
|
case GROUP_MEMBERS_SEARCH_SUCCESS:
|
|
|
|
return state.set('member_search_accounts', ImmutableList(action.accounts.map((item) => item.id)))
|
|
|
|
case CLEAR_GROUP_MEMBERS_SEARCH:
|
|
|
|
return state.set('member_search_accounts', ImmutableList())
|
|
|
|
case GROUP_REMOVED_ACCOUNTS_SEARCH_SUCCESS:
|
|
|
|
return state.set('removed_search_accounts', ImmutableList(action.accounts.map((item) => item.id)))
|
|
|
|
case CLEAR_GROUP_REMOVED_ACCOUNTS_SEARCH:
|
|
|
|
return state.set('removed_search_accounts', ImmutableList())
|
2019-07-15 14:47:05 +01:00
|
|
|
default:
|
2020-05-04 19:44:37 +01:00
|
|
|
return state
|
2019-07-15 14:47:05 +01:00
|
|
|
}
|
2020-05-04 19:44:37 +01:00
|
|
|
}
|
2020-09-14 23:12:45 +01:00
|
|
|
|