Skip to content

Commit 3a194fc

Browse files
authored
Merge pull request #1282 from Ayushmaanagarwal1211/Bugs
Created the functionality for Most Helpful Component
2 parents 4c786ef + 54cd2a5 commit 3a194fc

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

website3.0/components/profile/GrowYourReachTab.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ function GrowYourReachTab() {
6666
</div>
6767
<a
6868
href={`/profile?id=${user.username}&&isView=true`}
69-
target="_blank"
7069
rel="noopener noreferrer"
7170
className={`${theme?"bg-[#6089a4]":"bg-[#979797]"} text-lg max-md:text-sm text-white px-4 py-2 rounded-md`}
7271
>

website3.0/pages/ForumPage.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ const RecentTopics = ({ topic, img, user, theme }) => (
6161
</div>
6262
);
6363

64-
const HelpfulUser = ({ user }) => (
65-
<div>
64+
const HelpfulUser = ({ user }) => {
65+
return <div>
6666
<div className="flex items-center justify-between gap-2 mt-6">
6767
<div className="flex gap-2 items-center">
68-
<img src={user.img} alt="User" className="rounded-full w-8 h-8" />
68+
<img src={user.image1} alt="User" className="rounded-full w-8 h-8" />
6969
<div>{user.name}</div>
7070
</div>
7171
<div className="text-sm text-gray-500 flex gap-2 items-center">
7272
<FontAwesomeIcon icon={faCheckCircle} />
73-
{user.issuesSolved}
73+
{user.answers}
7474
</div>
7575
</div>
7676
<hr className="border-gray-200 border-[1px] mt-2" />
7777
</div>
78-
);
78+
};
7979
const TopIssue = ({ title, index }) => (
8080
<div className="flex items-center 2xl:justify-between max-md:gap-2 ">
8181
<span className=" text-base mr-4 max-sm:mr-0 border-gray-300 border-[1px] px-2 py-1 rounded-full ">
@@ -96,13 +96,15 @@ function ForumPage({ theme,finalUser,setIsPopup,setMsg }) {
9696
let [top,setTop]=useState([])
9797
const [isClosed,setIsClosed]=useState(false)
9898
let [sortedArray,setSortedArray]=useState([])
99+
let [mostHelpful,setMostHelpful]=useState([])
99100
const handleMouseEnter =async (event, userImg) => {
100101
setCursorPosition({ x: event.clientX, y: event.clientY });
101102
let obj={...userImg}
102103
console.log(userImg)
103-
let u=await fetch("/api/getuser",{method:"POST",body:JSON.stringify({id:userImg.authorId})})
104+
let u=await fetch("/api/getuserbyid",{method:"POST",body:JSON.stringify({id:userImg.authorId})})
104105
u=await u.json()
105106
u=u.msg
107+
console.log(u,"user")
106108
obj={...obj,count:Object.keys(u.followers).length,questions:u.questions,answers:u.answers}
107109
setHoveredUser(obj);
108110
};
@@ -137,9 +139,6 @@ function ForumPage({ theme,finalUser,setIsPopup,setMsg }) {
137139
useEffect(()=>{
138140
fetchData()
139141
},[])
140-
useEffect(()=>{
141-
console.log(users,'users')
142-
},[users])
143142
async function fetchData() {
144143
try {
145144
// Fetch initial data
@@ -156,7 +155,6 @@ function ForumPage({ theme,finalUser,setIsPopup,setMsg }) {
156155
// Collect all user IDs to fetch in parallel
157156
let userPromises = data.flatMap(item =>
158157
item.relatedUser.map(async (userRef) => {
159-
console.log(userRef)
160158
setUsers(prev=>[...prev,userRef.authorId])
161159

162160
})
@@ -172,7 +170,12 @@ function ForumPage({ theme,finalUser,setIsPopup,setMsg }) {
172170
data.reverse();
173171
setIssues([...data]);
174172
setOriginalIssues([...data]);
175-
173+
let a=data.sort((c,b)=>b.solutions.length-c.solutions.length)
174+
let ar=[]
175+
for(let i=0;i<a.length;i++){
176+
ar.push({image1:a[i].authorImage,name:a[i].authorName,answers:a[i].solutions.length})
177+
}
178+
setMostHelpful([...ar])
176179
} catch (error) {
177180
console.error("Error fetching data:", error);
178181
}
@@ -709,7 +712,7 @@ className="flex items-center gap-4">
709712
theme ? "" : "text-[#c4bbbb]"
710713
}`}
711714
>
712-
{helpfulUsers.map((user, index) => (
715+
{mostHelpful.slice(0,mostHelpful.length>=4?4:mostHelpful.length).map((user, index) => (
713716
<HelpfulUser key={index} user={user} />
714717
))}
715718
</div>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import user from "@utils/models/user"; // Importing Mongoose model for newsletter subscription
2+
import mongoose from "mongoose"; // Importing Mongoose for MongoDB interactions
3+
import nodemailer from "nodemailer"; // Importing nodemailer to send welcome email
4+
import { NextResponse } from "next/server"; // Importing Next.js server response utility
5+
const bcrypt = require("bcrypt");
6+
const saltRounds = 10;
7+
8+
export async function POST(req) {
9+
const { MONGO_URI } = process.env;
10+
let { id } = await req.json();
11+
// Connect to MongoDB using Mongoose
12+
await mongoose.connect(MONGO_URI);
13+
try {
14+
let data = await user.findById( id );
15+
16+
// checking if user exist or not
17+
if (data) {
18+
19+
return NextResponse.json({ success: true, msg: data }, { status: "200" });
20+
} else {
21+
22+
return NextResponse.json({ success: true, msg: data }, { status: "200" });
23+
24+
}
25+
26+
} catch {
27+
return NextResponse.json({ success: false }, { status: "200" });
28+
}
29+
}

0 commit comments

Comments
 (0)