Skip to content

Commit d30736c

Browse files
authored
App: rewrote using hooks (#364)
Also: - removed Log component: console.log is more than enough - added new generic useEventListener - removed lots of hacks in App component - removed apState.showDownloads tab: there is a single showExplorerTab prop now - fixed toolbar path to only be disabled when filestate is busy - removed checks for contenteditable in shouldCatch util
1 parent e66703f commit d30736c

File tree

14 files changed

+282
-704
lines changed

14 files changed

+282
-704
lines changed

src/components/App.tsx

Lines changed: 207 additions & 300 deletions
Large diffs are not rendered by default.

src/components/Log.tsx

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

src/components/Nav.tsx

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,15 @@ const Nav = observer(() => {
2222
const downloadClass = classNames(Classes.MINIMAL, 'download')
2323
const isSplitViewActive = appState.winStates[0].splitView
2424

25-
const showDownloadsTab = (): void => {
26-
appState.showDownloadsTab()
27-
}
28-
29-
const showExplorerTab = (): void => {
30-
appState.showExplorerTab()
31-
}
32-
3325
const navClick = (): void => {
3426
if (appState.isExplorer) {
35-
showDownloadsTab()
27+
appState.toggleExplorerTab(false)
3628
} else {
37-
showExplorerTab()
38-
}
39-
}
40-
41-
const onToggleSplitView = (): void => {
42-
if (appState.isExplorer) {
43-
appState.toggleSplitViewMode()
29+
appState.toggleExplorerTab(true)
4430
}
4531
}
4632

47-
const onOpenPrefs = (): void => {
48-
runInAction(() => (appState.isPrefsOpen = true))
49-
}
50-
51-
const onOpenShortcuts = (): void => {
52-
runInAction(() => (appState.isShortcutsOpen = true))
53-
}
33+
const onToggleSplitView = (): void => appState.isExplorer && appState.toggleSplitViewMode()
5434

5535
return (
5636
<Navbar>
@@ -85,7 +65,14 @@ const Nav = observer(() => {
8565
title={t('NAV.SPLITVIEW')}
8666
/>
8767
<Navbar.Divider />
88-
<Popover2 content={<HamburgerMenu onOpenShortcuts={onOpenShortcuts} onOpenPrefs={onOpenPrefs} />}>
68+
<Popover2
69+
content={
70+
<HamburgerMenu
71+
onOpenShortcuts={(): void => appState.toggleShortcutsDialog(true)}
72+
onOpenPrefs={(): void => appState.togglePrefsDialog(true)}
73+
/>
74+
}
75+
>
8976
<Button className={`data-cy-toggle-app-menu ${Classes.MINIMAL}`} icon="menu" />
9077
</Popover2>
9178
</Navbar.Group>

src/components/SideView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const SideView = observer(({ hide, viewState }: SideViewProps) => {
6969
<div ref={drop} id={divId} className={activeClass}>
7070
{needLogin && <LoginDialog isOpen={needLogin} onValidation={onValidation} onClose={onClose} />}
7171
<TabList></TabList>
72-
<Toolbar active={active && !busy} />
72+
<Toolbar active={!busy} />
7373
<FileView hide={hide} />
7474
<Statusbar />
7575
<Overlay id={`files-loader-${viewState.viewId}`} shouldShow={busy} delay={true}>

src/components/Toolbar.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useTranslation } from 'react-i18next'
77
import { FileMenu } from '$src/components/FileMenu'
88
import { MakedirDialog } from '$src/components/dialogs/MakedirDialog'
99
import { AppAlert } from '$src/components/AppAlert'
10-
import { Logger } from '$src/components/Log'
1110
import { AppToaster } from '$src/components/AppToaster'
1211
import { LocalizedError } from '$src/locale/error'
1312
import Keys from '$src/constants/keys'
@@ -113,7 +112,7 @@ export const Toolbar = observer(({ active }: Props) => {
113112
}
114113

115114
try {
116-
Logger.log("Let's create a directory :)", dirName, navigate)
115+
console.log("Let's create a directory :)", dirName, navigate)
117116
const dir = await cache.makedir(path, dirName)
118117

119118
if (!navigate) {
@@ -148,7 +147,7 @@ export const Toolbar = observer(({ active }: Props) => {
148147
const onFileAction = (action: string): void => {
149148
switch (action) {
150149
case 'makedir':
151-
Logger.log('Opening new folder dialog')
150+
console.log('Opening new folder dialog')
152151
onMakedir()
153152
break
154153

@@ -161,7 +160,7 @@ export const Toolbar = observer(({ active }: Props) => {
161160
break
162161

163162
default:
164-
Logger.warn('action unknown', action)
163+
console.warn('action unknown', action)
165164
}
166165
}
167166

src/components/__tests__/Nav.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ describe('Nav', () => {
2020
options.providerProps.appState = appState
2121
await options.providerProps.appState.loadSettingsAndPrepareViews()
2222

23-
jest.spyOn(appState, 'showDownloadsTab')
24-
jest.spyOn(appState, 'showExplorerTab')
23+
jest.spyOn(appState, 'toggleExplorerTab')
2524
jest.spyOn(appState, 'toggleSplitViewMode')
2625

2726
jest.clearAllMocks()
@@ -61,7 +60,7 @@ describe('Nav', () => {
6160

6261
await user.click(screen.getByRole('button', { name: t('NAV.TRANSFERS') }))
6362

64-
expect(options.providerProps.appState.showDownloadsTab).toHaveBeenCalled()
63+
expect(options.providerProps.appState.toggleExplorerTab).toHaveBeenCalledWith(false)
6564
})
6665

6766
it('should show downloads when clicking on downloads button and show explorer when clicking on explorer button', async () => {
@@ -72,12 +71,12 @@ describe('Nav', () => {
7271

7372
await user.click(transfersButton)
7473

75-
expect(options.providerProps.appState.showDownloadsTab).toHaveBeenCalled()
74+
expect(options.providerProps.appState.toggleExplorerTab).toHaveBeenCalledWith(false)
7675
expect(isSelected(explorerButton)).toBe(false)
7776
expect(isSelected(transfersButton)).toBe(true)
7877

7978
await user.click(explorerButton)
80-
expect(options.providerProps.appState.showExplorerTab).toHaveBeenCalled()
79+
expect(options.providerProps.appState.toggleExplorerTab).toHaveBeenCalledWith(true)
8180
expect(isSelected(explorerButton)).toBe(true)
8281
expect(isSelected(transfersButton)).toBe(false)
8382
})

src/components/shortcuts/KeyboardHotkeys.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { inject } from 'mobx-react'
77
import { AppState } from '$src/state/appState'
88
import { FileState } from '$src/state/fileState'
99
import { SettingsState } from '$src/state/settingsState'
10-
import { Logger } from '$src/components/Log'
1110
import { isMac } from '$src/utils/platform'
1211

1312
interface InjectedProps extends WithTranslation {
@@ -45,13 +44,9 @@ class KeyboardHotkeysClass extends React.Component<WithTranslation> {
4544
/**
4645
* Event Handlers
4746
*/
48-
onShowDownloadsTab = (): void => {
49-
this.appState.showDownloadsTab()
50-
}
47+
onShowDownloadsTab = (): void => this.appState.toggleExplorerTab(false)
5148

52-
onShowExplorerTab = (): void => {
53-
this.appState.showExplorerTab()
54-
}
49+
onShowExplorerTab = (): void => this.appState.toggleExplorerTab(true)
5550

5651
onNextView = (): void => {
5752
const winState = this.appState.winStates[0]

0 commit comments

Comments
 (0)