@@ -3,6 +3,7 @@ import { For, Show, Suspense, createSignal } from "solid-js";
3
3
import { convertFileSrc } from "@tauri-apps/api/core" ;
4
4
5
5
import { commands , events } from "~/utils/tauri" ;
6
+ import { createQueryInvalidate } from "~/utils/events" ;
6
7
7
8
type MediaEntry = {
8
9
id : string ;
@@ -13,38 +14,52 @@ type MediaEntry = {
13
14
} ;
14
15
15
16
export default function Recordings ( ) {
16
- const fetchRecordings = createQuery ( ( ) => ( {
17
- queryKey : [ "recordings" ] ,
18
- queryFn : async ( ) => {
19
- const result = await commands
20
- . listRecordings ( )
21
- . catch (
22
- ( ) =>
23
- Promise . resolve ( [ ] ) as ReturnType < typeof commands . listRecordings >
17
+ function fetchRecordingsQuery ( ) {
18
+ const fetchRecordings = createQuery ( ( ) => ( {
19
+ queryKey : [ "recordings" ] ,
20
+ queryFn : async ( ) => {
21
+ const result = await commands
22
+ . listRecordings ( )
23
+ . catch (
24
+ ( ) =>
25
+ Promise . resolve ( [ ] ) as ReturnType < typeof commands . listRecordings >
26
+ ) ;
27
+
28
+ const recordings = await Promise . all (
29
+ result . map ( async ( file ) => {
30
+ const [ id , path , meta ] = file ;
31
+ const thumbnailPath = `${ path } /screenshots/display.jpg` ;
32
+
33
+ return {
34
+ id,
35
+ path,
36
+ prettyName : meta . pretty_name ,
37
+ isNew : false ,
38
+ thumbnailPath,
39
+ } ;
40
+ } )
24
41
) ;
42
+ return recordings ;
43
+ } ,
44
+ staleTime : 0 ,
45
+ } ) ) ;
25
46
26
- const recordings = await Promise . all (
27
- result . map ( async ( file ) => {
28
- const [ id , path , meta ] = file ;
29
- const thumbnailPath = `${ path } /screenshots/display.jpg` ;
47
+ createQueryInvalidate ( fetchRecordings , "recordingDeleted" ) ;
30
48
31
- return {
32
- id,
33
- path,
34
- prettyName : meta . pretty_name ,
35
- isNew : false ,
36
- thumbnailPath,
37
- } ;
38
- } )
39
- ) ;
40
- return recordings ;
41
- } ,
42
- } ) ) ;
49
+ return fetchRecordings ;
50
+ }
43
51
44
- const handleRecordingClick = ( recording : MediaEntry ) => {
52
+ const recordings = fetchRecordingsQuery ( ) ;
53
+
54
+ const handleOpenRecording = ( recording : MediaEntry ) => {
45
55
events . newRecordingAdded . emit ( { path : recording . path } ) ;
46
56
} ;
47
57
58
+ const handleDeleteRecording = ( path : string ) => {
59
+ commands . deleteFile ( path ) ;
60
+ events . recordingDeleted . emit ( { path } ) ;
61
+ } ;
62
+
48
63
const handleOpenFolder = ( path : string ) => {
49
64
commands . openFilePath ( path ) ;
50
65
} ;
@@ -60,18 +75,21 @@ export default function Recordings() {
60
75
< div class = "flex-1 overflow-y-auto" >
61
76
< ul class = "p-[0.625rem] flex flex-col gap-[0.5rem] w-full" >
62
77
< Show
63
- when = { fetchRecordings . data && fetchRecordings . data . length > 0 }
78
+ when = { recordings . data && recordings . data . length > 0 }
64
79
fallback = {
65
80
< p class = "text-center text-gray-500" > No recordings found</ p >
66
81
}
67
82
>
68
- < For each = { fetchRecordings . data } >
83
+ < For each = { recordings . data } >
69
84
{ ( recording ) => (
70
85
< RecordingItem
71
86
recording = { recording }
72
- onClick = { ( ) => handleRecordingClick ( recording ) }
73
87
onOpenFolder = { ( ) => handleOpenFolder ( recording . path ) }
74
88
onOpenEditor = { ( ) => handleOpenEditor ( recording . path ) }
89
+ onOpenRecording = { ( ) => handleOpenRecording ( recording ) }
90
+ onDeleteRecording = { ( ) =>
91
+ handleDeleteRecording ( recording . path )
92
+ }
75
93
/>
76
94
) }
77
95
</ For >
@@ -84,9 +102,10 @@ export default function Recordings() {
84
102
85
103
function RecordingItem ( props : {
86
104
recording : MediaEntry ;
87
- onClick : ( ) => void ;
88
105
onOpenFolder : ( ) => void ;
89
106
onOpenEditor : ( ) => void ;
107
+ onOpenRecording : ( ) => void ;
108
+ onDeleteRecording : ( ) => void ;
90
109
} ) {
91
110
const [ imageExists , setImageExists ] = createSignal ( true ) ;
92
111
@@ -133,12 +152,22 @@ function RecordingItem(props: {
133
152
type = "button"
134
153
onClick = { ( e ) => {
135
154
e . stopPropagation ( ) ;
136
- props . onClick ( ) ;
155
+ props . onOpenRecording ( ) ;
137
156
} }
138
157
class = "p-2 hover:bg-gray-200 rounded-full"
139
158
>
140
159
< IconLucideEye class = "size-5" />
141
160
</ button >
161
+ < button
162
+ type = "button"
163
+ onClick = { ( e ) => {
164
+ e . stopPropagation ( ) ;
165
+ props . onDeleteRecording ( ) ;
166
+ } }
167
+ class = "p-2 hover:bg-gray-200 rounded-full"
168
+ >
169
+ < IconCapTrash class = "size-5" />
170
+ </ button >
142
171
</ div >
143
172
</ li >
144
173
) ;
0 commit comments