Skip to content

Commit c8a2c78

Browse files
committed
Remove unwanted imports and use of hooks
We don't want to use the `useNavigate` and `useLocation` hooks as of yet. These will be used in subsequent refactor.
1 parent c5ca1f6 commit c8a2c78

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

app/src/__stories__/StoryWrapper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { CSSProperties, useMemo } from 'react';
2-
import { BrowserRouter } from 'react-router-dom';
2+
import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
33
import { observer } from 'mobx-react-lite';
44
import { BalanceMode, Unit } from 'util/constants';
55
import { AuthenticationError } from 'util/errors';
@@ -70,13 +70,13 @@ const StoryWrapper: React.FC<{
7070
return (
7171
<StoreProvider store={store}>
7272
<ThemeProvider>
73-
<BrowserRouter>
73+
<HistoryRouter history={store.router.history}>
7474
{/* modify the bg styles so it isn't too big in docs mode */}
7575
<Background style={{ minHeight: 'inherit', height: '100%' }}>
7676
{/* render the Story after the store has been initialized */}
7777
{store.initialized ? <div style={style}>{children}</div> : null}
7878
</Background>
79-
</BrowserRouter>
79+
</HistoryRouter>
8080
<AlertContainer />
8181
</ThemeProvider>
8282
</StoreProvider>

app/src/components/layout/Layout.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,11 @@ const Styled = {
111111

112112
export const Layout: React.FC = ({ children }) => {
113113
const { settingsStore, appView } = useStore();
114-
const location = useLocation();
115-
const fullWidth = location.pathname === `/pool`;
116114

117115
const { Container, Hamburger, Aside, Content, Fluid } = Styled;
118116
return (
119117
<Background>
120-
<Container fullWidth={fullWidth}>
118+
<Container fullWidth={appView.fullWidth}>
121119
<Hamburger
122120
collapsed={!settingsStore.sidebarVisible}
123121
onClick={settingsStore.toggleSidebar}
@@ -127,7 +125,7 @@ export const Layout: React.FC = ({ children }) => {
127125
<Aside collapsed={!settingsStore.sidebarVisible}>
128126
<Sidebar />
129127
</Aside>
130-
<Content collapsed={!settingsStore.sidebarVisible} fullWidth={fullWidth}>
128+
<Content collapsed={!settingsStore.sidebarVisible} fullWidth={appView.fullWidth}>
131129
<Fluid className="container-fluid">{children}</Fluid>
132130
</Content>
133131
</Container>

app/src/components/settings/GeneralSettings.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useStore } from 'store';
88
import { HeaderFour } from 'components/base';
99
import PageHeader from 'components/common/PageHeader';
1010
import SettingItem from './SettingItem';
11-
import { useNavigate } from 'react-router-dom';
1211

1312
const Styled = {
1413
Wrapper: styled.section``,
@@ -19,16 +18,11 @@ const Styled = {
1918

2019
const GeneralSettings: React.FC = () => {
2120
const { l } = usePrefixedTranslation('cmps.settings.GeneralSettings');
22-
const { appView, log, nodeStore, settingsStore } = useStore();
23-
const navigate = useNavigate();
24-
const navigateTo = (path: string) => {
25-
log.info('Switch to Setting screen', path);
26-
navigate(`/settings/${path}`);
27-
};
21+
const { appView, nodeStore, settingsStore } = useStore();
2822

29-
const handleUnit = useCallback(() => navigateTo('unit'), [appView]);
30-
const handleBalance = useCallback(() => navigateTo('balance'), [appView]);
31-
const handleExplorers = useCallback(() => navigateTo('explorers'), [appView]);
23+
const handleUnit = useCallback(() => appView.showSettings('unit'), [appView]);
24+
const handleBalance = useCallback(() => appView.showSettings('balance'), [appView]);
25+
const handleExplorers = useCallback(() => appView.showSettings('explorers'), [appView]);
3226
const handleCopyPubkey = useCallback(() => nodeStore.copy('pubkey'), [nodeStore]);
3327
const handleCopyAlias = useCallback(() => nodeStore.copy('alias'), [nodeStore]);
3428
const handleCopyUrl = useCallback(() => nodeStore.copy('url'), [nodeStore]);

app/src/store/views/appView.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { AuthenticationError } from 'util/errors';
66
import { prefixTranslation } from 'util/translate';
77
import { Store } from 'store';
88
import { PUBLIC_URL } from '../../config';
9-
import { useLocation, useNavigate } from 'react-router-dom';
109

1110
const { l } = prefixTranslation('stores.appView');
1211

@@ -29,6 +28,10 @@ export default class AppView {
2928
this._store = store;
3029
}
3130

31+
get fullWidth() {
32+
return this._store.router.location.pathname === `${PUBLIC_URL}/pool`;
33+
}
34+
3235
/** navigate to the specified route */
3336
goTo(route: string) {
3437
if (this._store.router.location.pathname !== route) {

app/src/util/tests/renderWithProviders.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Suspense } from 'react';
2-
import { MemoryRouter, unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
2+
import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
33
import { fireEvent, render } from '@testing-library/react';
44
import { createStore, Store, StoreProvider } from 'store';
55
import AlertContainer from 'components/common/AlertContainer';

0 commit comments

Comments
 (0)