11'use client' ;
22
3+ import { useRef } from 'react' ;
34import { motion , useMotionValue , useTransform } from 'framer-motion' ;
45import { MapPin , Building2 , DollarSign , Wifi } from 'lucide-react' ;
56
67const SWIPE_THRESHOLD = 100 ;
8+ const TAP_THRESHOLD = 5 ; // Max pixels moved to count as a tap
79
810export default function SwipeCard ( {
911 job,
@@ -13,12 +15,24 @@ export default function SwipeCard({
1315 isBackground = false ,
1416} ) {
1517 const x = useMotionValue ( 0 ) ;
18+ const hasDragged = useRef ( false ) ;
1619
1720 // Transform x position to rotation and opacity
1821 const rotate = useTransform ( x , [ - 200 , 0 , 200 ] , [ - 15 , 0 , 15 ] ) ;
1922 const likeOpacity = useTransform ( x , [ 0 , 100 ] , [ 0 , 1 ] ) ;
2023 const nopeOpacity = useTransform ( x , [ - 100 , 0 ] , [ 1 , 0 ] ) ;
2124
25+ const handleDragStart = ( ) => {
26+ hasDragged . current = false ;
27+ } ;
28+
29+ const handleDrag = ( event , info ) => {
30+ // Mark as dragged if moved beyond tap threshold
31+ if ( Math . abs ( info . offset . x ) > TAP_THRESHOLD ) {
32+ hasDragged . current = true ;
33+ }
34+ } ;
35+
2236 const handleDragEnd = ( event , info ) => {
2337 if ( info . offset . x > SWIPE_THRESHOLD ) {
2438 onSwipeRight ?. ( ) ;
@@ -27,6 +41,13 @@ export default function SwipeCard({
2741 }
2842 } ;
2943
44+ const handleClick = ( ) => {
45+ // Only trigger tap if user didn't drag
46+ if ( ! hasDragged . current ) {
47+ onTap ?. ( ) ;
48+ }
49+ } ;
50+
3051 // Format salary display
3152 const formatSalary = ( ) => {
3253 if ( job . salaryMin && job . salaryMax ) {
@@ -71,10 +92,12 @@ export default function SwipeCard({
7192 drag = "x"
7293 dragConstraints = { { left : 0 , right : 0 } }
7394 dragElastic = { 0.7 }
95+ onDragStart = { handleDragStart }
96+ onDrag = { handleDrag }
7497 onDragEnd = { handleDragEnd }
7598 style = { { x, rotate } }
7699 whileTap = { { scale : 0.98 } }
77- onClick = { onTap }
100+ onClick = { handleClick }
78101 >
79102 { /* Like indicator */ }
80103 < motion . div
0 commit comments