feat(haptics): tactile feedback on primary mobile actions

lib/haptics.ts wraps the Vibration API with feature detection + try/catch so
the call is a safe no-op on iOS Safari (Apple removed the API in 2017) and
desktops, and fires a 10ms tick on Chrome Android — short enough to read as
confirmation, not a buzz.

Wired into:
- ApproveGroupButton (bulk "Approve all" on Action Queue)
- ActionButtons (per-row Approve / Reject)
- FeaturedCard "Run Now" (Prompt Library hero CTA)

Purely additive — no UI surface, no fallback, no error path. The original
Elon-led mobile review queue called these out as the dopamine-hit slots
that make a tap feel like "the thing happened" instead of "did it work?".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Opus 4.7 committed 2026-05-20 19:51:09 +02:00
1 parent 474c56f469
commit 8889c9ffc6
4 files changed
+28 -1

No files matched your search

+2 -1
View File
@@ -4,6 +4,7 @@ import { Zap, Clock } from "lucide-react";
import { usePromptModals } from "./use-prompt-modals";
import { CATEGORY_META, type PromptTemplate } from "@/config/prompt-library";
import type { Project } from "./types";
import { haptic } from "@/lib/haptics";
/** Larger card used in the Quick Access grid above category sections. */
export function FeaturedCard({
@@ -30,7 +31,7 @@ export function FeaturedCard({
</div>
<div className="flex gap-2 mt-auto">
<button
onClick={openRun}
onClick={() => { haptic(); openRun(); }}
className="ui-btn-lg flex flex-1 items-center justify-center gap-2"
>
<Zap className="h-4 w-4" /> Run Now
+3
View File
@@ -4,6 +4,7 @@ import { Check, X } from "lucide-react";
import { handleApprove, handleReject } from "@/app/actions";
import { useState } from "react";
import { ACTION_STATUS } from "@/lib/constants/statuses";
import { haptic } from "@/lib/haptics";
type DoneStatus = typeof ACTION_STATUS.APPROVED | typeof ACTION_STATUS.REJECTED;
@@ -19,6 +20,7 @@ export function ActionButtons({
const [error, setError] = useState<string | null>(null);
async function onApprove() {
haptic();
setBusy(true);
setError(null);
try {
@@ -32,6 +34,7 @@ export function ActionButtons({
}
async function onReject() {
haptic();
setBusy(true);
setError(null);
try {
@@ -3,6 +3,7 @@
import { Check, Loader2 } from "lucide-react";
import { useState } from "react";
import { handleApproveAll } from "@/app/actions";
import { haptic } from "@/lib/haptics";
export function ApproveGroupButton({ ids }: { ids: string[] }) {
const [busy, setBusy] = useState(false);
@@ -20,6 +21,7 @@ export function ApproveGroupButton({ ids }: { ids: string[] }) {
return (
<button
onClick={async () => {
haptic();
setBusy(true);
setError(false);
try {
+21
View File
@@ -0,0 +1,21 @@
/**
* Tiny wrapper around the Vibration API for primary-action tactile feedback.
*
* Browser support is uneven: Chrome Android fires, iOS Safari is a no-op
* (Apple removed the API in 2017 — Safari accepts the call but does nothing).
* Desktops typically ignore it. So this is purely additive — no fallback,
* no UI surface, no error path. If support is absent or the user has disabled
* vibration, the call silently does nothing.
*
* Default 10ms = "tick" duration; matches iOS UISelectionFeedback / Material
* "soft" feel — short enough that the user perceives it as confirmation,
* not a buzz.
*/
export function haptic(durationMs: number = 10): void {
if (typeof navigator === "undefined" || typeof navigator.vibrate !== "function") return;
try {
navigator.vibrate(durationMs);
} catch {
// Some browsers throw on programmatic vibrate without a user gesture; ignore.
}
}