Skip to content

Commit

Permalink
refactor: refactored code according to requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir committed Nov 13, 2024
1 parent dabf556 commit 1b6612c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
17 changes: 9 additions & 8 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
initialize,
mergeConfig,
subscribe,
getConfig,
} from '@edx/frontend-platform';
import {
AppProvider,
Expand All @@ -26,19 +27,19 @@ import Head from './head/Head';

import AppRoutes from './routes/AppRoutes';

if (process.env.ENABLE_NEW_PROFILE_VIEW === 'true') {
import('./index-v2.scss');
} else {
import('./index.scss');
}

subscribe(APP_READY, () => {
subscribe(APP_READY, async () => {
const isNewProfileEnabled = getConfig().ENABLE_NEW_PROFILE_VIEW === 'true';

Check warning on line 31 in src/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/index.jsx#L30-L31

Added lines #L30 - L31 were not covered by tests
if (isNewProfileEnabled) {
await import('./index-v2.scss');
} else {
await import('./index.scss');

Check warning on line 35 in src/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/index.jsx#L33-L35

Added lines #L33 - L35 were not covered by tests
}
ReactDOM.render(
<AppProvider store={configureStore()}>
<Head />
<Header />
<main id="main">
<AppRoutes />
<AppRoutes isNewProfileEnabled={isNewProfileEnabled} />
</main>
<FooterSlot />
</AppProvider>,
Expand Down
29 changes: 19 additions & 10 deletions src/routes/AppRoutes.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
AuthenticatedPageRoute,
PageWrap,
Expand All @@ -7,17 +8,25 @@ import { Routes, Route } from 'react-router-dom';
import { ProfilePage, NotFoundPage } from '../profile';
import { ProfilePage as NewProfilePage, NotFoundPage as NewNotFoundPage } from '../profile-v2';

const isNewProfileEnabled = process.env.ENABLE_NEW_PROFILE_VIEW === 'true';
const AppRoutes = ({ isNewProfileEnabled }) => {
const SelectedProfilePage = isNewProfileEnabled ? NewProfilePage : ProfilePage;
const SelectedNotFoundPage = isNewProfileEnabled ? NewNotFoundPage : NotFoundPage;

const SelectedProfilePage = isNewProfileEnabled ? NewProfilePage : ProfilePage;
const SelectedNotFoundPage = isNewProfileEnabled ? NewNotFoundPage : NotFoundPage;
return (
<Routes>
<Route path="/u/:username" element={<AuthenticatedPageRoute><SelectedProfilePage /></AuthenticatedPageRoute>} />
<Route path="/notfound" element={<PageWrap><SelectedNotFoundPage /></PageWrap>} />
<Route path="*" element={<PageWrap><SelectedNotFoundPage /></PageWrap>} />
</Routes>
);
};

const AppRoutes = () => (
<Routes>
<Route path="/u/:username" element={<AuthenticatedPageRoute><SelectedProfilePage /></AuthenticatedPageRoute>} />
<Route path="/notfound" element={<PageWrap><SelectedNotFoundPage /></PageWrap>} />
<Route path="*" element={<PageWrap><SelectedNotFoundPage /></PageWrap>} />
</Routes>
);
AppRoutes.propTypes = {
isNewProfileEnabled: PropTypes.bool,
};

AppRoutes.defaultProps = {
isNewProfileEnabled: null,
};

export default AppRoutes;

0 comments on commit 1b6612c

Please sign in to comment.