♻️ Improve function naming and return value

This commit is contained in:
Philipp Stracker 2025-02-26 12:20:09 +01:00
parent c244f97eb0
commit 700e67eef4
No known key found for this signature in database
2 changed files with 13 additions and 8 deletions

View file

@ -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( () => {

View file

@ -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;
}; };