From e258d2cbbb21214c7288f3e9a77396f7b081e3e4 Mon Sep 17 00:00:00 2001 From: Artsiom Ostrovskiy Date: Sat, 10 Sep 2022 14:27:10 +0200 Subject: [PATCH] refactor(#1137): separate deleteLineFromPath function from the logic of the settings-routes --- src/routing/routes/main-routes.ts | 6 +++--- src/routing/routes/settings-routes.ts | 9 +++------ src/routing/routes/utils.ts | 5 +++++ 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 src/routing/routes/utils.ts diff --git a/src/routing/routes/main-routes.ts b/src/routing/routes/main-routes.ts index 8c654d7d..ec6a5b28 100644 --- a/src/routing/routes/main-routes.ts +++ b/src/routing/routes/main-routes.ts @@ -36,9 +36,9 @@ const MainRoutes: MainRoutesObject = { props: { element: withPageGuard([REGISTERED_USER])(ChatPage), children: [ - React.createElement(Route, { key: 1, index: true, element: React.createElement(Welcome) }), - React.createElement(Route, { key: 2, path: ':id', element: React.createElement(MessageList) }), - React.createElement(Route, { key: 3, path: '*', element: React.createElement(Welcome) }), + React.createElement(Route, { key: '1', index: true, element: React.createElement(Welcome) }), + React.createElement(Route, { key: '2', path: ':id', element: React.createElement(MessageList) }), + React.createElement(Route, { key: '3', path: '*', element: React.createElement(Welcome) }), ], }, }, diff --git a/src/routing/routes/settings-routes.ts b/src/routing/routes/settings-routes.ts index 33aecf73..0066c0ef 100644 --- a/src/routing/routes/settings-routes.ts +++ b/src/routing/routes/settings-routes.ts @@ -17,6 +17,9 @@ import { import { SettingsRoutesEnum, SettingsRoutesObject } from '@routing/routing.types'; import withPageGuard from '@routing/with-page-guard'; +import { deleteLineFromPath } from './utils'; + +/* ------------- LazyLoading ------------- */ const ProfileSettings = LazyPreload(() => import('@pages/settings/edit-profile')); const NotificationsSettings = LazyPreload(() => import('@pages/settings/notifications-settings')); const LanguageSettings = LazyPreload(() => import('@pages/settings/language-settings')); @@ -25,12 +28,6 @@ const AppearanceSettings = LazyPreload(() => import('@pages/settings/appearance' const PrivacySecuritySettings = LazyPreload(() => import('@pages/settings/privacy-security')); const AudioVideoSettings = LazyPreload(() => import('@pages/settings/audio-video')); -const deleteLineFromPath = (path: string, line: string) => { - const preparedPath = path.split(''); - preparedPath.splice(path.indexOf(line), line.length); - return preparedPath.join(''); -}; - /* ------------- Routes ------------- */ const SettingsRoutes: SettingsRoutesObject = { [SettingsRoutesEnum.PROFILE_SETTINGS]: { diff --git a/src/routing/routes/utils.ts b/src/routing/routes/utils.ts new file mode 100644 index 00000000..985ac644 --- /dev/null +++ b/src/routing/routes/utils.ts @@ -0,0 +1,5 @@ +export const deleteLineFromPath = (path: string, line: string) => { + const preparedPath = path.split(''); + preparedPath.splice(path.indexOf(line), line.length); + return preparedPath.join(''); +};