Skip to content

Commit 7e4a9b9

Browse files
committed
app: Move docs button component.
Everything is visually unchanged. This just moves the button logic to the app, since it doesn't conceptually belong to the editor component. It controls things such as docs which has nothing to do with the editor. This way we don't have to pass states as props around when we add more buttons later.
1 parent c3a703f commit 7e4a9b9

File tree

6 files changed

+30
-39
lines changed

6 files changed

+30
-39
lines changed

src/app/App.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import 'react-splitter-layout/lib/index.css';
55
import './app.scss';
6-
import { Classes, Spinner } from '@blueprintjs/core';
6+
import { Button, Classes, Spinner } from '@blueprintjs/core';
7+
import { Manual } from '@blueprintjs/icons';
78
import React, { useEffect, useState } from 'react';
89
import SplitterLayout from 'react-splitter-layout';
910
import { useLocalStorage, useTernaryDarkMode } from 'usehooks-ts';
@@ -71,7 +72,8 @@ const Docs: React.FunctionComponent = () => {
7172
const App: React.FunctionComponent = () => {
7273
const i18n = useI18n();
7374
const { isDarkMode } = useTernaryDarkMode();
74-
const { isSettingShowDocsEnabled } = useSettingIsShowDocsEnabled();
75+
const { isSettingShowDocsEnabled, toggleIsSettingShowDocsEnabled } =
76+
useSettingIsShowDocsEnabled();
7577
const [isDragging, setIsDragging] = useState(false);
7678

7779
const [docsSplit, setDocsSplit] = useLocalStorage('app-docs-split', 30);
@@ -140,6 +142,18 @@ const App: React.FunctionComponent = () => {
140142
>
141143
<Editor />
142144
</React.Suspense>
145+
<Button
146+
className="pb-app-doc-button"
147+
minimal
148+
large
149+
icon={<Manual />}
150+
title={
151+
isSettingShowDocsEnabled
152+
? i18n.translate('docs.hide')
153+
: i18n.translate('docs.show')
154+
}
155+
onClick={toggleIsSettingShowDocsEnabled}
156+
/>
143157
</main>
144158
<aside
145159
className="pb-app-terminal"

src/app/app.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,21 @@
7171
height: 100%;
7272
display: flex;
7373
flex-direction: column;
74+
position: relative;
7475

7576
& .pb-editor {
7677
min-height: 0;
7778
flex: 1 1 auto;
7879
}
7980
}
8081

82+
.pb-app-doc-button {
83+
position: absolute;
84+
bottom: bp.$pt-grid-size;
85+
right: bp.$pt-grid-size;
86+
z-index: bp.$pt-z-index-overlay;
87+
}
88+
8189
$splitter-background-color: bp.$light-gray2;
8290
$splitter-background-color-hover: bp.$gray4;
8391
$dark-splitter-background-color: bp.$dark-gray5;

src/app/translations/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
"editor": "Editor",
55
"terminal": "Terminal",
66
"documentation": "Documentation"
7+
},
8+
"docs": {
9+
"show": "Show documentation",
10+
"hide": "Hide documentation"
711
}
812
}

src/editor/Editor.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ import {
1616
Tabs,
1717
Text,
1818
} from '@blueprintjs/core';
19-
import {
20-
Blank,
21-
Clipboard,
22-
Cross,
23-
Duplicate,
24-
Manual,
25-
Redo,
26-
Undo,
27-
} from '@blueprintjs/icons';
19+
import { Blank, Clipboard, Cross, Duplicate, Redo, Undo } from '@blueprintjs/icons';
2820
import classNames from 'classnames';
2921
import * as monaco from 'monaco-editor';
3022
import tomorrowNightEightiesTheme from 'monaco-themes/themes/Tomorrow-Night-Eighties.json';
@@ -37,7 +29,6 @@ import { UUID } from '../fileStorage';
3729
import { useFileStoragePath } from '../fileStorage/hooks';
3830
import { compile } from '../mpy/actions';
3931
import { useSelector } from '../reducers';
40-
import { useSettingIsShowDocsEnabled } from '../settings/hooks';
4132
import { isMacOS } from '../utils/os';
4233
import Welcome from './Welcome';
4334
import { editorActivateFile, editorCloseFile } from './actions';
@@ -387,8 +378,6 @@ const Editor: React.FunctionComponent = () => {
387378
const dispatch = useDispatch();
388379

389380
const [editor, setEditor] = useState<monaco.editor.IStandaloneCodeEditor>();
390-
const { isSettingShowDocsEnabled, toggleIsSettingShowDocsEnabled } =
391-
useSettingIsShowDocsEnabled();
392381
const { isDarkMode } = useTernaryDarkMode();
393382

394383
const i18n = useI18n();
@@ -510,18 +499,6 @@ const Editor: React.FunctionComponent = () => {
510499
<div className="pb-editor-monaco" ref={editorRef} />
511500
</ContextMenu>
512501
</ResizeSensor>
513-
<Button
514-
className="pb-editor-doc-button"
515-
minimal
516-
large
517-
icon={<Manual />}
518-
title={
519-
isSettingShowDocsEnabled
520-
? i18n.translate('docs.hide')
521-
: i18n.translate('docs.show')
522-
}
523-
onClick={toggleIsSettingShowDocsEnabled}
524-
/>
525502
</div>
526503
);
527504
};

src/editor/editor.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@
9393
color: bp.$pt-dark-text-color-muted;
9494
}
9595
}
96-
97-
&-doc-button {
98-
position: absolute;
99-
bottom: bp.$pt-grid-size;
100-
right: bp.$pt-grid-size;
101-
z-index: bp.$pt-z-index-overlay;
102-
}
10396
}
10497

10598
.monaco-editor {

src/editor/translations/en.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
"welcome": "Welcome",
66
"placeholder": "Write your program here...",
77
"check": "Check syntax",
8-
"toggleDocs": "Toggle documentation",
98
"copy": "Copy",
109
"paste": "Paste",
1110
"selectAll": "Select all",
1211
"undo": "Undo",
1312
"redo": "Redo",
1413
"closeFile": { "tooltip": "Close {fileName}" },
15-
"contextMenu": { "label": "Editor context menu" },
16-
"docs": {
17-
"show": "Show documentation",
18-
"hide": "Hide documentation"
19-
}
14+
"contextMenu": { "label": "Editor context menu" }
2015
}

0 commit comments

Comments
 (0)