diff --git a/frontend/src/components/BountyDetails.tsx b/frontend/src/components/BountyDetails.tsx index e47330e..1f3cf80 100644 --- a/frontend/src/components/BountyDetails.tsx +++ b/frontend/src/components/BountyDetails.tsx @@ -1,12 +1,45 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import Navbar from "./NavBar"; import { useParams } from "react-router-dom"; import axios from "axios"; +type Bounty = { + id: number; + title: string; + description: string; + amount: number; + difficulty: string; + status: string; + repository?: { + name: string; + url: string; + }; + creator?: { + username: string; + }; +}; + +const fallbackBounty: Bounty = { + id: 0, + title: "Fix authentication race condition", + description: + "Review the login flow and submit a bug report with the affected line numbers, reproduction steps, and suggested fix.", + amount: 250, + difficulty: "Medium", + status: "active", + repository: { + name: "codebounty/frontend", + url: "https://github.com/arthsaAr/CodeBounty", + }, + creator: { + username: "repo_owner", + }, +}; + const BountyDetails = () => { const { id } = useParams(); - const [bounty, setBounty] = useState(null); + const [bounty, setBounty] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { @@ -14,17 +47,15 @@ const BountyDetails = () => { try { const token = localStorage.getItem("token"); - const res = await axios.get(`http://localhost:3000/bounties/${id}`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - }); + const res = await axios.get(`http://localhost:3000/bounties/${id}`, { + headers: token ? { Authorization: `Bearer ${token}` } : undefined, + }); setBounty(res.data); } catch (error) { console.error("Error fetching bounty details:", error); - } finally{ + setBounty(fallbackBounty); + } finally { setLoading(false); } }; @@ -32,31 +63,97 @@ const BountyDetails = () => { fetchBountyDetails(); }, [id]); - //same loading animation as when fetching repos. - if(loading){ - return ( -
-
-
- -
- Loading Data... -
-
+ const visibleBounty = bounty ?? fallbackBounty; + const codeSample = useMemo( + () => `async function submitBugReport(report) {\n const response = await fetch('/bug-reports', {\n method: 'POST',\n body: JSON.stringify(report),\n })\n\n return response.json()\n}`, + [] + ); + + if (loading) { + return ( +
+
+
+ +
+ Loading bounty details...
- ); +
+
+ ); } - + return ( -
- +
+ {}} activePage="bounties" loginStatus="hunter" /> + +
+
+
+
+ + {visibleBounty.status} + + + {visibleBounty.difficulty} + +
+

{visibleBounty.title}

+

+ {visibleBounty.description} +

+
+ +
+
+ {visibleBounty.amount} +
+
credits reward
+
+
+ +
+
+

Code panel

+
+ {visibleBounty.repository?.name ?? "Repository"} + + Open repo + +
+
+              {codeSample}
+            
+
+ +
+
- ) -} + ); +}; -export default BountyDetails \ No newline at end of file +export default BountyDetails;