2020-05-03 06:22:49 +01:00
|
|
|
import { SETTING_CHANGE, SETTING_SAVE } from '../actions/settings'
|
|
|
|
import { STORE_HYDRATE } from '../actions/store'
|
|
|
|
import { EMOJI_USE } from '../actions/emojis'
|
|
|
|
import { LIST_DELETE_SUCCESS, LIST_FETCH_FAIL } from '../actions/lists'
|
2020-09-14 17:40:42 +01:00
|
|
|
import { TIMELINE_INJECTION_HIDE } from '../actions/timeline_injections'
|
2020-12-09 04:15:33 +00:00
|
|
|
import {
|
|
|
|
DECK_SET_COLUMN_AT_INDEX,
|
|
|
|
DECK_DELETE_COLUMN_AT_INDEX,
|
|
|
|
DECK_CHANGE_COLUMN_AT_INDEX,
|
|
|
|
} from '../actions/deck'
|
2020-09-14 17:40:42 +01:00
|
|
|
import {
|
|
|
|
COMMENT_SORTING_TYPE_OLDEST,
|
|
|
|
TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
|
|
|
TIMELINE_INJECTION_FEATURED_GROUPS,
|
|
|
|
TIMELINE_INJECTION_GROUP_CATEGORIES,
|
2020-10-13 16:30:14 +01:00
|
|
|
TIMELINE_INJECTION_PROGRESS,
|
2020-09-14 17:40:42 +01:00
|
|
|
TIMELINE_INJECTION_PRO_UPGRADE,
|
|
|
|
TIMELINE_INJECTION_PWA,
|
|
|
|
TIMELINE_INJECTION_SHOP,
|
|
|
|
TIMELINE_INJECTION_USER_SUGGESTIONS,
|
|
|
|
} from '../constants'
|
2020-12-09 04:15:33 +00:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
|
2020-05-03 06:22:49 +01:00
|
|
|
import uuid from '../utils/uuid'
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
|
|
|
saved: true,
|
2020-07-15 04:31:54 +01:00
|
|
|
shownOnboarding: false,
|
2019-07-02 08:10:25 +01:00
|
|
|
skinTone: 1,
|
2020-12-06 04:47:48 +00:00
|
|
|
isCompact: false,
|
2020-05-27 06:15:10 +01:00
|
|
|
commentSorting: COMMENT_SORTING_TYPE_OLDEST,
|
2020-12-09 04:15:33 +00:00
|
|
|
gabDeckOrder: ImmutableList([]),
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-09-14 17:40:42 +01:00
|
|
|
// every dismiss reduces by half or set to zero for pwa, shop, pro
|
|
|
|
injections: ImmutableMap({
|
|
|
|
[TIMELINE_INJECTION_FEATURED_GROUPS]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
|
|
|
[TIMELINE_INJECTION_GROUP_CATEGORIES]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
2020-10-13 16:30:14 +01:00
|
|
|
[TIMELINE_INJECTION_PROGRESS]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
2020-09-14 17:40:42 +01:00
|
|
|
[TIMELINE_INJECTION_PRO_UPGRADE]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
|
|
|
[TIMELINE_INJECTION_PWA]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
|
|
|
[TIMELINE_INJECTION_SHOP]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
|
|
|
[TIMELINE_INJECTION_USER_SUGGESTIONS]: TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
|
|
|
}),
|
|
|
|
|
2020-05-03 06:22:49 +01:00
|
|
|
displayOptions: ImmutableMap({
|
|
|
|
fontSize: 'normal',
|
|
|
|
radiusSmallDisabled: false,
|
|
|
|
radiusCircleDisabled: false,
|
2020-11-03 21:04:31 +00:00
|
|
|
logoDisabled: false,
|
2020-11-03 21:13:35 +00:00
|
|
|
theme: 'white',
|
2020-03-25 03:08:43 +00:00
|
|
|
}),
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-05-03 06:22:49 +01:00
|
|
|
home: ImmutableMap({
|
2019-08-09 01:41:56 +01:00
|
|
|
shows: ImmutableMap({
|
|
|
|
reply: true,
|
2020-03-25 03:08:43 +00:00
|
|
|
repost: true,
|
2019-08-09 01:41:56 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
community: ImmutableMap({
|
2020-03-25 03:08:43 +00:00
|
|
|
shows: ImmutableMap({
|
2019-07-31 16:04:11 +01:00
|
|
|
onlyMedia: false,
|
|
|
|
}),
|
2019-07-02 08:10:25 +01:00
|
|
|
}),
|
2020-12-09 04:15:33 +00:00
|
|
|
})
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
const defaultColumns = fromJS([
|
|
|
|
{ id: 'COMPOSE', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'HOME', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
|
2020-12-09 04:15:33 +00:00
|
|
|
])
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-12-09 04:15:33 +00:00
|
|
|
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val)
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-12-09 04:15:33 +00:00
|
|
|
const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false)
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-12-09 04:15:33 +00:00
|
|
|
const filterDeadListColumns = (state, listId) => state.update('columns', columns => columns.filterNot(column => column.get('id') === 'LIST' && column.get('params').get('id') === listId))
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
export default function settings(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STORE_HYDRATE:
|
2020-12-09 04:15:33 +00:00
|
|
|
return hydrate(state, action.state.get('settings'))
|
2019-07-02 08:10:25 +01:00
|
|
|
case SETTING_CHANGE:
|
|
|
|
return state
|
|
|
|
.setIn(action.path, action.value)
|
2020-12-09 04:15:33 +00:00
|
|
|
.set('saved', false)
|
2019-07-02 08:10:25 +01:00
|
|
|
case EMOJI_USE:
|
2020-12-09 04:15:33 +00:00
|
|
|
return updateFrequentEmojis(state, action.emoji)
|
2019-07-02 08:10:25 +01:00
|
|
|
case SETTING_SAVE:
|
2020-12-09 04:15:33 +00:00
|
|
|
return state.set('saved', true)
|
2019-07-02 08:10:25 +01:00
|
|
|
case LIST_FETCH_FAIL:
|
2020-12-09 04:15:33 +00:00
|
|
|
return action.error.response.status === 404 ? filterDeadListColumns(state, action.id) : state
|
2019-07-02 08:10:25 +01:00
|
|
|
case LIST_DELETE_SUCCESS:
|
2020-12-09 04:15:33 +00:00
|
|
|
return filterDeadListColumns(state, action.id)
|
|
|
|
case DECK_SET_COLUMN_AT_INDEX:
|
|
|
|
// : todo : max: 12
|
|
|
|
const sizeOfDeck = state.get('gabDeckOrder', ImmutableList()).size
|
|
|
|
const newIndex = Math.max(action.index || 0, sizeOfDeck)
|
|
|
|
return state.setIn(['gabDeckOrder', newIndex + 1], action.column).set('saved', false)
|
|
|
|
case DECK_DELETE_COLUMN_AT_INDEX:
|
|
|
|
return state.deleteIn(['gabDeckOrder', action.index])
|
|
|
|
case DECK_CHANGE_COLUMN_AT_INDEX:
|
|
|
|
return state.update('gabDeckOrder', idsList => idsList.withMutations((list) => {
|
|
|
|
let soruce = list.get(action.oldIndex)
|
|
|
|
let destination = list.get(action.newIndex)
|
|
|
|
return list.set(action.newIndex, soruce).set(action.oldIndex, destination)
|
|
|
|
}))
|
2019-07-02 08:10:25 +01:00
|
|
|
default:
|
2020-12-09 04:15:33 +00:00
|
|
|
return state
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
2020-12-09 04:15:33 +00:00
|
|
|
}
|