A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat(web): add haptic feedback on mobile sidebar navigation
Mohamed Bassemf91ec53160ea
diff --git a/apps/web/components.json b/apps/web/components.jsonindex fa674c93..f9a8bdc9 100644--- a/apps/web/components.json+++ b/apps/web/components.json@@ -10,8 +10,12 @@"cssVariables": true,"prefix": ""},+ "iconLibrary": "lucide","aliases": {"components": "@/components","utils": "@/lib/utils"+ },+ "registries": {+ "@ncdai": "https://chanhdai.com/r/{name}.json"}}diff --git a/apps/web/components/shared/sidebar/ModileSidebarItem.tsx b/apps/web/components/shared/sidebar/ModileSidebarItem.tsxindex 4d3436ea..e2cdf6ba 100644--- a/apps/web/components/shared/sidebar/ModileSidebarItem.tsx+++ b/apps/web/components/shared/sidebar/ModileSidebarItem.tsx@@ -2,6 +2,7 @@import Link from "next/link";import { usePathname } from "next/navigation";+import { haptic } from "@/lib/haptic";import { cn } from "@/lib/utils";export default function MobileSidebarItem({@@ -19,7 +20,7 @@ export default function MobileSidebarItem({path == currentPath ? "bg-background" : "",)}>- <Link href={path} className="m-auto px-3 py-2">+ <Link onClick={haptic} href={path} className="m-auto px-3 py-2">{logo}</Link></li>diff --git a/apps/web/lib/haptic.ts b/apps/web/lib/haptic.tsnew file mode 100644index 00000000..5a8b1f4c--- /dev/null+++ b/apps/web/lib/haptic.ts@@ -0,0 +1,53 @@+export const supportsHaptic =+ typeof window !== "undefined"+ ? window.matchMedia("(pointer: coarse)").matches+ : false;++/**+ * Type guard to check if navigator supports vibrate API+ */+function hasVibrate(+ nav: Navigator,+): nav is Navigator & { vibrate: (pattern: number | number[]) => boolean } {+ return "vibrate" in nav && typeof nav.vibrate === "function";+}++/**+ * Trigger haptic feedback on mobile devices.+ *+ * Uses Vibration API on Android/modern browsers, and iOS checkbox trick on iOS.+ *+ * @example+ * import { haptic } from "@/lib/haptic"+ *+ * <Button onClick={haptic}>Haptic</Button>+ */+export function haptic() {+ try {+ if (!supportsHaptic) return;++ if (hasVibrate(navigator)) {+ navigator.vibrate(50);+ return;+ }++ // iOS haptic trick via checkbox switch element+ const label = document.createElement("label");+ label.ariaHidden = "true";+ label.style.display = "none";++ const input = document.createElement("input");+ input.type = "checkbox";+ input.setAttribute("switch", "");+ label.appendChild(input);++ try {+ document.head.appendChild(label);+ label.click();+ } finally {+ document.head.removeChild(label);+ }+ } catch {+ // ignore+ }+}