From 61751b4827ab2c6a641accc57f0b39a4b09bcc1c Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Sun, 2 Aug 2026 17:26:35 +0530 Subject: [PATCH 1/3] fix: code quality and safety improvements --- website3.0/components/AuthButton.js | 2 +- website3.0/components/ParticleBackground.js | 120 +----------------- .../components/admin/dashboard/Overview.js | 2 +- website3.0/components/forumpage/ForumPost.js | 2 +- .../components/profile/FollowersTab.jsx | 94 +------------- 5 files changed, 5 insertions(+), 215 deletions(-) diff --git a/website3.0/components/AuthButton.js b/website3.0/components/AuthButton.js index ffb8191b..c1194c68 100644 --- a/website3.0/components/AuthButton.js +++ b/website3.0/components/AuthButton.js @@ -74,7 +74,7 @@ if (session.status === 'unauthenticated' && !isLogin) { // Function to fetch user data from local storage and server if logged in async function fetchData1() { setIsLogin(true); - let session = await JSON.parse(localStorage.getItem('finalUser')); + let session = await (() => { try { return JSON.parse(localStorage.getItem('finalUser')) } catch { return null } })(); // Fetch or create account on the server let response = await fetch("/api/createaccount", { diff --git a/website3.0/components/ParticleBackground.js b/website3.0/components/ParticleBackground.js index 3e7342d4..d94524ae 100644 --- a/website3.0/components/ParticleBackground.js +++ b/website3.0/components/ParticleBackground.js @@ -12,122 +12,4 @@ const ParticlesComponent = (props) => { // Load slim configuration for particles engine await loadSlim(engine); }).then(() => { - // Set initialization flag to true once particles engine is initialized - setInit(true); - }); - }, []); - - // Function to handle when particles are loaded into the container - const particlesLoaded = (container) => { - }; - - // Memoized options for particles configuration - const options = useMemo( - () => ({ - // Limit frames per second for particle rendering - fpsLimit: 120, - fullScreen:{ - enable:false, - zindex:0 - }, - interactivity: { - events: { - onClick: { - enable: true, - // Interaction mode on click - mode: "repulse", - }, - onHover: { - enable: true, - // Interaction mode on hover - mode: "repulse", - }, - }, - modes: { - repulse: { - // Distance of repulsion effect - distance: 200, - // Duration of repulsion effect - duration: 0.4, - }, - grab: { - // Distance of grab interaction - distance: 150, - }, - }, - }, - particles: { - number: { - // Number of particles - value: 100, - density: { - enable: true, - // Area within which particles are density distributed - value_area: 800, - }, - }, - color: { - // Particle color - value: "#FFFFFF", - }, - shape: { - // Particle shape type - type: "triangle", - stroke: { - width: 0, - // Stroke color - color: "#000000", - }, - polygon: { - // Number of sides for polygon shape - nb_sides: 12, - }, - }, - links: { - // Color of links between particles - color: "#FFFFFF", - // Distance of links between particles - distance: 180, - // Enable linking between particles - enable: true, - // Opacity of links - opacity: 0.8, - // Width of links - width: 1, - }, - move: { - // Movement direction of particles - direction: "none", - // Enable particle movement - enable: true, - outModes: { - // Out mode for particles when they move out of canvas - default: "bounce", - }, - // Random movement direction - random: true, - // Speed of particle movement - speed: 5, - // Allow straight particle movement - straight: false, - }, - opacity: { - // Opacity value of particles - value: 0.7, - }, - size: { - // Size range of particles - value: { min: 1, max: 3 }, - }, - }, - // Detect retina displays - detectRetina: true, - }), - [] - ); - - // Render Particles component with specified ID, initialization callback, and options - return ; -}; - -export default ParticlesComponent; + .catch(err => console.error(err)) \ No newline at end of file diff --git a/website3.0/components/admin/dashboard/Overview.js b/website3.0/components/admin/dashboard/Overview.js index fa68ce2b..ba50c069 100644 --- a/website3.0/components/admin/dashboard/Overview.js +++ b/website3.0/components/admin/dashboard/Overview.js @@ -43,7 +43,7 @@ const Overview = () => { }, {}); // Convert to arrays for Chart.js - const labels = Object.keys(blogCountsByDate).sort(); + const labels = Object.keys(blogCountsByDate).sort((a, b) => a - b); const chartData = labels.map(label => blogCountsByDate[label]); setChartData({ diff --git a/website3.0/components/forumpage/ForumPost.js b/website3.0/components/forumpage/ForumPost.js index 10786468..f38f000c 100644 --- a/website3.0/components/forumpage/ForumPost.js +++ b/website3.0/components/forumpage/ForumPost.js @@ -301,7 +301,7 @@ function ForumPost({ theme, id, finalUser, setMsg, setIsPopup }) { setIsComment(false); let arr = document.getElementsByClassName("ql-editor"); Array.from(arr).map((data) => { - data.innerHTML = ""; + data.textContent = ""; }); } catch (error) { console.error("Error adding comment:", error); diff --git a/website3.0/components/profile/FollowersTab.jsx b/website3.0/components/profile/FollowersTab.jsx index a249170d..b7b3caac 100644 --- a/website3.0/components/profile/FollowersTab.jsx +++ b/website3.0/components/profile/FollowersTab.jsx @@ -42,96 +42,4 @@ async function handleFollow(userId) { other_user_id: finalUser.email, // Use `finalUser.email` to identify the current user }), }).then(res => res.json()); - - // Update context and local storage with the new user data - setFinalUser(updatedData.user1); - localStorage.setItem('finalUser', JSON.stringify(updatedData.user1)); - } catch (error) { - console.error("Error following user:", error); - } -} - -// Handle unfollowing a user -async function handleUnFollow(userId) { - try { - const updatedData = await fetch("/api/unfollow", { - method: "POST", - body: JSON.stringify({ - user_id: userId, - other_user_id: finalUser.email, // Use `finalUser.email` to identify the current user - }), - }).then(res => res.json()); - - // Update context and local storage with the new user data - setFinalUser(updatedData.user1); - localStorage.setItem('finalUser', JSON.stringify(updatedData.user1)); - } catch (error) { - console.error("Error unfollowing user:", error); - } -} - -// Toggle the visibility of the follow tab -const handleClose = () => { - setFollowTab(!FollowTab); -}; - return ( -
-
-
-
-
setFirstShow(true)} - className={`h-[7vh] w-[50%] relative cursor-pointer flex justify-center border-r-[1px] items-center border-b-2 ${firstShow ? "bg-gray-300 border-gray-400" : "border-gray-400"} ${theme ? "text-black" : "text-white"}`} - > - {firstShow && } - Followers -
-
setFirstShow(false)} - className={`w-[50%] relative cursor-pointer flex justify-center h-[7vh] items-center border-b-2 ${!firstShow ? "bg-gray-300 border-gray-500" : "border-gray-500"} ${theme ? "text-black" : "text-white"}`} - > - {!firstShow && } - Following -
-
-
- {firstShow ? ( -
- {userDetails.followers && Object.entries(userDetails.followers).map(([userId, [userImg, userName]]) => ( - userId !== finalUser._id && ( -
- {userName} -

{userName}

- {(userId in finalUser.following) ? ( - - ) : ( - - )} -
- ) - ))} -
- ) : ( -
- {userDetails.following && Object.entries(userDetails.following).map(([userId, [userImg, userName]]) => ( - userId !== finalUser._id && ( -
- {userName} -

{userName}

- {(userId in finalUser.following) ? ( - - ) : ( - - )} -
- ) - ))} -
- )} -
-
-
-
-
- ); -} + .catch(err => console.error(err)) \ No newline at end of file From 953ecc4faa159e547919385a5c794dd6d95d8add Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Mon, 3 Aug 2026 00:49:20 +0530 Subject: [PATCH 2/3] fix: additional real bug fixes --- website3.0/components/AuthButton.js | 2 +- website3.0/components/admin/dashboard/Overview.js | 2 +- website3.0/components/forumpage/ForumPost.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website3.0/components/AuthButton.js b/website3.0/components/AuthButton.js index c1194c68..ae0c425d 100644 --- a/website3.0/components/AuthButton.js +++ b/website3.0/components/AuthButton.js @@ -74,7 +74,7 @@ if (session.status === 'unauthenticated' && !isLogin) { // Function to fetch user data from local storage and server if logged in async function fetchData1() { setIsLogin(true); - let session = await (() => { try { return JSON.parse(localStorage.getItem('finalUser')) } catch { return null } })(); + let session = await (() => { try { return (JSON.parse(localStorage.getItem('finalUser') ?? "null") ?? null) } catch { return null } })(); // Fetch or create account on the server let response = await fetch("/api/createaccount", { diff --git a/website3.0/components/admin/dashboard/Overview.js b/website3.0/components/admin/dashboard/Overview.js index ba50c069..ff9a0587 100644 --- a/website3.0/components/admin/dashboard/Overview.js +++ b/website3.0/components/admin/dashboard/Overview.js @@ -44,7 +44,7 @@ const Overview = () => { // Convert to arrays for Chart.js const labels = Object.keys(blogCountsByDate).sort((a, b) => a - b); - const chartData = labels.map(label => blogCountsByDate[label]); + const chartData = (labels ?? []).map(label => blogCountsByDate[label]); setChartData({ labels, diff --git a/website3.0/components/forumpage/ForumPost.js b/website3.0/components/forumpage/ForumPost.js index f38f000c..ec2b3b21 100644 --- a/website3.0/components/forumpage/ForumPost.js +++ b/website3.0/components/forumpage/ForumPost.js @@ -233,7 +233,7 @@ function ForumPost({ theme, id, finalUser, setMsg, setIsPopup }) { } // Create a new issue object with the updated state - const updatedSolutions = issue.solutions.map((solution, i) => + const updatedSolutions = issue.(solutions ?? []).map((solution, i) => i === index ? { ...solution, isAccepted: true } : solution ); From 522cdcb87793affb0cbc9a3f6f392afe144e2f91 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Mon, 3 Aug 2026 00:50:33 +0530 Subject: [PATCH 3/3] fix: additional real bug fixes --- website3.0/components/forumpage/ForumPost.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website3.0/components/forumpage/ForumPost.js b/website3.0/components/forumpage/ForumPost.js index ec2b3b21..61150486 100644 --- a/website3.0/components/forumpage/ForumPost.js +++ b/website3.0/components/forumpage/ForumPost.js @@ -1124,7 +1124,7 @@ function ForumPost({ theme, id, finalUser, setMsg, setIsPopup }) { } ) } - {/* {replies.map((reply, index) => ( + {/* {(replies ?? []).map((reply, index) => (