Skip to content

Commit

Permalink
Merge pull request #962 from Code4GovTech/bugfix/repeated_api_call
Browse files Browse the repository at this point in the history
API call Fixes
  • Loading branch information
riya-2206 authored Jun 20, 2024
2 parents 0b66c48 + a762bb7 commit 41b8f3c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 147 deletions.
4 changes: 2 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ module.exports = {
items: [
{
label: "VedantKhairnar",
to: "/docs/2024/org?id=VedantKhairnar",
to: "/docs/2024?id=VedantKhairnar",
},
{
label: "AbhimanyuSamagra",
to: "/docs/2024/org?id=AbhimanyuSamagra",
to: "/docs/2024?id=AbhimanyuSamagra",
},
]
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/IssueDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function IssueDescription({ currentOrg, currentIssue }) {
<li className="breadcrumbs__item">
<a
className="breadcrumbs__link breadcrumbs-items"
href={`/docs/2024/org?id=${currentOrg}`}
href={`/docs/2024?id=${currentOrg}`}
>
{currentOrg}
</a>
Expand Down Expand Up @@ -330,7 +330,7 @@ function IssueDescription({ currentOrg, currentIssue }) {
{d.content && isLearningsDropdown == i && (
<tr style={{ backgroundColor: "none" }}>
<td align="left">
<Markdown>{d.content}</Markdown>
{d.content.match(/<ul>[\s\S]*?<\/ul>/) ? <Markdown>{d.content.match(/<ul>[\s\S]*?<\/ul>/)[0]}</Markdown> : <Markdown>{d.content}</Markdown>}
</td>
</tr>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/OrgDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function OrgDescription({ currentOrg, currentOrgData }) {
<a
className="cursor-pointer"
onClick={() => {
const newUrl = `/docs/2024/org?id=${currentOrg}&issue=${d.id}`;
const newUrl = `/docs/2024?id=${currentOrg}&issue=${d.id}`;
history.push(newUrl);
}}
>
Expand Down
9 changes: 6 additions & 3 deletions src/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function Sidebar({
setCurrentOrg,
currentIssue,
setCurrentIssue,
setCurrentTab
}) {
const history = useHistory();
return (
Expand All @@ -18,7 +19,9 @@ function Sidebar({
<div
className={`menu__link cursor-pointer ${currentTab == "c4gt" ? "menu__link--active" : ""}`}
onClick={() => {
window.location.href = `/docs/2024/`;
const newUrl = `/docs/2024/`;
history.push(newUrl);
setCurrentTab("c4gt")
}}
>
C4GT'24
Expand All @@ -36,7 +39,7 @@ function Sidebar({
<div
className={`menu__list-item-collapsible cursor-pointer ${currentOrg == data?.org_name && currentIssue == null ? "menu__list-item-collapsible--active" : ""}`}
onClick={() => {
const newUrl = `/docs/2024/org?id=${data?.org_name}`;
const newUrl = `/docs/2024?id=${data?.org_name}`;
history.push(newUrl);
setCurrentOrg(() => data?.org_name);
setCurrentIssue(() => null);
Expand Down Expand Up @@ -74,7 +77,7 @@ function Sidebar({
<div
className={`menu__link cursor-pointer ${currentIssue == d.id ? "menu__link--active" : ""}`}
onClick={() => {
const newUrl = `/docs/2024/org?id=${currentOrg}&issue=${d.id}`;
const newUrl = `/docs/2024?id=${currentOrg}&issue=${d.id}`;
history.push(newUrl);
setCurrentIssue(() => d.id);
}}
Expand Down
88 changes: 84 additions & 4 deletions src/pages/docs/2024/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
import React, { useEffect, useState } from "react";
import Layout from "@theme/Layout";
import "./index.css";
import { useHistory, useLocation } from "react-router-dom";
import useParseMarkdown from "../../../hooks/useParseMarkdown";
import ErrorComponent from "../../../components/ErrorComponent";
import Sidebar from "../../../components/Sidebar";
import C4GT2024Description from "../../../components/C4gt2024Description";
import OrgDescription from "../../../components/OrgDescription";
import IssueDescription from "../../../components/IssueDescription";

function C4GT2024() {
const location = useLocation();
const history = useHistory();
const { API_AUTH_KEY, API_BASE_URL } = useParseMarkdown();
const [issueData, setIssueData] = useState(null);
const [error, setError] = useState(null);
const [currentOrg, setCurrentOrg] = useState(null);
const [currentIssue, setCurrentIssue] = useState(null);
const [issueData, setIssueData] = useState(null);
const [currentOrgData, setCurrentOrgData] = useState(null);
const [currentTab,setCurrentTab] = useState(null)
const [error, setError] = useState(null);

useEffect(() => {
setError(() => null);
const queryString = location.search;
const urlParams = new URLSearchParams(queryString);
const ifOrg = urlParams.get("id") ? urlParams.get("id") : null;
const ifIssue = urlParams.get("issue") ? urlParams.get("issue") : null;
const newUrl = ifIssue
? `/docs/2024?id=${ifOrg}&issue=${ifIssue}`
: ifOrg
? `/docs/2024?id=${ifOrg}`
: "/docs/2024/";
history.push(newUrl);
if (ifIssue) setCurrentIssue(() => ifIssue);
else setCurrentIssue(null);
if (ifOrg) {setCurrentOrg(() => ifOrg);
setCurrentTab("org")
}
else {setCurrentOrg(null);
setCurrentTab("c4gt")
}
fetch(`${API_BASE_URL}/issues`, {
method: "GET",
headers: {
Expand All @@ -29,13 +54,49 @@ function C4GT2024() {
throw new Error(`${data?.message}`);
} else if (data?.error) {
throw new Error(`${data?.error}`);
} else setIssueData(() => data?.issues);
} else {
let issues = data?.issues;
setIssueData(() => issues);
if (ifOrg) {
setCurrentOrgData(() => {
let issue_data = issues?.filter((d, i) => {
if (d.org_name == ifOrg) return d.issues;
else return;
});
return issue_data;
});
} else setCurrentOrgData(null);
}
})
.catch((error) => {
setError(() => error);
});
}, []);

useEffect(() => {
const queryString = location.search;
const urlParams = new URLSearchParams(queryString);
const ifOrg = urlParams.get("id") ? urlParams.get("id") : null;
const ifIssue = urlParams.get("issue") ? urlParams.get("issue") : null;
if (ifIssue) setCurrentIssue(() => ifIssue);
else setCurrentIssue(null);
if (ifOrg) {
setCurrentOrg(() => ifOrg);
setCurrentOrgData(() => {
let data = issueData?.filter((d, i) => {
if (d.org_name == ifOrg) return d.issues;
else return;
});
return data;
});
setCurrentTab("org")
} else {
setCurrentOrg(null);
setCurrentOrgData(null);
setCurrentTab("c4gt")
}
}, [location]);

return (
<>
{error ? (
Expand All @@ -47,15 +108,34 @@ function C4GT2024() {
<aside className="theme-doc-sidebar-container sidebar-container-2024">
<Sidebar
issueData={issueData}
currentTab={"c4gt"}
currentTab={currentTab}
currentOrg={currentOrg}
currentIssue={currentIssue}
setCurrentIssue={setCurrentIssue}
setCurrentOrg={setCurrentOrg}
setCurrentTab={setCurrentTab}
/>
</aside>
<main className="main-container">
{currentTab==="c4gt" ? (
<C4GT2024Description />
) : currentIssue != null ? (
<IssueDescription
currentOrg={currentOrg}
currentIssue={currentIssue}
/>
) : currentOrg != null ? (
<OrgDescription
currentIssue={currentIssue}
setCurrentIssue={setCurrentIssue}
currentOrg={currentOrg}
issueData={issueData}
currentOrgData={currentOrgData}
/>
) : (
<></>
)}

</main>
</div>
</div>
Expand Down
135 changes: 0 additions & 135 deletions src/pages/docs/2024/org/index.js

This file was deleted.

0 comments on commit 41b8f3c

Please sign in to comment.