wip: migrate fixed consts to RootEnum
This commit is contained in:
parent
701361a686
commit
ba2931665b
|
@ -6,7 +6,7 @@ import { connect } from 'react-redux';
|
|||
import { SetUsernameStackParamList, StackParamList } from './navigationTypes';
|
||||
import Navigation from './lib/Navigation';
|
||||
import { defaultHeader, getActiveRouteName, navigationTheme } from './utils/navigation';
|
||||
import { ROOT_INSIDE, ROOT_LOADING, ROOT_OUTSIDE, ROOT_SET_USERNAME } from './actions/app';
|
||||
import { RootEnum } from './definitions';
|
||||
// Stacks
|
||||
import AuthLoadingView from './views/AuthLoadingView';
|
||||
// SetUsername Stack
|
||||
|
@ -56,13 +56,13 @@ const App = React.memo(({ root, isMasterDetail }: { root: string; isMasterDetail
|
|||
}}>
|
||||
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
|
||||
<>
|
||||
{root === ROOT_LOADING ? <Stack.Screen name='AuthLoading' component={AuthLoadingView} /> : null}
|
||||
{root === ROOT_OUTSIDE ? <Stack.Screen name='OutsideStack' component={OutsideStack} /> : null}
|
||||
{root === ROOT_INSIDE && isMasterDetail ? (
|
||||
{root === RootEnum.ROOT_LOADING ? <Stack.Screen name='AuthLoading' component={AuthLoadingView} /> : null}
|
||||
{root === RootEnum.ROOT_OUTSIDE ? <Stack.Screen name='OutsideStack' component={OutsideStack} /> : null}
|
||||
{root === RootEnum.ROOT_INSIDE && isMasterDetail ? (
|
||||
<Stack.Screen name='MasterDetailStack' component={MasterDetailStack} />
|
||||
) : null}
|
||||
{root === ROOT_INSIDE && !isMasterDetail ? <Stack.Screen name='InsideStack' component={InsideStack} /> : null}
|
||||
{root === ROOT_SET_USERNAME ? <Stack.Screen name='SetUsernameStack' component={SetUsernameStack} /> : null}
|
||||
{root === RootEnum.ROOT_INSIDE && !isMasterDetail ? <Stack.Screen name='InsideStack' component={InsideStack} /> : null}
|
||||
{root === RootEnum.ROOT_SET_USERNAME ? <Stack.Screen name='SetUsernameStack' component={SetUsernameStack} /> : null}
|
||||
</>
|
||||
</Stack.Navigator>
|
||||
</NavigationContainer>
|
||||
|
|
|
@ -3,11 +3,6 @@ import { Action } from 'redux';
|
|||
import { RootEnum } from '../definitions';
|
||||
import { APP } from './actionsTypes';
|
||||
|
||||
export const ROOT_OUTSIDE = 'outside';
|
||||
export const ROOT_INSIDE = 'inside';
|
||||
export const ROOT_LOADING = 'loading';
|
||||
export const ROOT_SET_USERNAME = 'setUsername';
|
||||
|
||||
interface IAppStart extends Action {
|
||||
root: RootEnum;
|
||||
text?: string;
|
||||
|
|
|
@ -8,11 +8,12 @@ import { inviteLinksRequest, inviteLinksSetToken } from '../actions/inviteLinks'
|
|||
import database from '../lib/database';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
import EventEmitter from '../utils/events';
|
||||
import { ROOT_INSIDE, ROOT_OUTSIDE, appInit, appStart } from '../actions/app';
|
||||
import { appInit, appStart } from '../actions/app';
|
||||
import { localAuthenticate } from '../utils/localAuthentication';
|
||||
import { goRoom } from '../utils/goRoom';
|
||||
import { loginRequest } from '../actions/login';
|
||||
import log from '../utils/log';
|
||||
import { RootEnum } from '../definitions';
|
||||
|
||||
const roomTypes = {
|
||||
channel: 'c',
|
||||
|
@ -41,7 +42,7 @@ const popToRoot = function popToRoot({ isMasterDetail }) {
|
|||
};
|
||||
|
||||
const navigate = function* navigate({ params }) {
|
||||
yield put(appStart({ root: ROOT_INSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
|
||||
if (params.path || params.rid) {
|
||||
let type;
|
||||
let name;
|
||||
|
@ -192,7 +193,7 @@ const handleOpen = function* handleOpen({ params }) {
|
|||
yield fallbackNavigation();
|
||||
return;
|
||||
}
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
yield put(serverInitAdd(server));
|
||||
yield delay(1000);
|
||||
EventEmitter.emit('NewServer', { server: host });
|
||||
|
|
|
@ -9,7 +9,8 @@ import RocketChat from '../lib/rocketchat';
|
|||
import log from '../utils/log';
|
||||
import database from '../lib/database';
|
||||
import { localAuthenticate } from '../utils/localAuthentication';
|
||||
import { ROOT_OUTSIDE, appReady, appStart } from '../actions/app';
|
||||
import { appReady, appStart } from '../actions/app';
|
||||
import { RootEnum } from '../definitions';
|
||||
|
||||
export const initLocalSettings = function* initLocalSettings() {
|
||||
const sortPreferences = yield RocketChat.getSortPreferences();
|
||||
|
@ -22,7 +23,7 @@ const restore = function* restore() {
|
|||
let userId = yield UserPreferences.getStringAsync(`${RocketChat.TOKEN_KEY}-${server}`);
|
||||
|
||||
if (!server) {
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
} else if (!userId) {
|
||||
const serversDB = database.servers;
|
||||
const serversCollection = serversDB.get('servers');
|
||||
|
@ -38,7 +39,7 @@ const restore = function* restore() {
|
|||
}
|
||||
}
|
||||
}
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
} else {
|
||||
const serversDB = database.servers;
|
||||
const serverCollections = serversDB.get('servers');
|
||||
|
@ -56,7 +57,7 @@ const restore = function* restore() {
|
|||
yield put(appReady({}));
|
||||
} catch (e) {
|
||||
log(e);
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
|||
import { Q } from '@nozbe/watermelondb';
|
||||
|
||||
import * as types from '../actions/actionsTypes';
|
||||
import { ROOT_INSIDE, ROOT_LOADING, ROOT_OUTSIDE, ROOT_SET_USERNAME, appStart } from '../actions/app';
|
||||
import { appStart } from '../actions/app';
|
||||
import { selectServerRequest, serverFinishAdd } from '../actions/server';
|
||||
import { loginFailure, loginSuccess, logout, setUser } from '../actions/login';
|
||||
import { roomsRequest } from '../actions/rooms';
|
||||
|
@ -20,6 +20,7 @@ import { encryptionInit, encryptionStop } from '../actions/encryption';
|
|||
import UserPreferences from '../lib/userPreferences';
|
||||
import { inquiryRequest, inquiryReset } from '../ee/omnichannel/actions/inquiry';
|
||||
import { isOmnichannelStatusAvailable } from '../ee/omnichannel/lib';
|
||||
import { RootEnum } from '../definitions';
|
||||
|
||||
const getServer = state => state.server.server;
|
||||
const loginWithPasswordCall = args => RocketChat.loginWithPassword(args);
|
||||
|
@ -38,7 +39,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
|
|||
if (!result.username) {
|
||||
yield put(serverFinishAdd());
|
||||
yield put(setUser(result));
|
||||
yield put(appStart({ root: ROOT_SET_USERNAME }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_SET_USERNAME }));
|
||||
} else {
|
||||
const server = yield select(getServer);
|
||||
yield localAuthenticate(server);
|
||||
|
@ -167,7 +168,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
|
|||
yield put(setUser(user));
|
||||
EventEmitter.emit('connected');
|
||||
|
||||
yield put(appStart({ root: ROOT_INSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
|
||||
const inviteLinkToken = yield select(state => state.inviteLinks.token);
|
||||
if (inviteLinkToken) {
|
||||
yield put(inviteLinksRequest(inviteLinkToken));
|
||||
|
@ -179,7 +180,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
|
|||
|
||||
const handleLogout = function* handleLogout({ forcedByServer }) {
|
||||
yield put(encryptionStop());
|
||||
yield put(appStart({ root: ROOT_LOADING, text: I18n.t('Logging_out') }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Logging_out') }));
|
||||
const server = yield select(getServer);
|
||||
if (server) {
|
||||
try {
|
||||
|
@ -187,7 +188,7 @@ const handleLogout = function* handleLogout({ forcedByServer }) {
|
|||
|
||||
// if the user was logged out by the server
|
||||
if (forcedByServer) {
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
showErrorAlert(I18n.t('Logged_out_by_server'), I18n.t('Oops'));
|
||||
yield delay(300);
|
||||
EventEmitter.emit('NewServer', { server });
|
||||
|
@ -209,10 +210,10 @@ const handleLogout = function* handleLogout({ forcedByServer }) {
|
|||
}
|
||||
}
|
||||
// if there's no servers, go outside
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
}
|
||||
} catch (e) {
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@ import database from '../lib/database';
|
|||
import log, { logServerVersion } from '../utils/log';
|
||||
import I18n from '../i18n';
|
||||
import { BASIC_AUTH_KEY, setBasicAuth } from '../utils/fetch';
|
||||
import { ROOT_INSIDE, ROOT_OUTSIDE, appStart } from '../actions/app';
|
||||
import { appStart } from '../actions/app';
|
||||
import UserPreferences from '../lib/userPreferences';
|
||||
import { encryptionStop } from '../actions/encryption';
|
||||
import SSLPinning from '../utils/sslPinning';
|
||||
import { inquiryReset } from '../ee/omnichannel/actions/inquiry';
|
||||
import { RootEnum } from '../definitions';
|
||||
|
||||
const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
|
||||
try {
|
||||
|
@ -111,10 +112,10 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
|
|||
yield put(clearSettings());
|
||||
yield RocketChat.connect({ server, user, logoutOnError: true });
|
||||
yield put(setUser(user));
|
||||
yield put(appStart({ root: ROOT_INSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
|
||||
} else {
|
||||
yield RocketChat.connect({ server });
|
||||
yield put(appStart({ root: ROOT_OUTSIDE }));
|
||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||
}
|
||||
|
||||
// We can't use yield here because fetch of Settings & Custom Emojis is slower
|
||||
|
|
|
@ -5,11 +5,11 @@ import { setBadgeCount } from '../notifications/push';
|
|||
import log from '../utils/log';
|
||||
import { localAuthenticate, saveLastLocalAuthenticationSession } from '../utils/localAuthentication';
|
||||
import { APP_STATE } from '../actions/actionsTypes';
|
||||
import { ROOT_OUTSIDE } from '../actions/app';
|
||||
import { RootEnum } from '../definitions';
|
||||
|
||||
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
||||
const appRoot = yield select(state => state.app.root);
|
||||
if (appRoot === ROOT_OUTSIDE) {
|
||||
if (appRoot === RootEnum.ROOT_OUTSIDE) {
|
||||
return;
|
||||
}
|
||||
const login = yield select(state => state.login);
|
||||
|
@ -29,7 +29,7 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
|||
|
||||
const appHasComeBackToBackground = function* appHasComeBackToBackground() {
|
||||
const appRoot = yield select(state => state.app.root);
|
||||
if (appRoot === ROOT_OUTSIDE) {
|
||||
if (appRoot === RootEnum.ROOT_OUTSIDE) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -13,10 +13,11 @@ import StatusBar from '../../containers/StatusBar';
|
|||
import * as List from '../../containers/List';
|
||||
import { themes } from '../../constants/colors';
|
||||
import { withTheme } from '../../theme';
|
||||
import { ROOT_INSIDE, ROOT_LOADING, appStart as appStartAction } from '../../actions/app';
|
||||
import { appStart as appStartAction } from '../../actions/app';
|
||||
import { getUserSelector } from '../../selectors/login';
|
||||
import database from '../../lib/database';
|
||||
import SafeAreaView from '../../containers/SafeAreaView';
|
||||
import { RootEnum } from '../../definitions';
|
||||
|
||||
interface ILanguageViewProps {
|
||||
user: {
|
||||
|
@ -73,7 +74,7 @@ class LanguageView extends React.Component<ILanguageViewProps, ILanguageViewStat
|
|||
|
||||
const shouldRestart = isRTL(language) || isRTL(user.language);
|
||||
|
||||
await appStart({ root: ROOT_LOADING, text: I18n.t('Change_language_loading') });
|
||||
await appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Change_language_loading') });
|
||||
|
||||
// shows loading for at least 300ms
|
||||
await Promise.all([this.changeLanguage(language), new Promise(resolve => setTimeout(resolve, 300))]);
|
||||
|
@ -81,7 +82,7 @@ class LanguageView extends React.Component<ILanguageViewProps, ILanguageViewStat
|
|||
if (shouldRestart) {
|
||||
await RNRestart.Restart();
|
||||
} else {
|
||||
await appStart({ root: ROOT_INSIDE });
|
||||
await appStart({ root: RootEnum.ROOT_INSIDE });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import * as List from '../../containers/List';
|
|||
import Button from '../../containers/Button';
|
||||
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
||||
import { selectServerRequest as selectServerRequestAction, serverInitAdd as serverInitAddAction } from '../../actions/server';
|
||||
import { appStart as appStartAction, ROOT_OUTSIDE } from '../../actions/app';
|
||||
import { appStart as appStartAction } from '../../actions/app';
|
||||
import RocketChat from '../../lib/rocketchat';
|
||||
import I18n from '../../i18n';
|
||||
import EventEmitter from '../../utils/events';
|
||||
|
@ -24,6 +24,8 @@ import log, { events, logEvent } from '../../utils/log';
|
|||
import { headerHeight } from '../../containers/Header';
|
||||
import { goRoom } from '../../utils/goRoom';
|
||||
import UserPreferences from '../../lib/userPreferences';
|
||||
import { RootEnum } from '../../definitions';
|
||||
|
||||
import styles from './styles';
|
||||
|
||||
const ROW_HEIGHT = 68;
|
||||
|
@ -110,7 +112,7 @@ class ServerDropdown extends Component {
|
|||
navToNewServer = previousServer => {
|
||||
const { appStart, initAdd } = this.props;
|
||||
batch(() => {
|
||||
appStart({ root: ROOT_OUTSIDE });
|
||||
appStart({ root: RootEnum.ROOT_OUTSIDE });
|
||||
initAdd(previousServer);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -50,6 +50,8 @@ import { E2E_BANNER_TYPE } from '../../lib/encryption/constants';
|
|||
import { getInquiryQueueSelector } from '../../ee/omnichannel/selectors/inquiry';
|
||||
import { changeLivechatStatus, isOmnichannelStatusAvailable } from '../../ee/omnichannel/lib';
|
||||
import { DISPLAY_MODE_CONDENSED } from '../../constants/constantDisplayMode';
|
||||
import { RootEnum } from '../../definitions';
|
||||
|
||||
import styles from './styles';
|
||||
import ServerDropdown from './ServerDropdown';
|
||||
import ListHeader from './ListHeader';
|
||||
|
@ -862,7 +864,7 @@ class RoomsListView extends React.Component {
|
|||
}
|
||||
} else if (handleCommandAddNewServer(event)) {
|
||||
batch(() => {
|
||||
appStart({ root: ROOT_OUTSIDE });
|
||||
appStart({ root: RootEnum.ROOT_OUTSIDE });
|
||||
initAdd(server);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,12 +23,13 @@ import { withTheme } from '../../theme';
|
|||
import SidebarView from '../SidebarView';
|
||||
import { LISTENER } from '../../containers/Toast';
|
||||
import EventEmitter from '../../utils/events';
|
||||
import { ROOT_LOADING, appStart as appStartAction } from '../../actions/app';
|
||||
import { appStart as appStartAction } from '../../actions/app';
|
||||
import { onReviewPress } from '../../utils/review';
|
||||
import SafeAreaView from '../../containers/SafeAreaView';
|
||||
import database from '../../lib/database';
|
||||
import { isFDroidBuild } from '../../constants/environment';
|
||||
import { getUserSelector } from '../../selectors/login';
|
||||
import { RootEnum } from '../../definitions';
|
||||
|
||||
interface ISettingsViewProps {
|
||||
navigation: StackNavigationProp<SettingsStackParamList, 'SettingsView'>;
|
||||
|
@ -108,7 +109,7 @@ class SettingsView extends React.Component<ISettingsViewProps, any> {
|
|||
appStart,
|
||||
selectServerRequest
|
||||
} = this.props;
|
||||
appStart({ root: ROOT_LOADING, text: I18n.t('Clear_cache_loading') });
|
||||
appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Clear_cache_loading') });
|
||||
await RocketChat.clearCache({ server });
|
||||
await FastImage.clearMemoryCache();
|
||||
await FastImage.clearDiskCache();
|
||||
|
|
Loading…
Reference in New Issue