Skip to content

Commit

Permalink
client: allow to press Ctrl-A or Command-A to select all torrents
Browse files Browse the repository at this point in the history
  • Loading branch information
sabersalv authored and jesec committed Mar 22, 2021
1 parent afaccbd commit 02aa24e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client/src/javascript/actions/UIActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const UIActions = {
TorrentStore.setSelectedTorrents(data);
},

selectAllTorrents: () => {
TorrentStore.selectAllTorrents();
},

setTorrentStatusFilter: (status: TorrentStatus) => {
TorrentFilterStore.setStatusFilter(status);
},
Expand Down
22 changes: 21 additions & 1 deletion client/src/javascript/components/torrent-list/TorrentList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {FC, ReactNode, useEffect, useRef} from 'react';
import {FC, KeyboardEvent, ReactNode, useEffect, useRef} from 'react';
import {observer} from 'mobx-react';
import {reaction} from 'mobx';
import {Trans} from '@lingui/react';
import {useEvent} from 'react-use';

import type {FixedSizeList, ListChildComponentProps} from 'react-window';

Expand All @@ -12,6 +13,7 @@ import SettingActions from '@client/actions/SettingActions';
import SettingStore from '@client/stores/SettingStore';
import TorrentFilterStore from '@client/stores/TorrentFilterStore';
import TorrentStore from '@client/stores/TorrentStore';
import UIActions from '@client/actions/UIActions';

import SortDirections from '@client/constants/SortDirections';

Expand Down Expand Up @@ -47,6 +49,24 @@ const TorrentList: FC = observer(() => {
return dispose;
}, []);

useEvent('keydown', (e: KeyboardEvent) => {
const {ctrlKey, key, metaKey, repeat, target} = e;

const tagName = (target as HTMLElement)?.tagName.toUpperCase();
if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
return;
}

if (repeat) {
return;
}

if ((metaKey || ctrlKey) && key === 'a') {
e.preventDefault();
UIActions.selectAllTorrents();
}
});

const torrents = TorrentStore.filteredTorrents;
const {torrentListViewSize = 'condensed'} = SettingStore.floodSettings;

Expand Down
4 changes: 4 additions & 0 deletions client/src/javascript/stores/TorrentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class TorrentStore {
});
}

selectAllTorrents() {
this.selectedTorrents = this.filteredTorrents.map((v) => v.hash);
}

handleTorrentListDiffChange(torrentListDiffs: Operation[]) {
applyPatch(this.torrents, torrentListDiffs);
}
Expand Down

0 comments on commit 02aa24e

Please sign in to comment.