From ea01595aa94d9daf390378da8a62349a9089bbd6 Mon Sep 17 00:00:00 2001 From: Nandan Date: Sat, 21 Sep 2024 10:57:29 +0530 Subject: [PATCH] paginated studybuddy --- src/components/StudyBuddy.vue | 42 ++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/components/StudyBuddy.vue b/src/components/StudyBuddy.vue index 451a62d..2699c97 100644 --- a/src/components/StudyBuddy.vue +++ b/src/components/StudyBuddy.vue @@ -27,7 +27,7 @@
-
+
+

No nearby users found.

@@ -131,7 +132,7 @@ export default { token2: localStorage.getItem("Token2"), latitude: null, longitude: null, - users: [], + users: [], pusers: [], curIndex: 0, hasNext: true, loading: false, showPopup: true, showDeletePopupVisible: false, @@ -192,7 +193,32 @@ export default { longitude: this.longitude, }); - this.users = response.data.users; + // // check response file + // console.log(response.data); + // // Step 1: Convert the response data (object) to a JSON string + // const jsonStr = JSON.stringify(response.data, null, 2); // Pretty JSON with indentation + + // // Step 2: Create a Blob with the JSON string + // const blob = new Blob([jsonStr], { type: 'text/plain' }); + + // // Step 3: Create a temporary link element + // const link = document.createElement('a'); + // link.href = window.URL.createObjectURL(blob); + + // // Step 4: Set the download attribute with the desired file name + // link.download = 'response-data.txt'; + + // // Step 5: Append the link to the body (required to trigger download) + // document.body.appendChild(link); + + // // Step 6: Programmatically click the link to trigger the download + // link.click(); + + // // Step 7: Remove the link from the document + // document.body.removeChild(link); + // // check response file + + this.users = response.data.users; this.paginate(); this.social_media_profile_status = response.data.social_media_link_status; // console.log(this.users); // console.log("Users fetched successfully"); @@ -212,6 +238,16 @@ export default { alert("Location access is not given."); } }, + paginate() { + if (this.curIndex < this.users.length) { + let nextUsers = this.users.slice(this.curIndex, this.curIndex + 10); + console.log(this.users) + this.pusers = this.pusers.concat(nextUsers); + this.curIndex += 10; + } else { + this.hasNext = false; + } + }, showDeletePopup() { this.showDeletePopupVisible = true; },