2022-10-11 10:17:04 +02:00
|
|
|
import { expandSpoilers, disableSwiping } from 'flavours/glitch/initial_state';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2022-05-15 17:30:40 +02:00
|
|
|
import { openModal } from './modal';
|
|
|
|
|
2017-11-18 04:11:18 +01:00
|
|
|
export const LOCAL_SETTING_CHANGE = 'LOCAL_SETTING_CHANGE';
|
2022-05-15 17:30:40 +02:00
|
|
|
export const LOCAL_SETTING_DELETE = 'LOCAL_SETTING_DELETE';
|
|
|
|
|
|
|
|
export function checkDeprecatedLocalSettings() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const local_auto_unfold = getState().getIn(['local_settings', 'content_warnings', 'auto_unfold']);
|
|
|
|
const local_swipe_to_change_columns = getState().getIn(['local_settings', 'swipe_to_change_columns']);
|
|
|
|
let changed_settings = [];
|
|
|
|
|
|
|
|
if (local_auto_unfold !== null && local_auto_unfold !== undefined) {
|
|
|
|
if (local_auto_unfold === expandSpoilers) {
|
|
|
|
dispatch(deleteLocalSetting(['content_warnings', 'auto_unfold']));
|
|
|
|
} else {
|
|
|
|
changed_settings.push('user_setting_expand_spoilers');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (local_swipe_to_change_columns !== null && local_swipe_to_change_columns !== undefined) {
|
|
|
|
if (local_swipe_to_change_columns === !disableSwiping) {
|
|
|
|
dispatch(deleteLocalSetting(['swipe_to_change_columns']));
|
|
|
|
} else {
|
|
|
|
changed_settings.push('user_setting_disable_swiping');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed_settings.length > 0) {
|
2023-05-25 15:42:37 +02:00
|
|
|
dispatch(openModal({
|
|
|
|
modalType: 'DEPRECATED_SETTINGS',
|
|
|
|
modalProps: {
|
|
|
|
settings: changed_settings,
|
|
|
|
onConfirm: () => dispatch(clearDeprecatedLocalSettings()),
|
|
|
|
},
|
2022-05-15 17:30:40 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
};
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|
2022-05-15 17:30:40 +02:00
|
|
|
|
|
|
|
export function clearDeprecatedLocalSettings() {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(deleteLocalSetting(['content_warnings', 'auto_unfold']));
|
|
|
|
dispatch(deleteLocalSetting(['swipe_to_change_columns']));
|
|
|
|
};
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|
2017-11-18 04:11:18 +01:00
|
|
|
|
|
|
|
export function changeLocalSetting(key, value) {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: LOCAL_SETTING_CHANGE,
|
|
|
|
key,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch(saveLocalSettings());
|
|
|
|
};
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|
2017-11-18 04:11:18 +01:00
|
|
|
|
2022-05-15 17:30:40 +02:00
|
|
|
export function deleteLocalSetting(key) {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: LOCAL_SETTING_DELETE,
|
|
|
|
key,
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch(saveLocalSettings());
|
|
|
|
};
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|
2022-05-15 17:30:40 +02:00
|
|
|
|
2017-11-18 04:11:18 +01:00
|
|
|
// __TODO :__
|
|
|
|
// Right now `saveLocalSettings()` doesn't keep track of which user
|
|
|
|
// is currently signed in, but it might be better to give each user
|
|
|
|
// their *own* local settings.
|
|
|
|
export function saveLocalSettings() {
|
|
|
|
return (_, getState) => {
|
|
|
|
const localSettings = getState().get('local_settings').toJS();
|
|
|
|
localStorage.setItem('mastodon-settings', JSON.stringify(localSettings));
|
|
|
|
};
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|