From d38c17bcd8a9d7f55d0ccfd5fae90412ce755b5f Mon Sep 17 00:00:00 2001 From: Gleidson Daniel Silva Date: Thu, 7 Apr 2022 11:19:54 -0300 Subject: [PATCH] Chore: Create app/lib/store folder (#4028) Co-authored-by: Diego Mello --- app/containers/MessageBox/EmojiKeyboard.tsx | 2 +- app/ee/omnichannel/lib/subscriptions/inquiry.ts | 2 +- app/index.tsx | 4 ++-- app/lib/encryption/encryption.ts | 2 +- app/lib/methods/canOpenRoom.ts | 2 +- app/lib/methods/helpers/mergeSubscriptionsRooms.ts | 2 +- app/lib/methods/subscriptions/room.ts | 2 +- app/lib/methods/subscriptions/rooms.ts | 2 +- app/lib/rocketchat/methods/callJitsi.ts | 2 +- app/lib/rocketchat/methods/enterpriseModules.ts | 2 +- app/lib/rocketchat/methods/getCustomEmojis.ts | 2 +- app/lib/rocketchat/methods/getPermalinks.ts | 2 +- app/lib/rocketchat/methods/getPermissions.ts | 2 +- app/lib/rocketchat/methods/getRoles.ts | 2 +- app/lib/rocketchat/methods/getSettings.ts | 2 +- app/lib/rocketchat/methods/getUsersPresence.ts | 2 +- app/lib/rocketchat/methods/helpers.ts | 2 +- app/lib/rocketchat/methods/setUser.ts | 2 +- app/lib/rocketchat/services/connect.ts | 2 +- app/lib/rocketchat/services/restApi.ts | 2 +- app/lib/rocketchat/services/sdk.ts | 2 +- app/lib/rocketchat/services/shareExtension.ts | 2 +- .../appStateMiddleware.ts} | 8 ++++---- app/lib/{ => store}/auxStore.ts | 2 +- app/lib/{createStore.js => store/index.ts} | 4 ++-- app/notifications/push/index.ts | 2 +- app/notifications/push/push.ios.ts | 2 +- app/share.tsx | 4 ++-- app/utils/isReadOnly.ts | 2 +- app/utils/localAuthentication.ts | 2 +- 30 files changed, 36 insertions(+), 36 deletions(-) rename app/lib/{appStateMiddleware.js => store/appStateMiddleware.ts} (84%) rename app/lib/{ => store}/auxStore.ts (82%) rename app/lib/{createStore.js => store/index.ts} (92%) diff --git a/app/containers/MessageBox/EmojiKeyboard.tsx b/app/containers/MessageBox/EmojiKeyboard.tsx index e38660a9b..acf5dd863 100644 --- a/app/containers/MessageBox/EmojiKeyboard.tsx +++ b/app/containers/MessageBox/EmojiKeyboard.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { View } from 'react-native'; import { KeyboardRegistry } from 'react-native-ui-lib/keyboard'; -import { store } from '../../lib/auxStore'; +import { store } from '../../lib/store/auxStore'; import EmojiPicker from '../EmojiPicker'; import styles from './styles'; import { themes } from '../../lib/constants'; diff --git a/app/ee/omnichannel/lib/subscriptions/inquiry.ts b/app/ee/omnichannel/lib/subscriptions/inquiry.ts index 69953e378..480677f2e 100644 --- a/app/ee/omnichannel/lib/subscriptions/inquiry.ts +++ b/app/ee/omnichannel/lib/subscriptions/inquiry.ts @@ -1,5 +1,5 @@ import log from '../../../../utils/log'; -import { store } from '../../../../lib/auxStore'; +import { store } from '../../../../lib/store/auxStore'; import RocketChat from '../../../../lib/rocketchat'; import { inquiryQueueAdd, inquiryQueueRemove, inquiryQueueUpdate, inquiryRequest } from '../../actions/inquiry'; import sdk from '../../../../lib/rocketchat/services/sdk'; diff --git a/app/index.tsx b/app/index.tsx index 6d3dd9b2e..22446d9ce 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -12,7 +12,6 @@ import { appInit, appInitLocalSettings, setMasterDetail as setMasterDetailAction import { deepLinkingOpen } from './actions/deepLinking'; import parseQuery from './lib/methods/helpers/parseQuery'; import { initializePushNotifications, onNotification } from './notifications/push'; -import store from './lib/createStore'; import { toggleAnalyticsEventsReport, toggleCrashErrorsReport } from './utils/log'; import { ThemeContext, TSupportedThemes } from './theme'; import { DimensionsContext } from './dimensions'; @@ -30,7 +29,8 @@ import debounce from './utils/debounce'; import { isFDroidBuild, MIN_WIDTH_MASTER_DETAIL_LAYOUT, colors, themes } from './lib/constants'; import { IThemePreference } from './definitions/ITheme'; import { ICommand } from './definitions/ICommand'; -import { initStore } from './lib/auxStore'; +import store from './lib/store'; +import { initStore } from './lib/store/auxStore'; RNScreens.enableScreens(); initStore(store); diff --git a/app/lib/encryption/encryption.ts b/app/lib/encryption/encryption.ts index ff1727185..4d0cd68fa 100644 --- a/app/lib/encryption/encryption.ts +++ b/app/lib/encryption/encryption.ts @@ -9,7 +9,7 @@ import database from '../database'; import protectedFunction from '../methods/helpers/protectedFunction'; import Deferred from '../../utils/deferred'; import log from '../../utils/log'; -import { store } from '../auxStore'; +import { store } from '../store/auxStore'; import { joinVectorData, randomPassword, splitVectorData, toString, utf8ToBuffer } from './utils'; import { EncryptionRoom } from './index'; import { IMessage, ISubscription, TMessageModel, TSubscriptionModel, TThreadMessageModel, TThreadModel } from '../../definitions'; diff --git a/app/lib/methods/canOpenRoom.ts b/app/lib/methods/canOpenRoom.ts index 93f297180..404afa8a2 100644 --- a/app/lib/methods/canOpenRoom.ts +++ b/app/lib/methods/canOpenRoom.ts @@ -1,5 +1,5 @@ import { ERoomTypes } from '../../definitions'; -import { store } from '../auxStore'; +import { store } from '../store/auxStore'; import database from '../database'; import RocketChat from '../rocketchat'; import sdk from '../rocketchat/services/sdk'; diff --git a/app/lib/methods/helpers/mergeSubscriptionsRooms.ts b/app/lib/methods/helpers/mergeSubscriptionsRooms.ts index 9d108b9f9..e39bf2287 100644 --- a/app/lib/methods/helpers/mergeSubscriptionsRooms.ts +++ b/app/lib/methods/helpers/mergeSubscriptionsRooms.ts @@ -1,7 +1,7 @@ import EJSON from 'ejson'; import { Encryption } from '../../encryption'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import findSubscriptionsRooms from './findSubscriptionsRooms'; import normalizeMessage from './normalizeMessage'; import { ISubscription, IServerSubscription, IServerRoom, IRoom } from '../../../definitions'; diff --git a/app/lib/methods/subscriptions/room.ts b/app/lib/methods/subscriptions/room.ts index baac2b72c..296180686 100644 --- a/app/lib/methods/subscriptions/room.ts +++ b/app/lib/methods/subscriptions/room.ts @@ -9,7 +9,7 @@ import database from '../../database'; import { getMessageById } from '../../database/services/Message'; import { getThreadById } from '../../database/services/Thread'; import { getThreadMessageById } from '../../database/services/ThreadMessage'; -import reduxStore from '../../createStore'; +import { store as reduxStore } from '../../store/auxStore'; import { addUserTyping, clearUserTyping, removeUserTyping } from '../../../actions/usersTyping'; import debounce from '../../../utils/debounce'; import RocketChat from '../../rocketchat'; diff --git a/app/lib/methods/subscriptions/rooms.ts b/app/lib/methods/subscriptions/rooms.ts index 4a41475cb..e03ec4805 100644 --- a/app/lib/methods/subscriptions/rooms.ts +++ b/app/lib/methods/subscriptions/rooms.ts @@ -8,7 +8,7 @@ import { merge } from '../helpers/mergeSubscriptionsRooms'; import protectedFunction from '../helpers/protectedFunction'; import log from '../../../utils/log'; import random from '../../../utils/random'; -import { store } from '../../auxStore'; +import { store } from '../../store/auxStore'; import { handlePayloadUserInteraction } from '../actions'; import buildMessage from '../helpers/buildMessage'; import RocketChat from '../../rocketchat'; diff --git a/app/lib/rocketchat/methods/callJitsi.ts b/app/lib/rocketchat/methods/callJitsi.ts index 7b19bb389..1668802f1 100644 --- a/app/lib/rocketchat/methods/callJitsi.ts +++ b/app/lib/rocketchat/methods/callJitsi.ts @@ -1,6 +1,6 @@ import { ISubscription } from '../../../definitions'; import { events, logEvent } from '../../../utils/log'; -import { store } from '../../auxStore'; +import { store } from '../../store/auxStore'; import Navigation from '../../navigation/appNavigation'; import sdk from '../services/sdk'; diff --git a/app/lib/rocketchat/methods/enterpriseModules.ts b/app/lib/rocketchat/methods/enterpriseModules.ts index 41490e719..a38b99f81 100644 --- a/app/lib/rocketchat/methods/enterpriseModules.ts +++ b/app/lib/rocketchat/methods/enterpriseModules.ts @@ -1,5 +1,5 @@ import sdk from '../services/sdk'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import database from '../../database'; import log from '../../../utils/log'; import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../../actions/enterpriseModules'; diff --git a/app/lib/rocketchat/methods/getCustomEmojis.ts b/app/lib/rocketchat/methods/getCustomEmojis.ts index 94e3d737c..278693d47 100644 --- a/app/lib/rocketchat/methods/getCustomEmojis.ts +++ b/app/lib/rocketchat/methods/getCustomEmojis.ts @@ -2,7 +2,7 @@ import orderBy from 'lodash/orderBy'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { ICustomEmojis } from '../../../reducers/customEmojis'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import database from '../../database'; import log from '../../../utils/log'; import { setCustomEmojis as setCustomEmojisAction } from '../../../actions/customEmojis'; diff --git a/app/lib/rocketchat/methods/getPermalinks.ts b/app/lib/rocketchat/methods/getPermalinks.ts index 9bbe89a15..8e66517c1 100644 --- a/app/lib/rocketchat/methods/getPermalinks.ts +++ b/app/lib/rocketchat/methods/getPermalinks.ts @@ -1,6 +1,6 @@ import log from '../../../utils/log'; import { TMessageModel, TSubscriptionModel } from '../../../definitions'; -import { store } from '../../auxStore'; +import { store } from '../../store/auxStore'; import getRoom from '../../methods/getRoom'; import { isGroupChat } from './helpers'; diff --git a/app/lib/rocketchat/methods/getPermissions.ts b/app/lib/rocketchat/methods/getPermissions.ts index 2de011dc1..36199a5c8 100644 --- a/app/lib/rocketchat/methods/getPermissions.ts +++ b/app/lib/rocketchat/methods/getPermissions.ts @@ -5,7 +5,7 @@ import orderBy from 'lodash/orderBy'; import { setPermissions as setPermissionsAction } from '../../../actions/permissions'; import { IPermission, TPermissionModel } from '../../../definitions'; import log from '../../../utils/log'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import database from '../../database'; import sdk from '../services/sdk'; import protectedFunction from '../../methods/helpers/protectedFunction'; diff --git a/app/lib/rocketchat/methods/getRoles.ts b/app/lib/rocketchat/methods/getRoles.ts index 97677305a..0382a7bb3 100644 --- a/app/lib/rocketchat/methods/getRoles.ts +++ b/app/lib/rocketchat/methods/getRoles.ts @@ -4,7 +4,7 @@ import Model from '@nozbe/watermelondb/Model'; import database from '../../database'; import { getRoleById } from '../../database/services/Role'; import log from '../../../utils/log'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import { removeRoles, setRoles as setRolesAction, updateRoles } from '../../../actions/roles'; import protectedFunction from '../../methods/helpers/protectedFunction'; import { TRoleModel } from '../../../definitions'; diff --git a/app/lib/rocketchat/methods/getSettings.ts b/app/lib/rocketchat/methods/getSettings.ts index 01b549690..f0659c06a 100644 --- a/app/lib/rocketchat/methods/getSettings.ts +++ b/app/lib/rocketchat/methods/getSettings.ts @@ -6,7 +6,7 @@ import { DEFAULT_AUTO_LOCK, defaultSettings } from '../../constants'; import { IPreparedSettings, ISettingsIcon } from '../../../definitions'; import fetch from '../../../utils/fetch'; import log from '../../../utils/log'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import database from '../../database'; import RocketChat from '..'; import sdk from '../services/sdk'; diff --git a/app/lib/rocketchat/methods/getUsersPresence.ts b/app/lib/rocketchat/methods/getUsersPresence.ts index 92576a199..e7c24f663 100644 --- a/app/lib/rocketchat/methods/getUsersPresence.ts +++ b/app/lib/rocketchat/methods/getUsersPresence.ts @@ -2,7 +2,7 @@ import { InteractionManager } from 'react-native'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { IActiveUsers } from '../../../reducers/activeUsers'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import { setActiveUsers } from '../../../actions/activeUsers'; import { setUser } from '../../../actions/login'; import database from '../../database'; diff --git a/app/lib/rocketchat/methods/helpers.ts b/app/lib/rocketchat/methods/helpers.ts index 4a06e50ef..d62df0062 100644 --- a/app/lib/rocketchat/methods/helpers.ts +++ b/app/lib/rocketchat/methods/helpers.ts @@ -2,7 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import log from '../../../utils/log'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import database from '../../database'; import subscribeRoomsTmp from '../../methods/subscriptions/rooms'; import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, defaultSettings } from '../../constants'; diff --git a/app/lib/rocketchat/methods/setUser.ts b/app/lib/rocketchat/methods/setUser.ts index db95f0a4e..6cc31e5de 100644 --- a/app/lib/rocketchat/methods/setUser.ts +++ b/app/lib/rocketchat/methods/setUser.ts @@ -2,7 +2,7 @@ import { InteractionManager } from 'react-native'; import { setActiveUsers } from '../../../actions/activeUsers'; import { setUser } from '../../../actions/login'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; // TODO diff --git a/app/lib/rocketchat/services/connect.ts b/app/lib/rocketchat/services/connect.ts index f8f2c1f64..ad9e00f9a 100644 --- a/app/lib/rocketchat/services/connect.ts +++ b/app/lib/rocketchat/services/connect.ts @@ -11,7 +11,7 @@ import protectedFunction from '../../methods/helpers/protectedFunction'; import database from '../../database'; import { selectServerFailure } from '../../../actions/server'; import { twoFactor } from '../../../utils/twoFactor'; -import { store } from '../../auxStore'; +import { store } from '../../store/auxStore'; import { loginRequest, setLoginServices, setUser } from '../../../actions/login'; import sdk from './sdk'; import I18n from '../../../i18n'; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 2097b0f75..f82aad305 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -13,7 +13,7 @@ import { ISpotlight } from '../../../definitions/ISpotlight'; import { TEAM_TYPE } from '../../../definitions/ITeam'; import { Encryption } from '../../encryption'; import { TParams } from '../../../definitions/ILivechatEditView'; -import { store as reduxStore } from '../../auxStore'; +import { store as reduxStore } from '../../store/auxStore'; import { getDeviceToken } from '../../../notifications/push'; import { getBundleId, isIOS } from '../../../utils/deviceInfo'; import roomTypeToApiType, { RoomTypes } from '../../methods/roomTypeToApiType'; diff --git a/app/lib/rocketchat/services/sdk.ts b/app/lib/rocketchat/services/sdk.ts index d5aa3cead..fa8ec7de0 100644 --- a/app/lib/rocketchat/services/sdk.ts +++ b/app/lib/rocketchat/services/sdk.ts @@ -4,7 +4,7 @@ import isEmpty from 'lodash/isEmpty'; import { twoFactor } from '../../../utils/twoFactor'; import { useSsl } from '../../../utils/url'; -import reduxStore from '../../createStore'; +import { store as reduxStore } from '../../store/auxStore'; import { Serialized, MatchPathPattern, OperationParams, PathFor, ResultFor } from '../../../definitions/rest/helpers'; class Sdk { diff --git a/app/lib/rocketchat/services/shareExtension.ts b/app/lib/rocketchat/services/shareExtension.ts index 023cd601f..4a35c0629 100644 --- a/app/lib/rocketchat/services/shareExtension.ts +++ b/app/lib/rocketchat/services/shareExtension.ts @@ -8,7 +8,7 @@ import UserPreferences from '../../methods/userPreferences'; import database from '../../database'; import RocketChat from '..'; import { encryptionInit } from '../../../actions/encryption'; -import { store } from '../../auxStore'; +import { store } from '../../store/auxStore'; import sdk from './sdk'; export async function shareExtensionInit(server: string) { diff --git a/app/lib/appStateMiddleware.js b/app/lib/store/appStateMiddleware.ts similarity index 84% rename from app/lib/appStateMiddleware.js rename to app/lib/store/appStateMiddleware.ts index 93fdff95a..7025a8191 100644 --- a/app/lib/appStateMiddleware.js +++ b/app/lib/store/appStateMiddleware.ts @@ -1,16 +1,16 @@ // https://github.com/bamlab/redux-enhancer-react-native-appstate import { AppState } from 'react-native'; -import { APP_STATE } from '../actions/actionsTypes'; +import { APP_STATE } from '../../actions/actionsTypes'; export default () => - createStore => - (...args) => { + (createStore: any) => + (...args: any) => { const store = createStore(...args); let currentState = ''; - const handleAppStateChange = nextAppState => { + const handleAppStateChange = (nextAppState: any) => { if (nextAppState !== 'inactive') { if (currentState !== nextAppState) { let type; diff --git a/app/lib/auxStore.ts b/app/lib/store/auxStore.ts similarity index 82% rename from app/lib/auxStore.ts rename to app/lib/store/auxStore.ts index 2de3f72aa..bdb234af3 100644 --- a/app/lib/auxStore.ts +++ b/app/lib/store/auxStore.ts @@ -1,6 +1,6 @@ import { Store } from 'redux'; -import { IApplicationState } from '../definitions'; +import { IApplicationState } from '../../definitions'; // https://redux.js.org/faq/code-structure#how-can-i-use-the-redux-store-in-non-component-files export let store: Store = null as any; diff --git a/app/lib/createStore.js b/app/lib/store/index.ts similarity index 92% rename from app/lib/createStore.js rename to app/lib/store/index.ts index a9608de6c..1b3520871 100644 --- a/app/lib/createStore.js +++ b/app/lib/store/index.ts @@ -1,8 +1,8 @@ import { applyMiddleware, compose, createStore } from 'redux'; import createSagaMiddleware from 'redux-saga'; -import reducers from '../reducers'; -import sagas from '../sagas'; +import reducers from '../../reducers'; +import sagas from '../../sagas'; import applyAppStateMiddleware from './appStateMiddleware'; let sagaMiddleware; diff --git a/app/notifications/push/index.ts b/app/notifications/push/index.ts index e9ac11fba..6fced7ed3 100644 --- a/app/notifications/push/index.ts +++ b/app/notifications/push/index.ts @@ -1,6 +1,6 @@ import EJSON from 'ejson'; -import { store } from '../../lib/auxStore'; +import { store } from '../../lib/store/auxStore'; import { deepLinkingOpen } from '../../actions/deepLinking'; import { isFDroidBuild } from '../../lib/constants'; import PushNotification from './push'; diff --git a/app/notifications/push/push.ios.ts b/app/notifications/push/push.ios.ts index b9713af2a..00b107b02 100644 --- a/app/notifications/push/push.ios.ts +++ b/app/notifications/push/push.ios.ts @@ -2,7 +2,7 @@ // TODO BUMP LIB VERSION import NotificationsIOS, { NotificationAction, NotificationCategory, Notification } from 'react-native-notifications'; -import { store as reduxStore } from '../../lib/auxStore'; +import { store as reduxStore } from '../../lib/store/auxStore'; import I18n from '../../i18n'; import { INotification } from '../../definitions/INotification'; diff --git a/app/share.tsx b/app/share.tsx index 94075a830..fff29dea2 100644 --- a/app/share.tsx +++ b/app/share.tsx @@ -8,8 +8,8 @@ import { Provider } from 'react-redux'; import { getTheme, initialTheme, newThemeState, subscribeTheme, unsubscribeTheme } from './utils/theme'; import UserPreferences from './lib/methods/userPreferences'; import Navigation from './lib/navigation/shareNavigation'; -import store from './lib/createStore'; -import { initStore } from './lib/auxStore'; +import store from './lib/store'; +import { initStore } from './lib/store/auxStore'; import { closeShareExtension, shareExtensionInit } from './lib/rocketchat/services/shareExtension'; import { defaultHeader, getActiveRouteName, navigationTheme, themedHeader } from './utils/navigation'; import RocketChat from './lib/rocketchat'; diff --git a/app/utils/isReadOnly.ts b/app/utils/isReadOnly.ts index deee17d83..9e41362b5 100644 --- a/app/utils/isReadOnly.ts +++ b/app/utils/isReadOnly.ts @@ -1,5 +1,5 @@ import RocketChat from '../lib/rocketchat'; -import { store as reduxStore } from '../lib/auxStore'; +import { store as reduxStore } from '../lib/store/auxStore'; import { ISubscription } from '../definitions/ISubscription'; const canPostReadOnly = async ({ rid }: { rid: string }) => { diff --git a/app/utils/localAuthentication.ts b/app/utils/localAuthentication.ts index 35704374d..343878f1f 100644 --- a/app/utils/localAuthentication.ts +++ b/app/utils/localAuthentication.ts @@ -5,7 +5,7 @@ import { sha256 } from 'js-sha256'; import moment from 'moment'; import UserPreferences from '../lib/methods/userPreferences'; -import { store } from '../lib/auxStore'; +import { store } from '../lib/store/auxStore'; import database from '../lib/database'; import { getServerTimeSync } from '../lib/rocketchat/services/getServerTimeSync'; import {