Skip to content

Commit

Permalink
url changes and API
Browse files Browse the repository at this point in the history
  • Loading branch information
npy11 authored and npy11 committed Dec 10, 2024
1 parent bb470ed commit 4f6166a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 43 deletions.
21 changes: 13 additions & 8 deletions blocks/moredetailsaddress/moredetailsaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,21 @@ async function getStateCity(lat, lng) {
try {
const response = await getStateName(lat, lng);
const { results } = await response.json();
let placeIDs = [];
if (results[0]) {
for (const result of results) {
if (result.place_id) {
const reviewRating = await getReviewRating(result.place_id);
if (reviewRating.result.reviews && reviewRating.result?.opening_hours?.weekday_text) {
setLocationObj.review = reviewRating.result.reviews;
setLocationObj.working = reviewRating.result.opening_hours.weekday_text;
break;
}
}
if (result.place_id) placeIDs.push(result.place_id);
/* const reviewRating = await getReviewRating(result.place_id);
if (reviewRating.result.reviews && reviewRating.result?.opening_hours?.weekday_text) {
setLocationObj.review = reviewRating.result.reviews;
setLocationObj.working = reviewRating.result.opening_hours.weekday_text;
break;
} */
}
const reviewRating = await getReviewRating(placeIDs);
if(reviewRating.statusCode == 200){
setLocationObj.review = reviewRating.result.reviews;
setLocationObj.working = reviewRating.result.opening_hours.weekday_text;
}
}
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions blocks/whatsappservice/otppopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ export function getWhatAPIAuth() {
bot_id: '1',
},
};

return new Promise((resolve, reject) => {
fetchAPI('POST', getWhatAPIAuthURL, requestObj)
// fetchAPI('POST', getWhatAPIAuthURL, requestObj)
fetchAPI('GET', getWhatAPIAuthURL)
.then((response) => {
resolve(response.responseJson);
})
Expand Down
100 changes: 67 additions & 33 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,39 +524,8 @@ export function decorateViewMore(block) {
export function decorateAnchorTag(main) {
try {
main.querySelectorAll('a').forEach((anchor) => {
if (anchor.innerHTML.includes('<sub>')) {
anchor.target = '_blank';
} else if (anchor.href.includes('/modal-popup/')) {
const paths = anchor.href.split('/');
const dataid = paths[paths.length - 1];
anchor.dataset.modelId = dataid;
targetObject.modelId = dataid;
anchor.dataset.href = anchor.href;
anchor.href = 'javascript:void(0)';
anchor.addEventListener('click', (e) => {
targetObject.models = document.querySelectorAll(`.${dataid}`);
targetObject.models?.forEach((eachModel) => {
eachModel.classList.add('dp-none');
eachModel.remove();
body.prepend(eachModel);
});
e.preventDefault();
body.style.overflow = 'hidden';

targetObject.models?.forEach((eachModel) => {
eachModel.classList.remove('dp-none');
eachModel.classList.add('overlay');
const crossIcon = eachModel.querySelector('em');
if (crossIcon.innerHTML.includes(':cross-icon')) {
crossIcon.innerHTML = '';
crossIcon.addEventListener('click', (e) => {
eachModel.classList.remove('overlay');
eachModel.classList.add('dp-none');
});
}
});
});
}
const body = document.body;
processAnchor(anchor, body);
});
} catch (error) {
console.warn(error);
Expand Down Expand Up @@ -1285,3 +1254,68 @@ export function groupAllKeys(array) {
}, {});
}

// Helper functions
const handleRel = (anchor, hrefSplit) => {
if (hrefSplit.includes(',')) {
const rels = hrefSplit.split(',');
rels.forEach(function (eachRel) {
debugger
anchor.rel += `${eachRel.trim()}`;
});
} else {
anchor.rel = hrefSplit;
}
};
const handleModalPopup = (anchor, body) => {
const dataid = anchor.href.split('/').pop();
// Set attributes
anchor.dataset.modelId = dataid;
targetObject.modelId = dataid;
anchor.dataset.href = anchor.href;
anchor.href = 'javascript:void(0)';
anchor.addEventListener('click', (e) => {
e.preventDefault();
const models = document.querySelectorAll(`.${dataid}`);
targetObject.models = models;
if (!models.length) return;
// Handle models
models.forEach(model => {
model.classList.add('dp-none');
model.remove();
body.prepend(model);
// Show modal
model.classList.remove('dp-none');
model.classList.add('overlay');
// Handle close button
const crossIcon = model.querySelector('em');
if (crossIcon?.innerHTML.includes(':cross-icon')) {
crossIcon.innerHTML = '';
crossIcon.addEventListener('click', () => {
model.classList.remove('overlay');
model.classList.add('dp-none');
});
}
});
body.style.overflow = 'hidden';
});
};
// Main function
const processAnchor = (anchor, body) => {
// Handle rel attribute
if (anchor.href.includes('$')) {
const hrefSplit = anchor.href.split('$')[1];
if (hrefSplit) {
handleRel(anchor, hrefSplit);
anchor.href = anchor.href.split('$')[0];
}
}
// Handle target attribute
if (anchor.innerHTML.includes('<sub>')) {
anchor.target = '_blank';
}
// Handle modal popup
if (anchor.href.includes('/modal-popup/')) {
handleModalPopup(anchor, body);
}
};

0 comments on commit 4f6166a

Please sign in to comment.