preferences --> settings
I give up trying to organize them. Just going back to using Mastodon's preferences map.
This commit is contained in:
parent
fc04e6a718
commit
bc5b286737
17 changed files with 42 additions and 172 deletions
|
@ -65,9 +65,9 @@ export function importFetchedStatuses(statuses) {
|
||||||
|
|
||||||
function processStatus(status) {
|
function processStatus(status) {
|
||||||
const normalOldStatus = getState().getIn(['statuses', status.id]);
|
const normalOldStatus = getState().getIn(['statuses', status.id]);
|
||||||
const readingPrefs = getState().getIn(['preferences', 'reading']);
|
const expandSpoilers = getState().getIn(['settings', 'expandSpoilers']);
|
||||||
|
|
||||||
pushUnique(normalStatuses, normalizeStatus(status, normalOldStatus, readingPrefs));
|
pushUnique(normalStatuses, normalizeStatus(status, normalOldStatus, expandSpoilers));
|
||||||
pushUnique(accounts, status.account);
|
pushUnique(accounts, status.account);
|
||||||
|
|
||||||
if (status.reblog && status.reblog.id) {
|
if (status.reblog && status.reblog.id) {
|
||||||
|
|
|
@ -34,9 +34,8 @@ export function normalizeAccount(account) {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeStatus(status, normalOldStatus, readingPrefs) {
|
export function normalizeStatus(status, normalOldStatus, expandSpoilers) {
|
||||||
const normalStatus = { ...status };
|
const normalStatus = { ...status };
|
||||||
const expandSpoilers = readingPrefs.getIn(['expand', 'spoilers']);
|
|
||||||
|
|
||||||
normalStatus.account = status.account.id;
|
normalStatus.account = status.account.id;
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
import api from '../api';
|
|
||||||
import { fetchMeSuccess } from 'gabsocial/actions/me';
|
|
||||||
import { debounce } from 'lodash';
|
|
||||||
import { showAlertForError } from './alerts';
|
|
||||||
|
|
||||||
export const MASTO_PREFS_FETCH_SUCCESS = 'MASTO_PREFS_FETCH_SUCCESS';
|
|
||||||
export const PREFERENCE_CHANGE = 'PREFERENCE_CHANGE';
|
|
||||||
export const PREFERENCE_SAVE = 'PREFERENCE_SAVE';
|
|
||||||
|
|
||||||
export const FE_NAME = 'soapbox_fe';
|
|
||||||
|
|
||||||
export function fetchMastoPreferences() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
api(getState).get('/api/v1/preferences').then(response => {
|
|
||||||
dispatch(mastoFetchPrefsSuccess(response.data));
|
|
||||||
}).catch(e => {
|
|
||||||
console.error(e);
|
|
||||||
console.error('Could not fetch Mastodon preferences.');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mastoFetchPrefsSuccess(prefs) {
|
|
||||||
return {
|
|
||||||
type: MASTO_PREFS_FETCH_SUCCESS,
|
|
||||||
prefs,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changePreference(path, value) {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch({
|
|
||||||
type: PREFERENCE_CHANGE,
|
|
||||||
path,
|
|
||||||
value,
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch(savePreferences());
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const debouncedSave = debounce((dispatch, getState) => {
|
|
||||||
if (!getState().get('me')) return;
|
|
||||||
if (getState().getIn(['preferences', 'saved'])) return;
|
|
||||||
|
|
||||||
const data = getState().get('preferences').delete('saved').toJS();
|
|
||||||
|
|
||||||
api(getState).patch('/api/v1/accounts/update_credentials', {
|
|
||||||
pleroma_settings_store: {
|
|
||||||
[FE_NAME]: data,
|
|
||||||
},
|
|
||||||
}).then(response => {
|
|
||||||
dispatch({ type: PREFERENCE_SAVE });
|
|
||||||
dispatch(fetchMeSuccess(response.data));
|
|
||||||
}).catch(error => {
|
|
||||||
dispatch(showAlertForError(error));
|
|
||||||
});
|
|
||||||
}, 5000, { trailing: true });
|
|
||||||
|
|
||||||
export function savePreferences() {
|
|
||||||
return (dispatch, getState) => debouncedSave(dispatch, getState);
|
|
||||||
};
|
|
|
@ -1,10 +1,13 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { showAlertForError } from './alerts';
|
import { showAlertForError } from './alerts';
|
||||||
|
import { fetchMeSuccess } from 'gabsocial/actions/me';
|
||||||
|
|
||||||
export const SETTING_CHANGE = 'SETTING_CHANGE';
|
export const SETTING_CHANGE = 'SETTING_CHANGE';
|
||||||
export const SETTING_SAVE = 'SETTING_SAVE';
|
export const SETTING_SAVE = 'SETTING_SAVE';
|
||||||
|
|
||||||
|
export const FE_NAME = 'soapbox_fe';
|
||||||
|
|
||||||
export function changeSetting(path, value) {
|
export function changeSetting(path, value) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -19,16 +22,20 @@ export function changeSetting(path, value) {
|
||||||
|
|
||||||
const debouncedSave = debounce((dispatch, getState) => {
|
const debouncedSave = debounce((dispatch, getState) => {
|
||||||
if (!getState().get('me')) return;
|
if (!getState().get('me')) return;
|
||||||
|
if (getState().getIn(['settings', 'saved'])) return;
|
||||||
|
|
||||||
if (getState().getIn(['settings', 'saved'])) {
|
const data = getState().get('settings').delete('saved').toJS();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS();
|
api(getState).patch('/api/v1/accounts/update_credentials', {
|
||||||
|
pleroma_settings_store: {
|
||||||
api().put('/api/web/settings', { data })
|
[FE_NAME]: data,
|
||||||
.then(() => dispatch({ type: SETTING_SAVE }))
|
},
|
||||||
.catch(error => dispatch(showAlertForError(error)));
|
}).then(response => {
|
||||||
|
dispatch({ type: SETTING_SAVE });
|
||||||
|
dispatch(fetchMeSuccess(response.data));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(showAlertForError(error));
|
||||||
|
});
|
||||||
}, 5000, { trailing: true });
|
}, 5000, { trailing: true });
|
||||||
|
|
||||||
export function saveSettings() {
|
export function saveSettings() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
animate: state.getIn(['preferences', 'auto_play_gif']),
|
animate: state.getIn(['settings', 'autoPlayGif']),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
animate: state.getIn(['preferences', 'auto_play_gif']),
|
animate: state.getIn(['settings', 'autoPlayGif']),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
animate: state.getIn(['preferences', 'auto_play_gif']),
|
animate: state.getIn(['settings', 'autoPlayGif']),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
|
|
|
@ -16,7 +16,7 @@ const messages = defineMessages({
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
autoPlayGif: state.getIn(['preferences', 'auto_play_gif']),
|
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
|
||||||
});
|
});
|
||||||
|
|
||||||
@connect(mapStateToProps)
|
@connect(mapStateToProps)
|
||||||
|
|
|
@ -41,7 +41,7 @@ const mapStateToProps = (state) => {
|
||||||
return {
|
return {
|
||||||
showIntroduction,
|
showIntroduction,
|
||||||
me,
|
me,
|
||||||
theme: state.getIn(['preferences', 'theme']),
|
theme: state.getIn(['settings', 'theme']),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ const messages = defineMessages({
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
return {
|
return {
|
||||||
me: state.get('me'),
|
me: state.get('me'),
|
||||||
autoPlayGif: state.getIn(['preferences', 'auto_play_gif']),
|
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { decode } from 'blurhash';
|
||||||
import { isIOS } from 'gabsocial/is_mobile';
|
import { isIOS } from 'gabsocial/is_mobile';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
autoPlayGif: state.getIn(['preferences', 'auto_play_gif']),
|
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { defineMessages, injectIntl } from 'react-intl';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import { changePreference } from 'gabsocial/actions/preferences';
|
import { changeSetting } from 'gabsocial/actions/settings';
|
||||||
import Column from '../ui/components/column';
|
import Column from '../ui/components/column';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
@ -50,7 +50,7 @@ class Preferences extends ImmutablePureComponent {
|
||||||
|
|
||||||
onThemeChange = e => {
|
onThemeChange = e => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
dispatch(changePreference(['theme'], e.target.value));
|
dispatch(changeSetting(['theme'], e.target.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -90,7 +90,7 @@ const mapStateToProps = state => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account: getAccount(state, me),
|
account: getAccount(state, me),
|
||||||
autoPlayGif: state.getIn(['preferences', 'auto_play_gif']),
|
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
import { mastoPrefsToMap } from '../preferences';
|
|
||||||
import { Map as ImmutableMap } from 'immutable';
|
|
||||||
|
|
||||||
describe('mastoPrefToMap', () => {
|
|
||||||
const prefs = {
|
|
||||||
'posting:default:visibility': 'public',
|
|
||||||
'posting:default:sensitive': false,
|
|
||||||
'posting:default:language': null,
|
|
||||||
'reading:expand:media': 'default',
|
|
||||||
'reading:expand:spoilers': false,
|
|
||||||
};
|
|
||||||
it('returns a map', () => {
|
|
||||||
expect(mastoPrefsToMap(prefs)).toEqual(ImmutableMap({
|
|
||||||
posting: ImmutableMap({
|
|
||||||
default: ImmutableMap({
|
|
||||||
visibility: 'public',
|
|
||||||
sensitive: false,
|
|
||||||
language: null,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
reading: ImmutableMap({
|
|
||||||
expand: ImmutableMap({
|
|
||||||
media: 'default',
|
|
||||||
spoilers: false,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -42,7 +42,6 @@ import soapbox from './soapbox';
|
||||||
import instance from './instance';
|
import instance from './instance';
|
||||||
import me from './me';
|
import me from './me';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
import preferences from './preferences';
|
|
||||||
|
|
||||||
const reducers = {
|
const reducers = {
|
||||||
dropdown_menu,
|
dropdown_menu,
|
||||||
|
@ -88,7 +87,6 @@ const reducers = {
|
||||||
instance,
|
instance,
|
||||||
me,
|
me,
|
||||||
auth,
|
auth,
|
||||||
preferences,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default combineReducers(reducers);
|
export default combineReducers(reducers);
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
import {
|
|
||||||
MASTO_PREFS_FETCH_SUCCESS,
|
|
||||||
PREFERENCE_CHANGE,
|
|
||||||
PREFERENCE_SAVE,
|
|
||||||
FE_NAME,
|
|
||||||
} from 'gabsocial/actions/preferences';
|
|
||||||
import { ME_FETCH_SUCCESS } from 'gabsocial/actions/me';
|
|
||||||
|
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
|
||||||
saved: true,
|
|
||||||
posting: ImmutableMap({
|
|
||||||
default: ImmutableMap({
|
|
||||||
visibility: 'public',
|
|
||||||
sensitive: false,
|
|
||||||
language: null,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
reading: ImmutableMap({
|
|
||||||
expand: ImmutableMap({
|
|
||||||
media: 'default',
|
|
||||||
spoilers: false,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
auto_play_gif: false,
|
|
||||||
theme: 'lime',
|
|
||||||
});
|
|
||||||
|
|
||||||
export function mastoPrefsToMap(prefs) {
|
|
||||||
let map = ImmutableMap();
|
|
||||||
for (const [key, value] of Object.entries(prefs)) {
|
|
||||||
map = map.setIn(key.split(':'), value);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function preferences(state = initialState, action) {
|
|
||||||
switch(action.type) {
|
|
||||||
case MASTO_PREFS_FETCH_SUCCESS:
|
|
||||||
return state.merge(mastoPrefsToMap(action.prefs));
|
|
||||||
case ME_FETCH_SUCCESS:
|
|
||||||
const me = fromJS(action.me);
|
|
||||||
const fePrefs = me.getIn(['pleroma', 'settings_store', FE_NAME]);
|
|
||||||
return state.merge(fePrefs);
|
|
||||||
case PREFERENCE_CHANGE:
|
|
||||||
return state
|
|
||||||
.setIn(action.path, action.value)
|
|
||||||
.set('saved', false);
|
|
||||||
case PREFERENCE_SAVE:
|
|
||||||
return state.set('saved', true);
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +1,25 @@
|
||||||
import { SETTING_CHANGE, SETTING_SAVE } from '../actions/settings';
|
import { SETTING_CHANGE, SETTING_SAVE, FE_NAME } from '../actions/settings';
|
||||||
import { NOTIFICATIONS_FILTER_SET } from '../actions/notifications';
|
import { NOTIFICATIONS_FILTER_SET } from '../actions/notifications';
|
||||||
import { STORE_HYDRATE } from '../actions/store';
|
import { STORE_HYDRATE } from '../actions/store';
|
||||||
import { EMOJI_USE } from '../actions/emojis';
|
import { EMOJI_USE } from '../actions/emojis';
|
||||||
import { LIST_DELETE_SUCCESS, LIST_FETCH_FAIL } from '../actions/lists';
|
import { LIST_DELETE_SUCCESS, LIST_FETCH_FAIL } from '../actions/lists';
|
||||||
|
import { ME_FETCH_SUCCESS } from 'gabsocial/actions/me';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
import uuid from '../uuid';
|
import uuid from '../uuid';
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
saved: true,
|
saved: true,
|
||||||
|
|
||||||
onboarded: false,
|
onboarded: false,
|
||||||
|
|
||||||
skinTone: 1,
|
skinTone: 1,
|
||||||
|
reduceMotion: false,
|
||||||
|
autoPlayGif: false,
|
||||||
|
displayMedia: true,
|
||||||
|
expandSpoilers: false,
|
||||||
|
unfollowModal: false,
|
||||||
|
boostModal: false,
|
||||||
|
deleteModal: true,
|
||||||
|
theme: 'lime',
|
||||||
|
|
||||||
home: ImmutableMap({
|
home: ImmutableMap({
|
||||||
shows: ImmutableMap({
|
shows: ImmutableMap({
|
||||||
|
@ -101,6 +109,10 @@ export default function settings(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case STORE_HYDRATE:
|
case STORE_HYDRATE:
|
||||||
return hydrate(state, action.state.get('settings'));
|
return hydrate(state, action.state.get('settings'));
|
||||||
|
case ME_FETCH_SUCCESS:
|
||||||
|
const me = fromJS(action.me);
|
||||||
|
const fePrefs = me.getIn(['pleroma', 'settings_store', FE_NAME]);
|
||||||
|
return state.merge(fePrefs);
|
||||||
case NOTIFICATIONS_FILTER_SET:
|
case NOTIFICATIONS_FILTER_SET:
|
||||||
case SETTING_CHANGE:
|
case SETTING_CHANGE:
|
||||||
return state
|
return state
|
||||||
|
|
Loading…
Reference in a new issue