Skip to content

Commit 1671f7d

Browse files
committed
Merge branch 'frontend-cleanup-sidebar'
2 parents 36e4eac + 7ea9cb3 commit 1671f7d

File tree

6 files changed

+20
-36
lines changed

6 files changed

+20
-36
lines changed

frontends/web/src/components/layout/header.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const Header = ({
3535
}: Props) => {
3636
const { t } = useTranslation();
3737

38-
const { guideShown, guideExists, toggleGuide, toggleSidebar, sidebarStatus } = useContext(AppContext);
38+
const { guideShown, guideExists, toggleGuide, toggleSidebar } = useContext(AppContext);
3939

4040
const toggle = (e: React.SyntheticEvent) => {
4141
e.preventDefault();
@@ -45,9 +45,8 @@ export const Header = ({
4545
return false;
4646
};
4747

48-
4948
return (
50-
<div className={[style.container, sidebarStatus ? style[sidebarStatus] : ''].join(' ')}>
49+
<div className={style.container}>
5150
<div className={style.header}>
5251
<div className={`hide-on-small ${style.sidebarToggler} ${hideSidebarToggler ? style.hideSidebarToggler : ''}`} onClick={toggleSidebar}>
5352
<MenuDark className="show-in-lightmode" />

frontends/web/src/components/sidebar/sidebar.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ a.sidebarActive .single img,
198198
}
199199

200200
@media (min-width: 1200px) {
201-
.sidebarContainer:not(.forceHide) .sidebar {
201+
.sidebar {
202202
position: relative;
203203
margin-left: 0;
204204
width: var(--sidebar-width-large);

frontends/web/src/components/sidebar/sidebar.tsx

+16-20
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const Sidebar = ({
8181
const { t } = useTranslation();
8282
const { pathname } = useLocation();
8383
const [ canUpgrade, setCanUpgrade ] = useState(false);
84-
const { activeSidebar, sidebarStatus, toggleSidebar } = useContext(AppContext);
84+
const { activeSidebar, toggleSidebar } = useContext(AppContext);
8585

8686
const deviceIDs: string[] = Object.keys(devices);
8787

@@ -118,30 +118,27 @@ const Sidebar = ({
118118

119119
const handleTouchMove = (event: TouchEvent) => {
120120
if (
121-
sidebarStatus !== 'forceHidden'
122-
&& event.changedTouches
121+
event.changedTouches
123122
&& event.changedTouches.length
124123
) {
125124
swipe.active = true;
126125
}
127126
};
128127

129128
const handleTouchEnd = (event: TouchEvent) => {
130-
if (sidebarStatus !== 'forceHidden') {
131-
const touch = event.changedTouches[0];
132-
const travelX = Math.abs(touch.clientX - swipe.x);
133-
const travelY = Math.abs(touch.clientY - swipe.y);
134-
const validSwipe = window.innerWidth <= 901 && swipe.active && travelY < 100 && travelX > 70;
135-
if (
136-
(!activeSidebar && validSwipe && swipe.x < 60)
137-
|| (activeSidebar && validSwipe && swipe.x > 230)
138-
) {
139-
toggleSidebar();
140-
}
141-
swipe.x = 0;
142-
swipe.y = 0;
143-
swipe.active = false;
129+
const touch = event.changedTouches[0];
130+
const travelX = Math.abs(touch.clientX - swipe.x);
131+
const travelY = Math.abs(touch.clientY - swipe.y);
132+
const validSwipe = window.innerWidth <= 901 && swipe.active && travelY < 100 && travelX > 70;
133+
if (
134+
(!activeSidebar && validSwipe && swipe.x < 60)
135+
|| (activeSidebar && validSwipe && swipe.x > 230)
136+
) {
137+
toggleSidebar();
144138
}
139+
swipe.x = 0;
140+
swipe.y = 0;
141+
swipe.active = false;
145142
};
146143

147144
document.addEventListener('touchstart', handleTouchStart);
@@ -152,7 +149,7 @@ const Sidebar = ({
152149
document.removeEventListener('touchmove', handleTouchMove);
153150
document.removeEventListener('touchend', handleTouchEnd);
154151
};
155-
}, [activeSidebar, sidebarStatus, toggleSidebar]);
152+
}, [activeSidebar, toggleSidebar]);
156153

157154
const keystores = useKeystores();
158155

@@ -163,12 +160,11 @@ const Sidebar = ({
163160
}
164161
};
165162

166-
const hidden = sidebarStatus === 'forceHidden';
167163
const accountsByKeystore = getAccountsByKeystore(accounts);
168164
const userInSpecificAccountExchangePage = (pathname.startsWith('/exchange'));
169165

170166
return (
171-
<div className={[style.sidebarContainer, hidden ? style.forceHide : ''].join(' ')}>
167+
<div className={style.sidebarContainer}>
172168
<div key="overlay" className={[style.sidebarOverlay, activeSidebar ? style.active : ''].join(' ')} onClick={toggleSidebar}></div>
173169
<nav className={[style.sidebar, activeSidebar ? style.forceShow : ''].join(' ')}>
174170
<div key="app-logo" className={style.sidebarLogoContainer}>

frontends/web/src/contexts/AppContext.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import { Dispatch, SetStateAction, createContext } from 'react';
1818

19-
export type TSidebarStatus = '' | 'forceHidden'
2019
export type TChartDisplay = 'week' | 'month' | 'year' | 'all';
2120

2221
type AppContextProps = {
@@ -27,12 +26,10 @@ type AppContextProps = {
2726
isTesting: boolean;
2827
isDevServers: boolean;
2928
nativeLocale: string;
30-
sidebarStatus: TSidebarStatus;
3129
firmwareUpdateDialogOpen: boolean;
3230
chartDisplay: TChartDisplay;
3331
setActiveSidebar: Dispatch<SetStateAction<boolean>>;
3432
setGuideExists: Dispatch<SetStateAction<boolean>>;
35-
setSidebarStatus: Dispatch<SetStateAction<TSidebarStatus>>;
3633
setHideAmounts: Dispatch<SetStateAction<boolean>>;
3734
setChartDisplay: Dispatch<SetStateAction<TChartDisplay>>;
3835
setFirmwareUpdateDialogOpen: Dispatch<SetStateAction<boolean>>;

frontends/web/src/contexts/AppProvider.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { useDefault } from '@/hooks/default';
2222
import { getNativeLocale } from '@/api/nativelocale';
2323
import { getDevServers, getTesting } from '@/api/backend';
2424
import { i18nextFormat } from '@/i18n/utils';
25-
import type { TChartDisplay, TSidebarStatus } from './AppContext';
25+
import type { TChartDisplay } from './AppContext';
2626

2727
type TProps = {
2828
children: ReactNode;
@@ -36,7 +36,6 @@ export const AppProvider = ({ children }: TProps) => {
3636
const [guideExists, setGuideExists] = useState(false);
3737
const [hideAmounts, setHideAmounts] = useState(false);
3838
const [activeSidebar, setActiveSidebar] = useState(false);
39-
const [sidebarStatus, setSidebarStatus] = useState<TSidebarStatus>('');
4039
const [chartDisplay, setChartDisplay] = useState<TChartDisplay>('all');
4140
const [firmwareUpdateDialogOpen, setFirmwareUpdateDialogOpen] = useState(false);
4241

@@ -80,11 +79,9 @@ export const AppProvider = ({ children }: TProps) => {
8079
isTesting,
8180
isDevServers,
8281
nativeLocale,
83-
sidebarStatus,
8482
chartDisplay,
8583
setActiveSidebar,
8684
setGuideExists,
87-
setSidebarStatus,
8885
setHideAmounts,
8986
setChartDisplay,
9087
toggleHideAmounts,

frontends/web/src/routes/device/bitbox01/bitbox01.jsx

-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ class Device extends Component {
7373

7474
onDeviceStatusChanged = () => {
7575
apiGet('devices/' + this.props.deviceID + '/status').then(deviceStatus => {
76-
if (['seeded', 'initialized'].includes(deviceStatus)) {
77-
this.context.setSidebarStatus('');
78-
} else {
79-
this.context.setSidebarStatus('forceHidden');
80-
}
8176
this.setState({ deviceStatus });
8277
});
8378
};

0 commit comments

Comments
 (0)