Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit ffc31d5

Browse files
committed
(cleanup): handle some TODOs
just going through some of the incomplete TODOs before releasing.
1 parent 714e62e commit ffc31d5

9 files changed

Lines changed: 135 additions & 72 deletions

File tree

client/components/dashboard/torrent-list/context-menu/items.tsx

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TransmissionPriorityType as PriorityType } from '@transmission';
77
import {
88
RootState, showTorrentDetails, setLabelsOverlayAssigned,
99
removeTorrentOverlayAssigned, selectTorrentById,
10-
setTorrentLocationOverlayAssigned
10+
setTorrentLocationOverlayAssigned, notifyRequestError
1111
} from '@client/stores';
1212

1313
import {
@@ -20,19 +20,32 @@ export interface ContextItemProps {
2020
}
2121

2222
export function StartTorrentsItem(props: ContextItemProps) {
23+
const dispatch = useDispatch()
2324
const { transmission } = useContext(ClientContext)
24-
const onClick = () => {
25-
transmission.startTorrent(props.torrents)
26-
// TODO notify on error.
25+
const onClick = async () => {
26+
try {
27+
await transmission.startTorrent(props.torrents)
28+
} catch (err) {
29+
await dispatch(notifyRequestError({
30+
to: 'transmission', errorMessage: err, description: `starting torrents: ${props.torrents}`
31+
}))
32+
}
2733
}
2834

2935
return <li onClick={onClick}>Start</li>;
3036
}
3137

3238
export function StopTorrentsItem(props: ContextItemProps) {
39+
const dispatch = useDispatch()
3340
const { transmission } = useContext(ClientContext)
34-
const onClick = () => {
35-
transmission.stopTorrent(props.torrents)
41+
const onClick = async () => {
42+
try {
43+
await transmission.stopTorrent(props.torrents)
44+
} catch (err) {
45+
await dispatch(notifyRequestError({
46+
to: 'transmission', errorMessage: err, description: `stopping torrents: ${props.torrents}`
47+
}))
48+
}
3649
}
3750

3851
return <li onClick={onClick}>Stop</li>;
@@ -49,9 +62,16 @@ export function RemoveTorrentsItem(props: ContextItemProps) {
4962
}
5063

5164
export function CheckHashesItem(props: ContextItemProps) {
65+
const dispatch = useDispatch()
5266
const { transmission } = useContext(ClientContext)
53-
const onClick = () => {
54-
transmission.verifyTorrent(props.torrents)
67+
const onClick = async () => {
68+
try {
69+
await transmission.verifyTorrent(props.torrents)
70+
} catch (err) {
71+
await dispatch(notifyRequestError({
72+
to: 'transmission', errorMessage: err, description: `recheck torrents: ${props.torrents}`
73+
}))
74+
}
5575
}
5676

5777
return <li onClick={onClick}>Check Hash</li>;
@@ -89,11 +109,18 @@ export function PriorityItem(props: ContextItemProps) {
89109
const { transmission } = useContext(ClientContext)
90110
// TODO if all torrents share same priority, use that as default
91111
// instead of NORM.
112+
const dispatch = useDispatch()
92113
const [priority, setPriority] = useState(PriorityType.NORM)
93-
const updatePriority = (p: ExtendedPriorityType) => {
114+
const updatePriority = async (p: ExtendedPriorityType) => {
94115
if (isPriorityType(p)) {
95-
transmission.setTorrent(props.torrents, { bandwidthPriority: p })
96-
.then(() => setPriority(p))
116+
try {
117+
await transmission.setTorrent(props.torrents, { bandwidthPriority: p })
118+
setPriority(p)
119+
} catch (err) {
120+
await dispatch(notifyRequestError({
121+
to: 'transmission', errorMessage: err, description: `setting torrent priority: ${props.torrents}`
122+
}))
123+
}
97124
}
98125
}
99126
const onRootClick = (e: React.MouseEvent) => {
@@ -112,36 +139,68 @@ export function PriorityItem(props: ContextItemProps) {
112139
}
113140

114141
export function MoveToTopItem(props: ContextItemProps) {
142+
const dispatch = useDispatch()
115143
const { transmission } = useContext(ClientContext)
116-
const onClick = () => {
117-
transmission.moveTorrentsToTop(props.torrents)
144+
const onClick = async () => {
145+
try {
146+
await transmission.moveTorrentsToTop(props.torrents)
147+
} catch (err) {
148+
await dispatch(notifyRequestError({
149+
to: 'transmission', errorMessage: err,
150+
description: `moving torrents to top of queue: ${props.torrents}`
151+
}))
152+
}
118153
}
119154

120155
return <li onClick={onClick}>Move to Top</li>;
121156
}
122157

123158
export function MoveToBottomItem(props: ContextItemProps) {
159+
const dispatch = useDispatch()
124160
const { transmission } = useContext(ClientContext)
125-
const onClick = () => {
126-
transmission.moveTorrentsToBottom(props.torrents)
161+
const onClick = async () => {
162+
try {
163+
await transmission.moveTorrentsToBottom(props.torrents)
164+
} catch (err) {
165+
await dispatch(notifyRequestError({
166+
to: 'transmission', errorMessage: err,
167+
description: `moving torrents to bottom of queue: ${props.torrents}`
168+
}))
169+
}
127170
}
128171

129172
return <li onClick={onClick}>Move to Bottom</li>;
130173
}
131174

132175
export function MoveUpItem(props: ContextItemProps) {
176+
const dispatch = useDispatch()
133177
const { transmission } = useContext(ClientContext)
134-
const onClick = () => {
135-
transmission.moveTorrentsUp(props.torrents)
178+
const onClick = async () => {
179+
try {
180+
await transmission.moveTorrentsUp(props.torrents)
181+
} catch (err) {
182+
await dispatch(notifyRequestError({
183+
to: 'transmission', errorMessage: err,
184+
description: `moving torrents up in queue: ${props.torrents}`
185+
}))
186+
}
136187
}
137188

138189
return <li onClick={onClick}>Move Up</li>;
139190
}
140191

141192
export function MoveDownItem(props: ContextItemProps) {
193+
const dispatch = useDispatch()
142194
const { transmission } = useContext(ClientContext)
143-
const onClick = () => {
144-
transmission.moveTorrentsDown(props.torrents)
195+
const onClick = async () => {
196+
try {
197+
transmission.moveTorrentsDown(props.torrents)
198+
} catch (err) {
199+
await dispatch(notifyRequestError({
200+
to: 'transmission', errorMessage: err,
201+
description: `moving torrents down queue: ${props.torrents}`
202+
}))
203+
}
145204
}
146205

147206
return <li onClick={onClick}>Move Down</li>;

client/components/overlays/settings/views/network/index.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useContext } from 'react';
22
import { useDispatch } from 'react-redux';
33

4-
import { syncSession } from '@client/stores';
4+
import { syncSession, notifyRequestError } from '@client/stores';
55

66
import { sessionSelector, useStateFromSelector } from '../../utils';
77
import { Form, Section, Row } from '../../controls';
@@ -20,21 +20,29 @@ export function NetworkView() {
2020
const [enableUTP, setEnableUTP] = useStateFromSelector(sessionSelector(s => s['utp-enabled']));
2121
const [peerPort, setPeerPort] = useStateFromSelector(sessionSelector(s => s['peer-port']));
2222

23-
const onSubmit = () => {
23+
const onSubmit = async () => {
2424
setMessages([])
2525
if (isNaN(peerPort) || peerPort === 0) {
2626
setMessages([{ level: MessageLevel.ERROR, label: 'port number must be a valid non-zero number' }])
2727
return
2828
}
2929

30-
// TODO handle error
31-
return transmission.setSession({
32-
'peer-port-random-on-start': randomizePortOnLaunch,
33-
'port-forwarding-enabled': usePortForwarding,
34-
'utp-enabled': enableUTP,
35-
'peer-port': peerPort,
36-
}).then(() => setMessages([{ level: MessageLevel.INFO, label: 'succesfully synced settings' }]))
37-
.then(() => dispatch(syncSession(transmission)))
30+
try {
31+
await transmission.setSession({
32+
'peer-port-random-on-start': randomizePortOnLaunch,
33+
'port-forwarding-enabled': usePortForwarding,
34+
'utp-enabled': enableUTP,
35+
'peer-port': peerPort,
36+
})
37+
38+
setMessages([{ level: MessageLevel.INFO, label: 'succesfully synced settings' }])
39+
await dispatch(syncSession(transmission))
40+
} catch (err) {
41+
setMessages([{ level: MessageLevel.ERROR, label: 'failed to sync settings with transmission' }])
42+
await dispatch(notifyRequestError({
43+
to: 'transmission', errorMessage: err.toString(), description: 'syncing transmission network settings'
44+
}))
45+
}
3846
}
3947

4048
return (

client/components/overlays/settings/views/speed/index.tsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState, useContext } from 'react';
22
import { useDispatch } from 'react-redux';
33

44
import { padString } from '@client/utils';
5-
import { syncSession } from '@client/stores';
5+
import { syncSession, notifyRequestError } from '@client/stores';
66

77
import { Form, Section, Row } from '../../controls';
88
import { sessionSelector, useStateFromSelector } from '../../utils';
@@ -63,7 +63,7 @@ export function SpeedView() {
6363

6464
const selectedAltSpeedDaysOption = SCHEDULE_DAY_OPTIONS.find(o => o.value === altSpeedDays)
6565

66-
const onSubmit = () => {
66+
const onSubmit = async () => {
6767
const newMessages: MessageType[] = []
6868
let failed = false
6969
if (isNaN(uploadLimit)) {
@@ -89,20 +89,28 @@ export function SpeedView() {
8989
setMessages(newMessages)
9090
if (failed) return false
9191

92-
// TODO handle error
93-
return transmission.setSession({
94-
'speed-limit-up': uploadLimit,
95-
'speed-limit-down': downloadLimit,
96-
'speed-limit-up-enabled': allowUploadLimit,
97-
'speed-limit-down-enabled': allowDownloadLimit,
98-
'alt-speed-up': altUploadLimit,
99-
'alt-speed-down': altDownloadLimit,
100-
'alt-speed-time-enabled': useScheduledTimes,
101-
'alt-speed-time-day': altSpeedDays,
102-
'alt-speed-time-begin': altSpeedTimeBegin,
103-
'alt-speed-time-end': altSpeedTimeEnd,
104-
}).then(() => setMessages([{ level: MessageLevel.INFO, label: 'succesfully synced settings' }]))
105-
.then(() => dispatch(syncSession(transmission)))
92+
try {
93+
await transmission.setSession({
94+
'speed-limit-up': uploadLimit,
95+
'speed-limit-down': downloadLimit,
96+
'speed-limit-up-enabled': allowUploadLimit,
97+
'speed-limit-down-enabled': allowDownloadLimit,
98+
'alt-speed-up': altUploadLimit,
99+
'alt-speed-down': altDownloadLimit,
100+
'alt-speed-time-enabled': useScheduledTimes,
101+
'alt-speed-time-day': altSpeedDays,
102+
'alt-speed-time-begin': altSpeedTimeBegin,
103+
'alt-speed-time-end': altSpeedTimeEnd,
104+
})
105+
106+
setMessages([{ level: MessageLevel.INFO, label: 'succesfully synced settings' }])
107+
dispatch(syncSession(transmission))
108+
} catch (err) {
109+
setMessages([{ level: MessageLevel.ERROR, label: 'failed to sync settings with transmission' }])
110+
await dispatch(notifyRequestError({
111+
to: 'transmission', errorMessage: err.toString(), description: 'syncing transmission speed settings'
112+
}))
113+
}
106114
}
107115

108116
return (

client/components/overlays/settings/views/torrents/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function TorrentsView() {
5959
} catch (err) {
6060
setMessages([{ level: MessageLevel.ERROR, label: 'failed to sync settings with transmission' }])
6161
await dispatch(notifyRequestError({
62-
to: 'transmission', errorMessage: err.toString(), description: 'syncing transmission session settings'
62+
to: 'transmission', errorMessage: err.toString(), description: 'syncing transmission torrent settings'
6363
}))
6464
}
6565
}

client/components/sidebar/buttons/alt-speed.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useContext } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
33

4-
import { faTurtle } from '@client/utils/fontawesome';
4+
import { faFeather } from '@fortawesome/free-solid-svg-icons';
55

66
import {
7-
altSpeedToggled, selectAltSpeedEnabled
7+
altSpeedToggled, selectAltSpeedEnabled, notifyRequestError
88
} from '@client/stores';
99
import { ClientContext, TooltipButton } from '@client/components';
1010

@@ -13,18 +13,22 @@ export function ToggleAltSpeedButton() {
1313
const { transmission } = useContext(ClientContext)
1414
const isActive = useSelector(selectAltSpeedEnabled);
1515

16-
const onClick = () => {
17-
if (transmission)
18-
// TODO show notification when this fails
19-
transmission.setSession({'alt-speed-enabled': !isActive})
20-
.then(() => dispatch(altSpeedToggled({ value: !isActive })))
16+
const onClick = async () => {
17+
try {
18+
await transmission.setSession({'alt-speed-enabled': !isActive})
19+
dispatch(altSpeedToggled({ value: !isActive }))
20+
} catch (err) {
21+
await dispatch(notifyRequestError({
22+
to: 'transmission', errorMessage: err.toString(), description: 'toggling alt-speed'
23+
}))
24+
}
2125
}
2226

2327
return (
2428
<TooltipButton
2529
className={isActive ? 'selected' : ''}
2630
onClick={onClick}
27-
icon={faTurtle}
31+
icon={faFeather}
2832
tooltip={`${isActive ? 'Disable' : 'Enable'} Alt Speed`} />
2933
);
3034
}

client/components/sidebar/filters/search.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { DelayInput } from 'react-delay-input';
1212
* searching. The shorter it is, the more bogus searches will take
1313
* place. The longer it is, the less intuitive the search feels.
1414
*
15-
* TODO calibrate to feel just right.
1615
*/
1716
const QUERY_SET_TIMEOUT = 100
1817

client/utils/fontawesome.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ export const faInfinity: IconDefinition = {
1818
}
1919

2020
// This is the pro faTurtle icon. I'm too lazy to find
21-
// an alternative, but TODO find one before release.
22-
export const faTurtle: IconDefinition = {
23-
"prefix": "fas",
24-
"iconName": "turtle",
25-
"icon": [
26-
576,
27-
512,
28-
[],
29-
"",
30-
"M68.25 256h279.51c23.54 0 40.97-19.8 35.1-40.04C362.84 146.97 292.33 64 208.41 64h-.82c-83.91 0-154.43 82.97-174.44 151.96C27.27 236.2 44.71 256 68.25 256zm484.03-118.75l-48.65-34.75c-35.17-17.42-80.49 1.57-86.81 40.31-.54 3.32-.82 6.72-.82 10.19v71.22c-.03 13.88-4.6 27.18-13.27 38.44-12.42 16.11-31.25 25.34-51.68 25.34H18.6C8.33 288 0 296.33 0 306.6c0 8 5.12 15.11 12.71 17.64l98.29 22.1L66.17 424c-6.16 10.67 1.54 24 13.86 24h36.95c5.71 0 11-3.05 13.86-8l40.3-69.8c25.99 8.52 45.55 13.8 84.87 13.8s58.89-5.28 84.87-13.8l40.3 69.8c2.86 4.95 8.14 8 13.86 8h36.95c12.32 0 20.01-13.33 13.86-24l-47.21-81.76c21.25-8.42 40.36-21.78 54.81-40.53 14.08-18.28 22.47-39.4 25.29-61.7h40.62c31.29 0 56.65-25.36 56.65-56.65a56.7 56.7 0 0 0-23.73-46.11zM480 176c-8.84 0-16-7.16-16-16s7.16-16 16-16 16 7.16 16 16-7.16 16-16 16z"
31-
]
32-
}
33-
3421
export const faTint: IconDefinition = {
3522
"prefix": "fas",
3623
"iconName": "tint",

transmission/base.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ export default abstract class Transmission {
6363
*/
6464
private requestInit = (params: any): RequestInit => {
6565
if (this.requestTag) {
66-
// WARN mutates params in place, TODO check
67-
// whether there's any benefit to cloning it.
66+
// WARN mutates params in place
6867
params.tag = this.requestTag
6968
}
7069

transmission/client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ export * from './shared';
22
import TransmissionBase from './base';
33

44
// client transmission interface, this just redirects
5-
// all transmission requests to the puddle server and
6-
// TODO finish thought.
5+
// all transmission requests to the puddle server.
76

87
export interface TransmissionSerialised {
98
sessionId: string

0 commit comments

Comments
 (0)