File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export const Home = () => {
31
31
const navigate = useNavigate ( ) ;
32
32
const user = ( ) => params . user || context . user ( ) ?. display ;
33
33
34
- const [ repls ] = createResource < Repls , string > ( user , async ( user ) => {
34
+ const [ repls , { mutate } ] = createResource < Repls , string > ( user , async ( user ) => {
35
35
if ( ! user ) return { total : 0 , list : [ ] } ;
36
36
return await fetch ( `${ API } /repl/${ user } /list` ) . then ( ( r ) => r . json ( ) ) ;
37
37
} ) ;
@@ -101,7 +101,23 @@ export const Home = () => {
101
101
< td > { new Date ( repl . created_at ) . toLocaleString ( ) } </ td >
102
102
< td >
103
103
< Icon path = { repl . public ? eye : eyeOff } class = "w-6 inline m-2 ml-0" />
104
- < Icon path = { x } class = "w-6 inline m-2 mr-0 text-red-700" />
104
+ < Icon
105
+ path = { x }
106
+ class = "w-6 inline m-2 mr-0 text-red-700 cursor-pointer"
107
+ onClick = { async ( ) => {
108
+ fetch ( `${ API } /repl/${ repl . id } ` , {
109
+ method : 'DELETE' ,
110
+ headers : {
111
+ authorization : `Bearer ${ context . token } ` ,
112
+ } ,
113
+ } ) ;
114
+ const current = repls . latest ! ;
115
+ mutate ( {
116
+ total : current . total - 1 ,
117
+ list : current . list . filter ( ( x ) => x . id !== repl . id ) ,
118
+ } ) ;
119
+ } }
120
+ />
105
121
</ td >
106
122
</ tr >
107
123
) }
You can’t perform that action at this time.
0 commit comments