11import { useKeyboard } from "@opentui/react" ;
2- import { useQuery } from "@tanstack/react-query" ;
2+ import { useMutation , useQuery } from "@tanstack/react-query" ;
33import { useRefreshConfig } from "../../contexts/refresh-config" ;
44import { useRegisterKeyBind } from "../../contexts/registered-keybinds" ;
55import { useRoute } from "../../routing/provider" ;
@@ -29,6 +29,19 @@ export function EntryDetails(props: Props) {
2929 } ,
3030 } ) ;
3131
32+ const deleteMutation = useMutation ( {
33+ mutationKey : [ "redis" , "delete-key" , props . pathKey ] ,
34+ mutationFn : async ( ) => {
35+ // Delete the key
36+ const redis = ( await import ( "../../redis" ) ) . getRedis ( ) ;
37+ await redis . del ( props . pathKey ) ;
38+ } ,
39+ onSuccess : ( ) => {
40+ // Go back to previous route
41+ router . previousRoute != null && router . setRoute ( router . previousRoute ) ;
42+ } ,
43+ } ) ;
44+
3245 useKeyboard ( ( key ) => {
3346 if ( ! props . focussed ) {
3447 return ;
@@ -49,15 +62,15 @@ export function EntryDetails(props: Props) {
4962 query . refetch ( ) ;
5063 }
5164 } , refreshInterval ) ;
52- useRegisterKeyBind ( "ctrl +r" , "Refresh" ) ;
65+ useRegisterKeyBind ( "shift +r" , "Refresh" ) ;
5366 useRegisterKeyBind ( "r" , `${ autoRefresh ? "Disable" : "Enable" } auto-refresh` ) ;
5467 useKeyboard ( ( key ) => {
5568 if ( ! props . focussed ) {
5669 return ;
5770 }
5871 if ( key . name === "r" ) {
5972 key . preventDefault ( ) ;
60- if ( key . ctrl ) {
73+ if ( key . shift ) {
6174 query . refetch ( ) ;
6275 } else {
6376 setAutoRefresh ( ( current ) => ! current ) ;
@@ -80,6 +93,17 @@ export function EntryDetails(props: Props) {
8093 }
8194 } ) ;
8295
96+ useRegisterKeyBind ( "shift+d" , "Delete key" ) ;
97+ useKeyboard ( ( key ) => {
98+ if ( ! props . focussed ) {
99+ return ;
100+ }
101+ if ( key . name === "d" && key . shift ) {
102+ key . preventDefault ( ) ;
103+ deleteMutation . mutate ( ) ;
104+ }
105+ } ) ;
106+
83107 return (
84108 < box
85109 borderColor = "cyan"
0 commit comments