Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add esc key to caps selector

Richie McIlroyfd169be777dc
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 227021087..262986fe3 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -71,6 +71,49 @@ export const Caps = ({
fetchAnalytics();
}, [data]);
+ useEffect(() => {
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape" && selectedCaps.length > 0) {
+ setSelectedCaps([]);
+ }
+
+ if (
+ (e.key === "Delete" || e.key === "Backspace") &&
+ selectedCaps.length > 0
+ ) {
+ if (e.key === "Backspace") {
+ e.preventDefault();
+ }
+
+ if (
+ !["INPUT", "TEXTAREA", "SELECT"].includes(
+ document.activeElement?.tagName || ""
+ )
+ ) {
+ deleteSelectedCaps();
+ }
+ }
+
+ if (e.key === "a" && (e.ctrlKey || e.metaKey) && data.length > 0) {
+ if (
+ !["INPUT", "TEXTAREA", "SELECT"].includes(
+ document.activeElement?.tagName || ""
+ )
+ ) {
+ e.preventDefault();
+ setSelectedCaps(data.map((cap) => cap.id));
+ setAnimateDirection("up");
+ }
+ }
+ };
+
+ window.addEventListener("keydown", handleKeyDown);
+
+ return () => {
+ window.removeEventListener("keydown", handleKeyDown);
+ };
+ }, [selectedCaps.length, data]);
+
const deleteCap = async (videoId: string) => {
if (
!window.confirm(
@@ -98,7 +141,6 @@ export const Caps = ({
? prev.filter((id) => id !== capId)
: [...prev, capId];
- // Set animation direction based on count change
previousCountRef.current = prev.length;
setAnimateDirection(newSelection.length > prev.length ? "up" : "down");
diff --git a/apps/web/app/dashboard/caps/components/CapCard.tsx b/apps/web/app/dashboard/caps/components/CapCard.tsx
index c4506a51a..3abd579cf 100644
--- a/apps/web/app/dashboard/caps/components/CapCard.tsx
+++ b/apps/web/app/dashboard/caps/components/CapCard.tsx
@@ -330,7 +330,6 @@ export const CapCard: React.FC<CapCardProps> = ({
</Tooltip>
</div>
)}
- {/* Selection checkbox */}
{!sharedCapCard && onSelectToggle && (
<div
className={`absolute top-2 left-2 z-[20] duration-200 ${