-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add animation to swiping (#40)
- Loading branch information
1 parent
54c907c
commit 07a295c
Showing
3 changed files
with
91 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ yarn-debug.log* | |
yarn-error.log* | ||
|
||
# coverage testing | ||
/coverage | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ const LandingPage = () => { | |
|
||
const [swipingResumes, setSwipingResumes] = useState([]); | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
const [swipeDirection, setSwipeDirection] = useState(null); // 'left' or 'right' | ||
const [isSwiping, setIsSwiping] = useState(false); | ||
|
||
const [openZoomModal, ZoomModal] = useZoomModal(); | ||
|
||
|
@@ -59,30 +61,40 @@ const LandingPage = () => { | |
|
||
console.log('Current Resume:', JSON.stringify(currentResume, null, 2)); // Log current resume | ||
|
||
if (!currentResume || !currentResume._id || !currentResume.uploader_id) { | ||
console.error('Invalid current resume structure:', currentResume); | ||
return; | ||
} | ||
if (!currentResume || !currentResume._id || !currentResume.uploader_id) { | ||
console.error('Invalid current resume structure:', currentResume); | ||
return; | ||
} | ||
|
||
setSwipeDirection(accept ? 'right' : 'left'); | ||
setIsSwiping(true); | ||
|
||
try { | ||
let axiosConfig = { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
setTimeout( async () => { | ||
try { | ||
let axiosConfig = { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
|
||
await axios.post(`http://localhost:3001/api/swipes/${userId}`, { | ||
user_id: userId, | ||
resume_id: currentResume._id, | ||
uploader_id: currentResume.uploader_id, | ||
accept: accept | ||
}, axiosConfig); | ||
await axios.post(`http://localhost:3001/api/swipes/${userId}`, { | ||
user_id: userId, | ||
resume_id: currentResume._id, | ||
uploader_id: currentResume.uploader_id, | ||
accept: accept | ||
}, axiosConfig); | ||
|
||
setCurrentIndex(prevIndex => prevIndex + 1); | ||
await checkMatches(userId, currentResume.uploader_id._id, currentResume._id); | ||
} catch (error) { | ||
console.error('Failed to swipe resume', error); | ||
} finally { | ||
// Reset the animation state to prepare for the next swipe | ||
setIsSwiping(false); | ||
setSwipeDirection(null); | ||
} | ||
}, 400); | ||
|
||
setCurrentIndex(prevIndex => prevIndex + 1); | ||
await checkMatches(userId, currentResume.uploader_id._id, currentResume._id); | ||
} catch (error) { | ||
console.error('Failed to swipe resume', error); | ||
} | ||
}; | ||
|
||
const checkMatches = async (currentUserId, swipedResumeUploaderId, swipedResumeId) => { | ||
|
@@ -142,7 +154,9 @@ const LandingPage = () => { | |
</button> | ||
</div> | ||
</div> | ||
<div className="swiping-pdf-item" onClick={() => openZoomModal(currentResume)}> | ||
<div className={`swiping-pdf-item ${isSwiping ? `swipe-${swipeDirection}` : ''}`} | ||
onClick={() => openZoomModal(currentResume)} | ||
> | ||
<Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js"> | ||
<Viewer | ||
fileUrl={`http://localhost:3001/bucket/files/${currentResume.file_path}`} | ||
|