@@ -6,6 +6,7 @@ import { useUser } from '#context/User.tsx'
6
6
import { useViteEnv } from '#context/ViteEnv.tsx'
7
7
import { extendDeviceSharing } from '#resources/extendDeviceSharing.ts'
8
8
import { listUserDevices } from '#resources/listUserDevices.ts'
9
+ import { stopDeviceSharing } from '#resources/stopDeviceSharing.ts'
9
10
import { type ModelID , models } from '@hello.nrfcloud.com/proto-map/models'
10
11
import {
11
12
createEffect ,
@@ -15,7 +16,7 @@ import {
15
16
Show ,
16
17
Switch ,
17
18
} from 'solid-js'
18
- import { Card , CardBody , CardHeader } from './Card.tsx'
19
+ import { Card , CardBody , CardFooter , CardHeader } from './Card.tsx'
19
20
import { CopyableProp } from './CopyableProp.tsx'
20
21
21
22
const f = new Intl . DateTimeFormat ( undefined , {
@@ -25,6 +26,10 @@ const f = new Intl.DateTimeFormat(undefined, {
25
26
26
27
const formatAsDate = ( d : Date ) => f . format ( d )
27
28
29
+ import { Success } from '#component/notifications/Success.tsx'
30
+ import { Checked , Unchecked } from '#icons/LucideIcon.tsx'
31
+ import './ShowDevice.css'
32
+
28
33
export const ShowDevice = ( ) => {
29
34
const { protoVersion } = useViteEnv ( )
30
35
const deviceId = new URLSearchParams (
@@ -98,7 +103,26 @@ export const ShowDevice = () => {
98
103
>
99
104
< Problem class = "gap-t" problem = { devicesRequest . error } />
100
105
</ Show >
106
+ < Show
107
+ when = {
108
+ ! devicesRequest . loading &&
109
+ devicesRequest . error === undefined &&
110
+ deviceInfo ( ) === undefined
111
+ }
112
+ >
113
+ < Problem
114
+ problem = { {
115
+ status : 404 ,
116
+ title : `Device ${ deviceId } not found!` ,
117
+ } }
118
+ />
119
+ </ Show >
101
120
</ CardBody >
121
+ < Show when = { deviceInfo ( ) !== undefined } >
122
+ < CardFooter class = "stop-sharing" >
123
+ < StopSharing id = { deviceId ! } />
124
+ </ CardFooter >
125
+ </ Show >
102
126
</ Card >
103
127
)
104
128
}
@@ -157,3 +181,84 @@ const ExtendSharing = (props: { id: string; expires: Date }) => {
157
181
</ >
158
182
)
159
183
}
184
+
185
+ const StopSharing = ( props : { id : string } ) => {
186
+ const [ stop , setStopped ] = createSignal ( false )
187
+ const [ unlocked , setUnlocked ] = createSignal ( false )
188
+ const { jwt } = useUser ( )
189
+ const { apiURL } = useParameters ( )
190
+ const [ stopRequest ] = createResource ( ( ) => {
191
+ if ( ! stop ( ) ) return undefined
192
+ return {
193
+ id : props . id ,
194
+ jwt : jwt ( ) ! ,
195
+ }
196
+ } , stopDeviceSharing ( apiURL ) )
197
+
198
+ createEffect ( ( ) => {
199
+ if ( stopRequest . loading ) return
200
+ if ( stopRequest . state !== 'ready' ) return
201
+ setStopped ( true )
202
+ } )
203
+
204
+ return (
205
+ < >
206
+ < p >
207
+ You can stop the publication of this device at any time. If you stop the
208
+ publication, the device will no longer be visible on the map. You can
209
+ start the publication again at any time. It may take a few minutes for
210
+ the device to disappear from the map.
211
+ </ p >
212
+ < p class = "confirm" >
213
+ < button
214
+ class = "pad-e"
215
+ type = "button"
216
+ onClick = { ( ) => setUnlocked ( ( l ) => ! l ) }
217
+ >
218
+ < Show
219
+ when = { unlocked ( ) }
220
+ fallback = { < Unchecked strokeWidth = { 1 } size = { 20 } /> }
221
+ >
222
+ < Checked strokeWidth = { 1 } size = { 20 } />
223
+ </ Show >
224
+ Yes, I want to stop the publication of this device.
225
+ </ button >
226
+ < Show
227
+ when = { unlocked ( ) }
228
+ fallback = {
229
+ < Show
230
+ when = { ! stopRequest . loading }
231
+ fallback = {
232
+ < button type = "button" class = "btn" disabled >
233
+ stopping ...
234
+ </ button >
235
+ }
236
+ >
237
+ < button type = "button" class = "btn" disabled >
238
+ stop publication
239
+ </ button >
240
+ </ Show >
241
+ }
242
+ >
243
+ < button
244
+ type = "button"
245
+ class = "btn"
246
+ onClick = { ( ) => {
247
+ setStopped ( true )
248
+ } }
249
+ >
250
+ stop publication
251
+ </ button >
252
+ </ Show >
253
+ </ p >
254
+ < Switch >
255
+ < Match when = { ! stopRequest . loading && stopRequest . error !== undefined } >
256
+ < Problem class = "gap-t" problem = { stopRequest . error } />
257
+ </ Match >
258
+ < Match when = { ! stopRequest . loading && stopRequest . state === 'ready' } >
259
+ < Success > The publication of this device has been stopped.</ Success >
260
+ </ Match >
261
+ </ Switch >
262
+ </ >
263
+ )
264
+ }
0 commit comments