mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
♻️ Improve function naming and return value
This commit is contained in:
parent
c244f97eb0
commit
700e67eef4
2 changed files with 13 additions and 8 deletions
|
@ -6,7 +6,7 @@ import SpinnerOverlay from './ReusableComponents/SpinnerOverlay';
|
||||||
import SendOnlyMessage from './Screens/SendOnlyMessage';
|
import SendOnlyMessage from './Screens/SendOnlyMessage';
|
||||||
import OnboardingScreen from './Screens/Onboarding';
|
import OnboardingScreen from './Screens/Onboarding';
|
||||||
import SettingsScreen from './Screens/Settings';
|
import SettingsScreen from './Screens/Settings';
|
||||||
import { cleanBrowserUrl, getQuery } from '../utils/navigation';
|
import { getQuery, cleanUrlQueryParams } from '../utils/navigation';
|
||||||
|
|
||||||
const SettingsApp = () => {
|
const SettingsApp = () => {
|
||||||
const { isReady: onboardingIsReady, completed: onboardingCompleted } =
|
const { isReady: onboardingIsReady, completed: onboardingCompleted } =
|
||||||
|
@ -35,10 +35,15 @@ const SettingsApp = () => {
|
||||||
const [ activePanel, setActivePanel ] = useState( getQuery().panel );
|
const [ activePanel, setActivePanel ] = useState( getQuery().panel );
|
||||||
|
|
||||||
const removeUnsupportedArgs = () => {
|
const removeUnsupportedArgs = () => {
|
||||||
if ( cleanBrowserUrl( [ 'page', 'tab', 'section' ] ) ) {
|
const urlWasCleaned = cleanUrlQueryParams( [
|
||||||
return;
|
'page',
|
||||||
|
'tab',
|
||||||
|
'section',
|
||||||
|
] );
|
||||||
|
|
||||||
|
if ( urlWasCleaned ) {
|
||||||
|
setActivePanel( '' );
|
||||||
}
|
}
|
||||||
setActivePanel( '' );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Content = useMemo( () => {
|
const Content = useMemo( () => {
|
||||||
|
|
|
@ -61,9 +61,9 @@ export const filterObjectKeys = ( obj, allowedKeys ) => {
|
||||||
* Clean the browser URL by removing unsupported query parameters.
|
* Clean the browser URL by removing unsupported query parameters.
|
||||||
*
|
*
|
||||||
* @param {string[]} supportedArgs An array of supported query parameter names.
|
* @param {string[]} supportedArgs An array of supported query parameter names.
|
||||||
* @return {boolean} Returns true if the URL was already clean, false if it was cleaned.
|
* @return {boolean} Returns true if the URL was modified (cleaned), false if nothing changed.
|
||||||
*/
|
*/
|
||||||
export const cleanBrowserUrl = ( supportedArgs ) => {
|
export const cleanUrlQueryParams = ( supportedArgs ) => {
|
||||||
const currentQuery = getQuery();
|
const currentQuery = getQuery();
|
||||||
const cleanedQuery = filterObjectKeys( currentQuery, supportedArgs );
|
const cleanedQuery = filterObjectKeys( currentQuery, supportedArgs );
|
||||||
|
|
||||||
|
@ -71,10 +71,10 @@ export const cleanBrowserUrl = ( supportedArgs ) => {
|
||||||
Object.keys( cleanedQuery ).length ===
|
Object.keys( cleanedQuery ).length ===
|
||||||
Object.keys( currentQuery ).length;
|
Object.keys( currentQuery ).length;
|
||||||
|
|
||||||
if ( ! isUrlClean ) {
|
if ( isUrlClean ) {
|
||||||
updateQueryString( cleanedQuery, true );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateQueryString( cleanedQuery, true );
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue