chore: remove calls to Storage from settings.tsx

pull/3080/head
Audric Ackermann 1 year 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 moment from 'moment';
import React from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
@ -87,11 +87,31 @@ function createSessionInboxStore() {
return createStore(initialState); 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) { function setupLeftPane(forceUpdateInboxComponent: () => void) {
window.openConversationWithMessages = openConversationWithMessages; window.openConversationWithMessages = openConversationWithMessages;
window.inboxStore = createSessionInboxStore(); 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(); forceUpdateInboxComponent();
} }

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

@ -1,17 +1,16 @@
import { combineReducers } from '@reduxjs/toolkit'; 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 { 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 { reducer as conversations, ConversationsStateType } from './ducks/conversations'; // todo
import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/defaultRooms'; // 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 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 search, SearchStateType } from './ducks/search'; // todo
import { reducer as section, SectionStateType } from './ducks/section'; import { reducer as section, SectionStateType } from './ducks/section'; // ok: importing only SessionSettingsCategory which is not importing anything else
import { ReduxSogsRoomInfos, SogsRoomInfoState } from './ducks/sogsRoomInfo'; 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 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 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 { modalReducer as modals, ModalState } from './ducks/modalDialog';
import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion'; // ok: not importing anything else import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion'; // ok: not importing anything else
import { settingsReducer, SettingsState } from './ducks/settings'; import { settingsReducer, SettingsState } from './ducks/settings';

Loading…
Cancel
Save