@@ -9,35 +9,36 @@ import {
9
9
IconRefresh ,
10
10
IconRotateClockwise ,
11
11
IconTrash ,
12
- IconX ,
13
12
} from '@tabler/icons' ;
14
13
import axios from 'axios' ;
15
14
import Dockerode from 'dockerode' ;
16
15
import { tryMatchService } from '../../../tools/addToHomarr' ;
17
- import { useConfig } from '../../../tools/state' ;
18
16
import { AddAppShelfItemForm } from '../../AppShelf/AddAppShelfItem' ;
19
17
20
- function sendDockerCommand ( action : string , containerId : string , containerName : string ) {
18
+ function sendDockerCommand (
19
+ action : string ,
20
+ containerId : string ,
21
+ containerName : string ,
22
+ reload : ( ) => void
23
+ ) {
21
24
showNotification ( {
22
25
id : containerId ,
23
26
loading : true ,
24
- title : `${ action } ing container ${ containerName . substring ( 1 ) } ` ,
27
+ title : `${ action } ing container ${ containerName } ` ,
25
28
message : undefined ,
26
29
autoClose : false ,
27
30
disallowClose : true ,
28
31
} ) ;
29
32
axios
30
33
. get ( `/api/docker/container/${ containerId } ?action=${ action } ` )
31
34
. then ( ( res ) => {
32
- if ( res . data . success === true ) {
33
- updateNotification ( {
34
- id : containerId ,
35
- title : `Container ${ containerName } ${ action } ed` ,
36
- message : `Your container was successfully ${ action } ed` ,
37
- icon : < IconCheck /> ,
38
- autoClose : 2000 ,
39
- } ) ;
40
- }
35
+ updateNotification ( {
36
+ id : containerId ,
37
+ title : `Container ${ containerName } ${ action } ed` ,
38
+ message : `Your container was successfully ${ action } ed` ,
39
+ icon : < IconCheck /> ,
40
+ autoClose : 2000 ,
41
+ } ) ;
41
42
} )
42
43
. catch ( ( err ) => {
43
44
updateNotification ( {
@@ -47,6 +48,9 @@ function sendDockerCommand(action: string, containerId: string, containerName: s
47
48
message : err . response . data . reason ,
48
49
autoClose : 2000 ,
49
50
} ) ;
51
+ } )
52
+ . finally ( ( ) => {
53
+ reload ( ) ;
50
54
} ) ;
51
55
}
52
56
@@ -56,7 +60,6 @@ export interface ContainerActionBarProps {
56
60
}
57
61
58
62
export default function ContainerActionBar ( { selected, reload } : ContainerActionBarProps ) {
59
- const { config, setConfig } = useConfig ( ) ;
60
63
const [ opened , setOpened ] = useBooleanToggle ( false ) ;
61
64
return (
62
65
< Group >
@@ -78,19 +81,9 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
78
81
onClick = { ( ) =>
79
82
Promise . all (
80
83
selected . map ( ( container ) =>
81
- sendDockerCommand ( 'restart' , container . Id , container . Names [ 0 ] . substring ( 1 ) )
84
+ sendDockerCommand ( 'restart' , container . Id , container . Names [ 0 ] . substring ( 1 ) , reload )
82
85
)
83
86
)
84
- . catch ( ( err ) => {
85
- showNotification ( {
86
- color : 'red' ,
87
- title : 'There was an error with your container.' ,
88
- message : err . message ,
89
- icon : < IconX /> ,
90
- autoClose : 2000 ,
91
- } ) ;
92
- } )
93
- . then ( ( ) => reload ( ) )
94
87
}
95
88
variant = "light"
96
89
color = "orange"
@@ -103,9 +96,9 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
103
96
onClick = { ( ) =>
104
97
Promise . all (
105
98
selected . map ( ( container ) =>
106
- sendDockerCommand ( 'stop' , container . Id , container . Names [ 0 ] . substring ( 1 ) )
99
+ sendDockerCommand ( 'stop' , container . Id , container . Names [ 0 ] . substring ( 1 ) , reload )
107
100
)
108
- ) . then ( ( ) => reload ( ) )
101
+ )
109
102
}
110
103
variant = "light"
111
104
color = "red"
@@ -118,9 +111,9 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
118
111
onClick = { ( ) =>
119
112
Promise . all (
120
113
selected . map ( ( container ) =>
121
- sendDockerCommand ( 'start' , container . Id , container . Names [ 0 ] . substring ( 1 ) )
114
+ sendDockerCommand ( 'start' , container . Id , container . Names [ 0 ] . substring ( 1 ) , reload )
122
115
)
123
- ) . then ( ( ) => reload ( ) )
116
+ )
124
117
}
125
118
variant = "light"
126
119
color = "green"
@@ -140,7 +133,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
140
133
if ( selected . length !== 1 ) {
141
134
showNotification ( {
142
135
autoClose : 5000 ,
143
- title : < Title order = { 4 } > Please only add one service at a time!</ Title > ,
136
+ title : < Title order = { 5 } > Please only add one service at a time!</ Title > ,
144
137
color : 'red' ,
145
138
message : undefined ,
146
139
} ) ;
@@ -158,18 +151,10 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
158
151
radius = "md"
159
152
onClick = { ( ) =>
160
153
Promise . all (
161
- selected . map ( ( container ) => {
162
- if ( container . State === 'running' ) {
163
- return showNotification ( {
164
- id : container . Id ,
165
- title : `Failed to delete ${ container . Names [ 0 ] . substring ( 1 ) } ` ,
166
- message : "You can't delete a running container" ,
167
- autoClose : 1000 ,
168
- } ) ;
169
- }
170
- return sendDockerCommand ( 'remove' , container . Id , container . Names [ 0 ] . substring ( 1 ) ) ;
171
- } )
172
- ) . then ( ( ) => reload ( ) )
154
+ selected . map ( ( container ) =>
155
+ sendDockerCommand ( 'remove' , container . Id , container . Names [ 0 ] . substring ( 1 ) , reload )
156
+ )
157
+ )
173
158
}
174
159
>
175
160
Remove
0 commit comments