Skip to content

Commit 38a7123

Browse files
committed
app: Replace local/session docs toggle with state.
Having this persist across sessions is not necessary and a bit overly complicated when we add more sideview states such as camera (which should not stay on by default).
1 parent 7e4a9b9 commit 38a7123

3 files changed

Lines changed: 12 additions & 54 deletions

File tree

src/app/App.test.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2021-2023 The Pybricks Authors
2+
// Copyright (c) 2021-2026 The Pybricks Authors
33

44
import { cleanup } from '@testing-library/react';
55
import React from 'react';
@@ -42,15 +42,7 @@ it.each([false, true])('should render', (darkMode) => {
4242
});
4343

4444
describe('documentation pane', () => {
45-
it('should show by default on large screens', () => {
46-
jest.spyOn(window, 'innerWidth', 'get').mockReturnValue(1024);
47-
testRender(<App />);
48-
expect(document.querySelector('.pb-show-docs')).not.toBeNull();
49-
expect(document.querySelector('.pb-hide-docs')).toBeNull();
50-
});
51-
52-
it('should hide by default on small screens', () => {
53-
jest.spyOn(window, 'innerWidth', 'get').mockReturnValue(800);
45+
it('should hide by default', () => {
5446
testRender(<App />);
5547
expect(document.querySelector('.pb-show-docs')).toBeNull();
5648
expect(document.querySelector('.pb-hide-docs')).not.toBeNull();

src/app/App.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import './app.scss';
66
import { Button, Classes, Spinner } from '@blueprintjs/core';
77
import { Manual } from '@blueprintjs/icons';
88
import React, { useEffect, useState } from 'react';
9+
10+
type SideView = 'off' | 'docs';
911
import SplitterLayout from 'react-splitter-layout';
1012
import { useLocalStorage, useTernaryDarkMode } from 'usehooks-ts';
1113
import Activities from '../activities/Activities';
1214
import DfuWindowsDriverInstallDialog from '../firmware/dfuWindowsDriverInstallDialog/DfuWindowsDriverInstallDialog';
1315
import { InstallPybricksDialog } from '../firmware/installPybricksDialog/InstallPybricksDialog';
1416
import RestoreOfficialDialog from '../firmware/restoreOfficialDialog/RestoreOfficialDialog';
15-
import { useSettingIsShowDocsEnabled } from '../settings/hooks';
1617
import SponsorDialog from '../sponsor/SponsorDialog';
1718
import StatusBar from '../status-bar/StatusBar';
1819
import Toolbar from '../toolbar/Toolbar';
@@ -72,8 +73,7 @@ const Docs: React.FunctionComponent = () => {
7273
const App: React.FunctionComponent = () => {
7374
const i18n = useI18n();
7475
const { isDarkMode } = useTernaryDarkMode();
75-
const { isSettingShowDocsEnabled, toggleIsSettingShowDocsEnabled } =
76-
useSettingIsShowDocsEnabled();
76+
const [sideView, setSideView] = useState<SideView>('off');
7777
const [isDragging, setIsDragging] = useState(false);
7878

7979
const [docsSplit, setDocsSplit] = useLocalStorage('app-docs-split', 30);
@@ -118,7 +118,7 @@ const App: React.FunctionComponent = () => {
118118
<div className="pb-app-main" style={{ position: 'relative' }}>
119119
<SplitterLayout
120120
customClassName={
121-
isSettingShowDocsEnabled ? 'pb-show-docs' : 'pb-hide-docs'
121+
sideView === 'docs' ? 'pb-show-docs' : 'pb-hide-docs'
122122
}
123123
onDragStart={(): void => setIsDragging(true)}
124124
onDragEnd={(): void => setIsDragging(false)}
@@ -148,11 +148,15 @@ const App: React.FunctionComponent = () => {
148148
large
149149
icon={<Manual />}
150150
title={
151-
isSettingShowDocsEnabled
151+
sideView === 'docs'
152152
? i18n.translate('docs.hide')
153153
: i18n.translate('docs.show')
154154
}
155-
onClick={toggleIsSettingShowDocsEnabled}
155+
onClick={() =>
156+
setSideView(
157+
sideView === 'docs' ? 'off' : 'docs',
158+
)
159+
}
156160
/>
157161
</main>
158162
<aside

src/settings/hooks.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)