@@ -7,7 +7,7 @@ import { TransmissionPriorityType as PriorityType } from '@transmission';
77import {
88 RootState , showTorrentDetails , setLabelsOverlayAssigned ,
99 removeTorrentOverlayAssigned , selectTorrentById ,
10- setTorrentLocationOverlayAssigned
10+ setTorrentLocationOverlayAssigned , notifyRequestError
1111} from '@client/stores' ;
1212
1313import {
@@ -20,19 +20,32 @@ export interface ContextItemProps {
2020}
2121
2222export 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
3238export 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
5164export 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
114141export 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
123158export 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
132175export 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
141192export 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 > ;
0 commit comments