Skip to content

Commit 9dfb314

Browse files
committed
Resolve dependency mobx-react
Use mobx-react-lite Signed-off-by: Marcin Maj <marcinmajsc@gmail.com>
1 parent 286dee3 commit 9dfb314

13 files changed

Lines changed: 47 additions & 50 deletions

File tree

client/src/javascript/components/modals/settings-modal/UITab.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {FC, useRef, useState} from 'react';
1+
import {FC, useState} from 'react';
22
import {Trans, useLingui} from '@lingui/react';
33

44
import {Form, FormRow, Select, SelectItem, Radio} from '@client/ui';
55
import Languages from '@client/constants/Languages';
66
import SettingStore from '@client/stores/SettingStore';
7-
import ToggleList from '@client/components/general/ToggleList';
87

98
import type {Language} from '@client/constants/Languages';
109

@@ -24,9 +23,6 @@ const UITab: FC<UITabProps> = ({onSettingsChange}: UITabProps) => {
2423
const [torrentListViewSize, setTorrentListViewSize] = useState(SettingStore.floodSettings.torrentListViewSize);
2524
const [selectedLanguage, setSelectedLanguage] = useState(SettingStore.floodSettings.language);
2625
const [UITagSelectorMode, setUITagSelectorMode] = useState(SettingStore.floodSettings.UITagSelectorMode);
27-
const UITorrentDetailsPanelRef = useRef<FloodSettings['UITorrentDetailsPanel']>(
28-
SettingStore.floodSettings.UITorrentDetailsPanel ?? true,
29-
);
3026

3127
return (
3228
<Form
@@ -74,23 +70,6 @@ const UITab: FC<UITabProps> = ({onSettingsChange}: UITabProps) => {
7470
<Trans id="settings.ui.tag.selector.mode.multi" />
7571
</Radio>
7672
</FormRow>
77-
<ModalFormSectionHeader>
78-
<Trans id="settings.ui.torrent.details" />
79-
</ModalFormSectionHeader>
80-
<FormRow>
81-
<ToggleList
82-
items={[
83-
{
84-
label: 'settings.ui.torrent.details.panel',
85-
defaultChecked: UITorrentDetailsPanelRef.current,
86-
onClick: () => {
87-
UITorrentDetailsPanelRef.current = !UITorrentDetailsPanelRef.current;
88-
onSettingsChange({UITorrentDetailsPanel: UITorrentDetailsPanelRef.current});
89-
},
90-
},
91-
]}
92-
/>
93-
</FormRow>
9473
<ModalFormSectionHeader>
9574
<Trans id="settings.ui.torrent.list" />
9675
</ModalFormSectionHeader>

client/src/javascript/components/modals/settings-modal/lists/MiscUISettingsList.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const MiscUISettingsList: FC<MiscUISettingsListProps> = ({onSettingsChange}: Mis
2222
const [filterTagEnabled, setFilterTagEnabled] = useState<FloodSettings['UISidebarFilterTag']>(
2323
SettingStore.floodSettings.UISidebarFilterTag,
2424
);
25+
const [torrentDetailsPanelEnabled, setTorrentDetailsPanelEnabled] = useState<FloodSettings['UITorrentDetailsPanel']>(
26+
SettingStore.floodSettings.UITorrentDetailsPanel ?? true,
27+
);
2528

2629
const handlePageTitleSpeedToggle = () => {
2730
const nextValue = !pageTitleSpeedEnabled;
@@ -43,6 +46,11 @@ const MiscUISettingsList: FC<MiscUISettingsListProps> = ({onSettingsChange}: Mis
4346
setFilterTagEnabled(nextValue);
4447
onSettingsChange({UISidebarFilterTag: nextValue});
4548
};
49+
const handleTorrentDetailsPanelToggle = () => {
50+
const nextValue = !torrentDetailsPanelEnabled;
51+
setTorrentDetailsPanelEnabled(nextValue);
52+
onSettingsChange({UITorrentDetailsPanel: nextValue});
53+
};
4654
return (
4755
<ToggleList
4856
items={[
@@ -66,6 +74,11 @@ const MiscUISettingsList: FC<MiscUISettingsListProps> = ({onSettingsChange}: Mis
6674
checked: filterTagEnabled,
6775
onClick: handleFilterTagToggle,
6876
},
77+
{
78+
label: 'settings.ui.torrent.details.panel',
79+
checked: torrentDetailsPanelEnabled,
80+
onClick: handleTorrentDetailsPanelToggle,
81+
},
6982
]}
7083
/>
7184
);

client/src/javascript/components/modals/torrent-details-modal/TorrentContents.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import classnames from 'classnames';
22
import {observer} from 'mobx-react-lite';
33
import {FC, useEffect, useState} from 'react';
44
import {Trans, useLingui} from '@lingui/react';
5+
import getTorrentDetailsHash from './getTorrentDetailsHash';
56

67
import {Button, Checkbox, Form, FormRow, FormRowItem, Select, SelectItem} from '@client/ui';
78
import ConfigStore from '@client/stores/ConfigStore';
89
import {Disk} from '@client/ui/icons';
910
import selectionTree from '@client/util/selectionTree';
1011
import TorrentActions from '@client/actions/TorrentActions';
1112
import TorrentStore from '@client/stores/TorrentStore';
12-
import UIStore from '@client/stores/UIStore';
1313

1414
import type {TorrentContent, TorrentContentSelection, TorrentContentSelectionTree} from '@shared/types/TorrentContent';
1515

@@ -21,8 +21,7 @@ const TorrentContents: FC = observer(() => {
2121
const [selectedIndices, setSelectedIndices] = useState<number[]>([]);
2222
const {i18n} = useLingui();
2323

24-
const torrentHash =
25-
UIStore.detailsPanelHash || (UIStore.activeModal?.id === 'torrent-details' ? UIStore.activeModal.hash : null);
24+
const torrentHash = getTorrentDetailsHash();
2625

2726
useEffect(() => {
2827
if (torrentHash) {
@@ -39,7 +38,7 @@ const TorrentContents: FC = observer(() => {
3938
return null;
4039
}
4140

42-
const {hash} = UIStore.activeModal;
41+
const hash = torrentHash;
4342

4443
let directoryHeadingIconContent = null;
4544
let fileDetailContent = null;

client/src/javascript/components/modals/torrent-details-modal/TorrentGeneralInfo.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {FC} from 'react';
22
import {observer} from 'mobx-react-lite';
33
import {Trans, useLingui} from '@lingui/react';
4+
import getTorrentDetailsHash from './getTorrentDetailsHash';
45

56
import type {TorrentProperties} from '@shared/types/Torrent';
67

78
import LinkedText from '../../general/LinkedText';
89
import Size from '../../general/Size';
910
import TorrentStore from '../../../stores/TorrentStore';
10-
import UIStore from '../../../stores/UIStore';
1111

1212
const getTags = (tags: TorrentProperties['tags']) =>
1313
tags.map((tag) => (
@@ -19,8 +19,7 @@ const getTags = (tags: TorrentProperties['tags']) =>
1919
const TorrentGeneralInfo: FC = observer(() => {
2020
const {i18n} = useLingui();
2121

22-
const torrentHash =
23-
UIStore.detailsPanelHash || (UIStore.activeModal?.id === 'torrent-details' ? UIStore.activeModal.hash : null);
22+
const torrentHash = getTorrentDetailsHash();
2423
const torrent = torrentHash ? TorrentStore.torrents[torrentHash] : undefined;
2524

2625
if (torrent == null) {

client/src/javascript/components/modals/torrent-details-modal/TorrentHeading.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {computed} from 'mobx';
33
import {FC, useEffect, useState} from 'react';
44
import {observer} from 'mobx-react-lite';
55
import {Trans, useLingui} from '@lingui/react';
6+
import getTorrentDetailsHash from './getTorrentDetailsHash';
67

78
import {Clock, DownloadThick, Ratio, Start, Stop, UploadThick} from '@client/ui/icons';
89
import TorrentActions from '@client/actions/TorrentActions';
910
import {torrentStatusClasses, torrentStatusEffective} from '@client/util/torrentStatus';
1011
import TorrentStore from '@client/stores/TorrentStore';
11-
import UIStore from '@client/stores/UIStore';
1212

1313
import Duration from '../../general/Duration';
1414
import PriorityMeter from '../../general/PriorityMeter';
@@ -17,8 +17,7 @@ import Size from '../../general/Size';
1717

1818
const TorrentHeading: FC = observer(() => {
1919
const {i18n} = useLingui();
20-
const torrentHash =
21-
UIStore.detailsPanelHash || (UIStore.activeModal?.id === 'torrent-details' ? UIStore.activeModal.hash : null);
20+
const torrentHash = getTorrentDetailsHash();
2221
const torrent = torrentHash ? TorrentStore.torrents[torrentHash] : undefined;
2322
const [torrentStatus, setTorrentStatus] = useState<'start' | 'stop'>('stop');
2423

client/src/javascript/components/modals/torrent-details-modal/TorrentMediainfo.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import axios, {CancelTokenSource} from 'axios';
22
import {FC, useEffect, useRef, useState} from 'react';
33
import {Trans, useLingui} from '@lingui/react';
4+
import getTorrentDetailsHash from './getTorrentDetailsHash';
45

56
import {Button} from '@client/ui';
67
import {Checkmark, Clipboard} from '@client/ui/icons';
78
import TorrentActions from '@client/actions/TorrentActions';
8-
import UIStore from '@client/stores/UIStore';
99

1010
import Tooltip from '../../general/Tooltip';
1111

@@ -18,8 +18,7 @@ const TorrentMediainfo: FC = () => {
1818
const [isFetchingMediainfo, setIsFetchingMediainfo] = useState<boolean>(true);
1919
const [isCopiedToClipboard, setIsCopiedToClipboard] = useState<boolean>(false);
2020

21-
const torrentHash =
22-
UIStore.detailsPanelHash || (UIStore.activeModal?.id === 'torrent-details' ? UIStore.activeModal.hash : null);
21+
const torrentHash = getTorrentDetailsHash();
2322

2423
useEffect(() => {
2524
const {current: currentCancelToken} = cancelToken;

client/src/javascript/components/modals/torrent-details-modal/TorrentPeers.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {FC, Suspense, useEffect, useState} from 'react';
1+
import {FC, Suspense, useCallback, useEffect, useState} from 'react';
22
import {Trans} from '@lingui/react';
33
import {useInterval} from 'react-use';
4+
import getTorrentDetailsHash from './getTorrentDetailsHash';
45

56
import {css} from '@client/styled-system/css';
67
import {CheckmarkThick, CountryFlag, Lock, Spinner} from '@client/ui/icons';
78
import ConfigStore from '@client/stores/ConfigStore';
89
import TorrentActions from '@client/actions/TorrentActions';
9-
import UIStore from '@client/stores/UIStore';
1010

1111
import type {TorrentPeer} from '@shared/types/TorrentPeer';
1212

@@ -17,10 +17,9 @@ const TorrentPeers: FC = () => {
1717
const [peers, setPeers] = useState<Array<TorrentPeer>>([]);
1818
const [pollingDelay, setPollingDelay] = useState<number | null>(null);
1919

20-
const torrentHash =
21-
UIStore.detailsPanelHash || (UIStore.activeModal?.id === 'torrent-details' ? UIStore.activeModal.hash : null);
20+
const torrentHash = getTorrentDetailsHash();
2221

23-
const fetchPeers = () => {
22+
const fetchPeers = useCallback(() => {
2423
setPollingDelay(null);
2524
if (torrentHash) {
2625
TorrentActions.fetchTorrentPeers(torrentHash).then((data) => {
@@ -30,9 +29,9 @@ const TorrentPeers: FC = () => {
3029
});
3130
}
3231
setPollingDelay(ConfigStore.pollInterval);
33-
};
32+
}, [torrentHash]);
3433

35-
useEffect(() => fetchPeers(), [torrentHash]);
34+
useEffect(() => fetchPeers(), [fetchPeers]);
3635
useInterval(() => fetchPeers(), pollingDelay);
3736

3837
return (

client/src/javascript/components/modals/torrent-details-modal/TorrentTrackers.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import {FC, useEffect, useState} from 'react';
22
import {Trans} from '@lingui/react';
3+
import getTorrentDetailsHash from './getTorrentDetailsHash';
34

45
import type {TorrentTracker} from '@shared/types/TorrentTracker';
56

67
import Badge from '../../general/Badge';
78
import TorrentActions from '../../../actions/TorrentActions';
8-
import UIStore from '../../../stores/UIStore';
99

1010
const TorrentTrackers: FC = () => {
1111
const [trackers, setTrackers] = useState<Array<TorrentTracker>>([]);
1212

13-
const torrentHash =
14-
UIStore.detailsPanelHash || (UIStore.activeModal?.id === 'torrent-details' ? UIStore.activeModal.hash : null);
13+
const torrentHash = getTorrentDetailsHash();
1514

1615
const trackerCount = trackers.length;
1716
const trackerTypes = ['http', 'udp', 'dht'];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import UIStore from '@client/stores/UIStore';
2+
3+
const getTorrentDetailsHash = (): string | null => {
4+
const {activeModal} = UIStore;
5+
6+
if (activeModal?.id === 'torrent-details') {
7+
return activeModal.hash;
8+
}
9+
10+
return UIStore.detailsPanelHash;
11+
};
12+
13+
export default getTorrentDetailsHash;

client/src/javascript/components/torrent-details-panel/TorrentDetailsPanel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {FC, useEffect, useState} from 'react';
2-
import {observer} from 'mobx-react';
2+
import {observer} from 'mobx-react-lite';
33
import {Trans, useLingui} from '@lingui/react';
44

5-
import ConfigStore from '@client/stores/ConfigStore';
65
import TorrentStore from '@client/stores/TorrentStore';
76
import UIStore from '@client/stores/UIStore';
87
import SettingStore from '@client/stores/SettingStore';

0 commit comments

Comments
 (0)