Skip to content

Commit 41b8f3c

Browse files
authored
Merge pull request #962 from Code4GovTech/bugfix/repeated_api_call
API call Fixes
2 parents 0b66c48 + a762bb7 commit 41b8f3c

File tree

6 files changed

+95
-147
lines changed

6 files changed

+95
-147
lines changed

docusaurus.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ module.exports = {
229229
items: [
230230
{
231231
label: "VedantKhairnar",
232-
to: "/docs/2024/org?id=VedantKhairnar",
232+
to: "/docs/2024?id=VedantKhairnar",
233233
},
234234
{
235235
label: "AbhimanyuSamagra",
236-
to: "/docs/2024/org?id=AbhimanyuSamagra",
236+
to: "/docs/2024?id=AbhimanyuSamagra",
237237
},
238238
]
239239
}

src/components/IssueDescription.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function IssueDescription({ currentOrg, currentIssue }) {
5858
<li className="breadcrumbs__item">
5959
<a
6060
className="breadcrumbs__link breadcrumbs-items"
61-
href={`/docs/2024/org?id=${currentOrg}`}
61+
href={`/docs/2024?id=${currentOrg}`}
6262
>
6363
{currentOrg}
6464
</a>
@@ -330,7 +330,7 @@ function IssueDescription({ currentOrg, currentIssue }) {
330330
{d.content && isLearningsDropdown == i && (
331331
<tr style={{ backgroundColor: "none" }}>
332332
<td align="left">
333-
<Markdown>{d.content}</Markdown>
333+
{d.content.match(/<ul>[\s\S]*?<\/ul>/) ? <Markdown>{d.content.match(/<ul>[\s\S]*?<\/ul>/)[0]}</Markdown> : <Markdown>{d.content}</Markdown>}
334334
</td>
335335
</tr>
336336
)}

src/components/OrgDescription.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function OrgDescription({ currentOrg, currentOrgData }) {
103103
<a
104104
className="cursor-pointer"
105105
onClick={() => {
106-
const newUrl = `/docs/2024/org?id=${currentOrg}&issue=${d.id}`;
106+
const newUrl = `/docs/2024?id=${currentOrg}&issue=${d.id}`;
107107
history.push(newUrl);
108108
}}
109109
>

src/components/Sidebar.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Sidebar({
88
setCurrentOrg,
99
currentIssue,
1010
setCurrentIssue,
11+
setCurrentTab
1112
}) {
1213
const history = useHistory();
1314
return (
@@ -18,7 +19,9 @@ function Sidebar({
1819
<div
1920
className={`menu__link cursor-pointer ${currentTab == "c4gt" ? "menu__link--active" : ""}`}
2021
onClick={() => {
21-
window.location.href = `/docs/2024/`;
22+
const newUrl = `/docs/2024/`;
23+
history.push(newUrl);
24+
setCurrentTab("c4gt")
2225
}}
2326
>
2427
C4GT'24
@@ -36,7 +39,7 @@ function Sidebar({
3639
<div
3740
className={`menu__list-item-collapsible cursor-pointer ${currentOrg == data?.org_name && currentIssue == null ? "menu__list-item-collapsible--active" : ""}`}
3841
onClick={() => {
39-
const newUrl = `/docs/2024/org?id=${data?.org_name}`;
42+
const newUrl = `/docs/2024?id=${data?.org_name}`;
4043
history.push(newUrl);
4144
setCurrentOrg(() => data?.org_name);
4245
setCurrentIssue(() => null);
@@ -74,7 +77,7 @@ function Sidebar({
7477
<div
7578
className={`menu__link cursor-pointer ${currentIssue == d.id ? "menu__link--active" : ""}`}
7679
onClick={() => {
77-
const newUrl = `/docs/2024/org?id=${currentOrg}&issue=${d.id}`;
80+
const newUrl = `/docs/2024?id=${currentOrg}&issue=${d.id}`;
7881
history.push(newUrl);
7982
setCurrentIssue(() => d.id);
8083
}}

src/pages/docs/2024/index.js

+84-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
import React, { useEffect, useState } from "react";
22
import Layout from "@theme/Layout";
33
import "./index.css";
4+
import { useHistory, useLocation } from "react-router-dom";
45
import useParseMarkdown from "../../../hooks/useParseMarkdown";
56
import ErrorComponent from "../../../components/ErrorComponent";
67
import Sidebar from "../../../components/Sidebar";
78
import C4GT2024Description from "../../../components/C4gt2024Description";
9+
import OrgDescription from "../../../components/OrgDescription";
10+
import IssueDescription from "../../../components/IssueDescription";
811

912
function C4GT2024() {
13+
const location = useLocation();
14+
const history = useHistory();
1015
const { API_AUTH_KEY, API_BASE_URL } = useParseMarkdown();
11-
const [issueData, setIssueData] = useState(null);
12-
const [error, setError] = useState(null);
1316
const [currentOrg, setCurrentOrg] = useState(null);
1417
const [currentIssue, setCurrentIssue] = useState(null);
18+
const [issueData, setIssueData] = useState(null);
19+
const [currentOrgData, setCurrentOrgData] = useState(null);
20+
const [currentTab,setCurrentTab] = useState(null)
21+
const [error, setError] = useState(null);
1522

1623
useEffect(() => {
1724
setError(() => null);
25+
const queryString = location.search;
26+
const urlParams = new URLSearchParams(queryString);
27+
const ifOrg = urlParams.get("id") ? urlParams.get("id") : null;
28+
const ifIssue = urlParams.get("issue") ? urlParams.get("issue") : null;
29+
const newUrl = ifIssue
30+
? `/docs/2024?id=${ifOrg}&issue=${ifIssue}`
31+
: ifOrg
32+
? `/docs/2024?id=${ifOrg}`
33+
: "/docs/2024/";
34+
history.push(newUrl);
35+
if (ifIssue) setCurrentIssue(() => ifIssue);
36+
else setCurrentIssue(null);
37+
if (ifOrg) {setCurrentOrg(() => ifOrg);
38+
setCurrentTab("org")
39+
}
40+
else {setCurrentOrg(null);
41+
setCurrentTab("c4gt")
42+
}
1843
fetch(`${API_BASE_URL}/issues`, {
1944
method: "GET",
2045
headers: {
@@ -29,13 +54,49 @@ function C4GT2024() {
2954
throw new Error(`${data?.message}`);
3055
} else if (data?.error) {
3156
throw new Error(`${data?.error}`);
32-
} else setIssueData(() => data?.issues);
57+
} else {
58+
let issues = data?.issues;
59+
setIssueData(() => issues);
60+
if (ifOrg) {
61+
setCurrentOrgData(() => {
62+
let issue_data = issues?.filter((d, i) => {
63+
if (d.org_name == ifOrg) return d.issues;
64+
else return;
65+
});
66+
return issue_data;
67+
});
68+
} else setCurrentOrgData(null);
69+
}
3370
})
3471
.catch((error) => {
3572
setError(() => error);
3673
});
3774
}, []);
3875

76+
useEffect(() => {
77+
const queryString = location.search;
78+
const urlParams = new URLSearchParams(queryString);
79+
const ifOrg = urlParams.get("id") ? urlParams.get("id") : null;
80+
const ifIssue = urlParams.get("issue") ? urlParams.get("issue") : null;
81+
if (ifIssue) setCurrentIssue(() => ifIssue);
82+
else setCurrentIssue(null);
83+
if (ifOrg) {
84+
setCurrentOrg(() => ifOrg);
85+
setCurrentOrgData(() => {
86+
let data = issueData?.filter((d, i) => {
87+
if (d.org_name == ifOrg) return d.issues;
88+
else return;
89+
});
90+
return data;
91+
});
92+
setCurrentTab("org")
93+
} else {
94+
setCurrentOrg(null);
95+
setCurrentOrgData(null);
96+
setCurrentTab("c4gt")
97+
}
98+
}, [location]);
99+
39100
return (
40101
<>
41102
{error ? (
@@ -47,15 +108,34 @@ function C4GT2024() {
47108
<aside className="theme-doc-sidebar-container sidebar-container-2024">
48109
<Sidebar
49110
issueData={issueData}
50-
currentTab={"c4gt"}
111+
currentTab={currentTab}
51112
currentOrg={currentOrg}
52113
currentIssue={currentIssue}
53114
setCurrentIssue={setCurrentIssue}
54115
setCurrentOrg={setCurrentOrg}
116+
setCurrentTab={setCurrentTab}
55117
/>
56118
</aside>
57119
<main className="main-container">
120+
{currentTab==="c4gt" ? (
58121
<C4GT2024Description />
122+
) : currentIssue != null ? (
123+
<IssueDescription
124+
currentOrg={currentOrg}
125+
currentIssue={currentIssue}
126+
/>
127+
) : currentOrg != null ? (
128+
<OrgDescription
129+
currentIssue={currentIssue}
130+
setCurrentIssue={setCurrentIssue}
131+
currentOrg={currentOrg}
132+
issueData={issueData}
133+
currentOrgData={currentOrgData}
134+
/>
135+
) : (
136+
<></>
137+
)}
138+
59139
</main>
60140
</div>
61141
</div>

src/pages/docs/2024/org/index.js

-135
This file was deleted.

0 commit comments

Comments
 (0)