Skip to content

Commit 466813a

Browse files
feat: ✨ add ability to delete a key
1 parent e0a3530 commit 466813a

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/components/functional/browser/browser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ export function Browser(props: Props) {
210210
query.refetch();
211211
}
212212
}, getConfig().refreshInterval);
213-
useRegisterKeyBind("ctrl+r", "Refresh");
213+
useRegisterKeyBind("shift+r", "Refresh");
214214
useRegisterKeyBind("r", `${autoRefresh ? "Disable" : "Enable"} auto-refresh`);
215215
useKeyboard((key) => {
216216
if (focus !== "key-list") {
217217
return;
218218
}
219219
if (key.name === "r") {
220220
key.preventDefault();
221-
if (key.ctrl) {
221+
if (key.shift) {
222222
query.refetch();
223223
} else {
224224
setAutoRefresh((current) => !current);

src/components/functional/entry-detail-view.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useKeyboard } from "@opentui/react";
2-
import { useQuery } from "@tanstack/react-query";
2+
import { useMutation, useQuery } from "@tanstack/react-query";
33
import { useRefreshConfig } from "../../contexts/refresh-config";
44
import { useRegisterKeyBind } from "../../contexts/registered-keybinds";
55
import { 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

Comments
 (0)