Progress on Gab Deck, Updates on Compose
• Progress on Gab Deck, Updates on Compose
This commit is contained in:
@@ -3,6 +3,11 @@ import { STORE_HYDRATE } from '../actions/store'
|
||||
import { EMOJI_USE } from '../actions/emojis'
|
||||
import { LIST_DELETE_SUCCESS, LIST_FETCH_FAIL } from '../actions/lists'
|
||||
import { TIMELINE_INJECTION_HIDE } from '../actions/timeline_injections'
|
||||
import {
|
||||
DECK_SET_COLUMN_AT_INDEX,
|
||||
DECK_DELETE_COLUMN_AT_INDEX,
|
||||
DECK_CHANGE_COLUMN_AT_INDEX,
|
||||
} from '../actions/deck'
|
||||
import {
|
||||
COMMENT_SORTING_TYPE_OLDEST,
|
||||
TIMELINE_INJECTION_WEIGHT_DEFAULT,
|
||||
@@ -14,7 +19,7 @@ import {
|
||||
TIMELINE_INJECTION_SHOP,
|
||||
TIMELINE_INJECTION_USER_SUGGESTIONS,
|
||||
} from '../constants'
|
||||
import { Map as ImmutableMap, fromJS } from 'immutable'
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
|
||||
import uuid from '../utils/uuid'
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
@@ -23,6 +28,7 @@ const initialState = ImmutableMap({
|
||||
skinTone: 1,
|
||||
isCompact: false,
|
||||
commentSorting: COMMENT_SORTING_TYPE_OLDEST,
|
||||
gabDeckOrder: ImmutableList([]),
|
||||
|
||||
// every dismiss reduces by half or set to zero for pwa, shop, pro
|
||||
injections: ImmutableMap({
|
||||
@@ -55,37 +61,50 @@ const initialState = ImmutableMap({
|
||||
onlyMedia: false,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
})
|
||||
|
||||
const defaultColumns = fromJS([
|
||||
{ id: 'COMPOSE', uuid: uuid(), params: {} },
|
||||
{ id: 'HOME', uuid: uuid(), params: {} },
|
||||
{ id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
|
||||
]);
|
||||
])
|
||||
|
||||
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val);
|
||||
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val)
|
||||
|
||||
const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false);
|
||||
const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false)
|
||||
|
||||
const filterDeadListColumns = (state, listId) => state.update('columns', columns => columns.filterNot(column => column.get('id') === 'LIST' && column.get('params').get('id') === listId));
|
||||
const filterDeadListColumns = (state, listId) => state.update('columns', columns => columns.filterNot(column => column.get('id') === 'LIST' && column.get('params').get('id') === listId))
|
||||
|
||||
export default function settings(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case STORE_HYDRATE:
|
||||
return hydrate(state, action.state.get('settings'));
|
||||
return hydrate(state, action.state.get('settings'))
|
||||
case SETTING_CHANGE:
|
||||
return state
|
||||
.setIn(action.path, action.value)
|
||||
.set('saved', false);
|
||||
.set('saved', false)
|
||||
case EMOJI_USE:
|
||||
return updateFrequentEmojis(state, action.emoji);
|
||||
return updateFrequentEmojis(state, action.emoji)
|
||||
case SETTING_SAVE:
|
||||
return state.set('saved', true);
|
||||
return state.set('saved', true)
|
||||
case LIST_FETCH_FAIL:
|
||||
return action.error.response.status === 404 ? filterDeadListColumns(state, action.id) : state;
|
||||
return action.error.response.status === 404 ? filterDeadListColumns(state, action.id) : state
|
||||
case LIST_DELETE_SUCCESS:
|
||||
return filterDeadListColumns(state, action.id);
|
||||
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)
|
||||
}))
|
||||
default:
|
||||
return state;
|
||||
return state
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user