client: allow to press Ctrl-A or Command-A to select all torrents

This commit is contained in:
Saber
2021-03-22 11:40:42 +08:00
committed by Jesse Chan
parent afaccbd858
commit 02aa24e287
3 changed files with 29 additions and 1 deletions
@@ -33,6 +33,10 @@ const UIActions = {
TorrentStore.setSelectedTorrents(data);
},
selectAllTorrents: () => {
TorrentStore.selectAllTorrents();
},
setTorrentStatusFilter: (status: TorrentStatus) => {
TorrentFilterStore.setStatusFilter(status);
},
@@ -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';
@@ -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';
@@ -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;
@@ -65,6 +65,10 @@ class TorrentStore {
});
}
selectAllTorrents() {
this.selectedTorrents = this.filteredTorrents.map((v) => v.hash);
}
handleTorrentListDiffChange(torrentListDiffs: Operation[]) {
applyPatch(this.torrents, torrentListDiffs);
}