chore: remove calls to Storage from settings.tsx

pull/3080/head
Audric Ackermann 3 weeks ago
parent 49ab04d2fd
commit fb99c3491c

@ -1,4 +1,4 @@
import { fromPairs, map } from 'lodash';
import { fromPairs, isBoolean, map } from 'lodash';
import moment from 'moment';
import React from 'react';
import { Provider } from 'react-redux';
@ -87,11 +87,31 @@ function createSessionInboxStore() {
return createStore(initialState);
}
function getBoolFromStorageOrFalse(settingsKey: string): boolean {
const got = Storage.get(settingsKey, false);
if (isBoolean(got)) {
return got;
}
return false;
}
function setupLeftPane(forceUpdateInboxComponent: () => void) {
window.openConversationWithMessages = openConversationWithMessages;
window.inboxStore = createSessionInboxStore();
window.inboxStore.dispatch(updateAllOnStorageReady());
window.inboxStore.dispatch(
updateAllOnStorageReady({
hasBlindedMsgRequestsEnabled: getBoolFromStorageOrFalse(
SettingsKey.hasBlindedMsgRequestsEnabled
),
someDeviceOutdatedSyncing: getBoolFromStorageOrFalse(SettingsKey.someDeviceOutdatedSyncing),
settingsLinkPreview: getBoolFromStorageOrFalse(SettingsKey.settingsLinkPreview),
hasFollowSystemThemeEnabled: getBoolFromStorageOrFalse(
SettingsKey.hasFollowSystemThemeEnabled
),
hasShiftSendEnabled: getBoolFromStorageOrFalse(SettingsKey.hasShiftSendEnabled),
})
);
forceUpdateInboxComponent();
}

@ -1,8 +1,7 @@
import { isBoolean } from 'lodash';
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
import { SettingsKey } from '../../data/settings-key';
import { Storage } from '../../util/storage';
import { SettingsKey } from '../../data/settings-key'; // ok: does not import anything else
const SettingsBoolsKeyTrackedInRedux = [
SettingsKey.someDeviceOutdatedSyncing,
@ -44,33 +43,31 @@ const settingsSlice = createSlice({
// Once the storage is ready,
initialState: getSettingsInitialState(),
reducers: {
updateAllOnStorageReady(state) {
const linkPreview = Storage.get(SettingsKey.settingsLinkPreview, false);
const outdatedSync = Storage.get(SettingsKey.someDeviceOutdatedSyncing, false);
const hasBlindedMsgRequestsEnabled = Storage.get(
SettingsKey.hasBlindedMsgRequestsEnabled,
false
);
const hasFollowSystemThemeEnabled = Storage.get(
SettingsKey.hasFollowSystemThemeEnabled,
false
);
const hasShiftSendEnabled = Storage.get(SettingsKey.hasShiftSendEnabled, false);
state.settingsBools.someDeviceOutdatedSyncing = isBoolean(outdatedSync)
? outdatedSync
: false;
state.settingsBools['link-preview-setting'] = isBoolean(linkPreview) ? linkPreview : false; // this is the value of SettingsKey.settingsLinkPreview
state.settingsBools.hasBlindedMsgRequestsEnabled = isBoolean(hasBlindedMsgRequestsEnabled)
? hasBlindedMsgRequestsEnabled
: false;
updateAllOnStorageReady(
state,
{
payload,
}: PayloadAction<{
settingsLinkPreview: boolean;
someDeviceOutdatedSyncing: boolean;
hasBlindedMsgRequestsEnabled: boolean;
hasFollowSystemThemeEnabled: boolean;
hasShiftSendEnabled: boolean;
}>
) {
const {
hasBlindedMsgRequestsEnabled,
hasFollowSystemThemeEnabled,
settingsLinkPreview,
someDeviceOutdatedSyncing,
hasShiftSendEnabled,
} = payload;
state.settingsBools.hasFollowSystemThemeEnabled = isBoolean(hasFollowSystemThemeEnabled)
? hasFollowSystemThemeEnabled
: false;
state.settingsBools.hasShiftSendEnabled = isBoolean(hasShiftSendEnabled)
? hasShiftSendEnabled
: false;
state.settingsBools.someDeviceOutdatedSyncing = someDeviceOutdatedSyncing;
state.settingsBools['link-preview-setting'] = settingsLinkPreview;
state.settingsBools.hasBlindedMsgRequestsEnabled = hasBlindedMsgRequestsEnabled;
state.settingsBools.hasFollowSystemThemeEnabled = hasFollowSystemThemeEnabled;
state.settingsBools.hasShiftSendEnabled = hasShiftSendEnabled;
return state;
},

@ -1,17 +1,16 @@
import { combineReducers } from '@reduxjs/toolkit';
import { callReducer as call, CallStateType } from './ducks/call'; // ok: importing only RingingManager.ts which is not importing anything else
import { reducer as conversations, ConversationsStateType } from './ducks/conversations'; // todo
import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/defaultRooms'; // todo
import { reducer as primaryColor } from './ducks/primaryColor'; // ok: importing only Constants.tsx which is not importing anything else
import { reducer as search, SearchStateType } from './ducks/search';
import { reducer as section, SectionStateType } from './ducks/section';
import { ReduxSogsRoomInfos, SogsRoomInfoState } from './ducks/sogsRoomInfo';
import { reducer as theme } from './ducks/theme'; // ok: importing only Constants.tsx which is not importing anything else
import { reducer as user, UserStateType } from './ducks/user'; // ok: not importing anything else
import { reducer as search, SearchStateType } from './ducks/search'; // todo
import { reducer as section, SectionStateType } from './ducks/section'; // ok: importing only SessionSettingsCategory which is not importing anything else
import { ReduxSogsRoomInfos, SogsRoomInfoState } from './ducks/sogsRoomInfo'; // todo
import { reducer as theme } from './ducks/theme'; // ok: importing only Constants.tsx which is not importing anything else
import { reducer as user, UserStateType } from './ducks/user'; // ok: not importing anything else
import { PrimaryColorStateType, ThemeStateType } from '../themes/constants/colors'; // ok: not importing anything else
import { PrimaryColorStateType, ThemeStateType } from '../themes/constants/colors'; // ok: not importing anything else
import { modalReducer as modals, ModalState } from './ducks/modalDialog';
import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion'; // ok: not importing anything else
import { settingsReducer, SettingsState } from './ducks/settings';

Loading…
Cancel
Save