Skip to content

Commit

Permalink
calculator ui in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
pashtepooja18 committed Jul 8, 2024
2 parents 474c940 + 7e37ef0 commit 9d3669f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
26 changes: 21 additions & 5 deletions blocks/accordion/accordion.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { fetchAPI } from "../../scripts/scripts.js";

/* this function also gets called by accordion-group */
export function generateAccordionDOM(block) {
const details = document.createElement("details");
const summary = document.createElement("summary");
details.append(summary);
Array.from(block.children).forEach((element, i) => {
Array.from(block.children).forEach(async (element, i) => {
if (i === 0) {
const heading = element.querySelector("h2,h3,h4,h5,h6");
// const heading = element.querySelector("h2,h3,h4,h5,h6");
const heading = element;
summary.append(heading || element.textContent.trim());
} else {
const elementText = element.innerHTML;
var elementDiv = document.createElement("div");
elementDiv.innerHTML = elementText;
const url = element.innerText.trim();
const isurl = url.includes(".json");
if (isurl) {
const data = await renderDataFromAPI(url);
details += data;
return
}
const elementText = element.innerHTML;
var elementDiv = document.createElement("div");
elementDiv.innerHTML = elementText;
details.append(elementDiv);
}
});
Expand All @@ -23,4 +33,10 @@ export default function decorate(block) {
block.append(dom);
}

async function renderDataFromAPI(url) {
const resp = await fetchAPI("GET", url);
const data = await resp.json();
return data;
}


5 changes: 3 additions & 2 deletions paths.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"mappings": [
"/content/piramalfinance-eds/:/",
"/content/piramalfinance-eds/:/",
"/content/piramalfinance-eds/redirects:/redirects.json",
"/content/piramalfinance-eds/cust-testimonial:/cust-testimonial.json",
"/content/piramalfinance-eds/home-emi-calc:/home-emi-calc.json",
Expand All @@ -9,8 +9,9 @@
"/content/piramalfinance-eds/home-loan-cities:/home-loan-cities.json",
"/content/piramalfinance-eds/personal-loan-city:/personal-loan-city.json",
"/content/piramalfinance-eds/bussiness-loan-city:/bussiness-loan-city.json",
"/content/piramalfinance-eds/document-required:/document-required.json",
"/content/piramalfinance-eds/placeholder:/placeholder.json",
"/content/piramalfinance-eds/ph:/ph.json",
"/content/piramalfinance-eds/test:/test.json"
]
}
}
1 change: 1 addition & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function fetchAPI(method, url, data) {
resolve({ responseJson: json });
}
} catch (error) {
console.warn(error);
reject(error);
}
});
Expand Down

0 comments on commit 9d3669f

Please sign in to comment.