2021-11-11 14:32:56 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-06-16 09:49:07 +00:00
|
|
|
import { toState } from '../../base/redux';
|
|
|
|
import { isWelcomePageEnabled } from '../../welcome/functions';
|
|
|
|
import { _sendReadyToClose } from '../external-api/functions';
|
|
|
|
|
|
|
|
import { screen } from './routes';
|
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
export const rootNavigationRef = React.createRef();
|
|
|
|
|
2022-06-16 09:49:07 +00:00
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
/**
|
|
|
|
* User defined navigation action included inside the reference to the container.
|
|
|
|
*
|
|
|
|
* @param {string} name - Destination name of the route that has been defined somewhere.
|
|
|
|
* @param {Object} params - Params to pass to the destination route.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-07-11 12:30:37 +00:00
|
|
|
export function navigateRoot(name: string, params?: Object) {
|
2021-11-11 14:32:56 +00:00
|
|
|
return rootNavigationRef.current?.navigate(name, params);
|
|
|
|
}
|
|
|
|
|
2022-06-16 09:49:07 +00:00
|
|
|
/**
|
|
|
|
* User defined navigation action included inside the reference to the container.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function goBack() {
|
|
|
|
return rootNavigationRef.current?.goBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates back to Welcome page, if it's available.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
|
|
|
|
* @param {Function} dispatch - Redux dispatch function.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
export function goBackToRoot(stateful: Function | Object, dispatch: Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
|
|
|
|
if (isWelcomePageEnabled(state)) {
|
|
|
|
navigateRoot(screen.root);
|
|
|
|
} else {
|
|
|
|
// For JitsiSDK, WelcomePage is not available
|
|
|
|
_sendReadyToClose(dispatch);
|
|
|
|
}
|
|
|
|
}
|