Skip to content

Commit

Permalink
Merge pull request #1769 from gustavomm19/optimize-requests
Browse files Browse the repository at this point in the history
Optimize requests
  • Loading branch information
alesanchezr authored Sep 26, 2023
2 parents 3676282 + a49b8fc commit 25e45b7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/components/Icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Icon = ({ icon, ...rest }) => {
const Comp = loadable(() =>
import(`./set/${icon}`).catch((err) => console.error(err))
);
return <Comp {...rest} />;
return icon && <Comp {...rest} />;
};
Icon.propTypes = {
icon: PropTypes.string.isRequired,
Expand Down
3 changes: 2 additions & 1 deletion src/components/UpcomingDates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ const UpcomingDates = ({
const academySlug = session.academyAliasDictionary[location]
? session.academyAliasDictionary[location]
: location;
const cohorts = await getCohorts({ academy: academySlug });
let cohorts = await getCohorts({ academy: academySlug, limit: 10 });
cohorts = cohorts?.results || [];
console.log("cohorts upcoming", cohorts);
let syllabus = [];
for (let i in cohorts) {
Expand Down
2 changes: 2 additions & 0 deletions src/data/page/calendar.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ meta_info:
redirects: ["/calendario", "/es/calendario"]

seo_title: "Coding Bootcamp"
show_more: Mostrar más
show_less: Mostrar menos
header:
title: Próximos programas y Eventos de 4GEEKS ACADEMY
paragraph: "Ajusta los filtros a los eventos de los cursos que más te interesan"
Expand Down
2 changes: 2 additions & 0 deletions src/data/page/calendar.us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ meta_info:
redirects: ["/upcoming", "/dates", "/calendar", "/us/calendar"]

seo_title: "Coding Bootcamp"
show_more: Show more
show_less: Show less
header:
title: Upcoming Courses
paragraph: "Filter the events or cohorts based what you are interested on"
Expand Down
5 changes: 3 additions & 2 deletions src/pages/thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ const ThumbnailPage = () => {
if (isWindow) document.body.className = "page-thumbnail";
}, [data]);

const url = `/images/bg/random-bg${Math.floor(Math.random() * 4) + 1}.png`;

const Div = styled.div`
background: url("/images/bg/random-bg${Math.floor(Math.random() * 4) +
1}.png");
background: url("${url}");
background-repeat: no-repeat;
background-size: cover;
height: 100vh;
Expand Down
11 changes: 7 additions & 4 deletions src/templates/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ const Calendar = (props) => {

useEffect(() => {
const getData = async () => {
let cohorts = await getCohorts();
let cohorts = await getCohorts({ limit: 100 });
let events = await getEvents();
let syllabus = [];
cohorts = cohorts?.results || [];
for (let i in cohorts) {
let name = cohorts[i].syllabus_version.name;
name === "Full-Stack Software Developer FT"
Expand Down Expand Up @@ -581,7 +582,7 @@ const Calendar = (props) => {
cursor="pointer"
onClick={() => setLimit(!limit)}
>
Show more
{content.show_more}
</Paragraph>
</GridContainer>
)}
Expand All @@ -596,7 +597,7 @@ const Calendar = (props) => {
cursor="pointer"
onClick={() => setLimit(!limit)}
>
Show less
{content.show_less}
</Paragraph>
</GridContainer>
)}
Expand All @@ -618,7 +619,7 @@ const Calendar = (props) => {
>
<>
{datas.events.filtered.map((m, i) => {
const limits = limit == true ? 6 : 100;
const limits = limit ? 6 : 100;
return (
i < limits && (
<Div
Expand Down Expand Up @@ -706,6 +707,8 @@ export const query = graphql`
image
keywords
}
show_more
show_less
events {
title
paragraph
Expand Down
48 changes: 24 additions & 24 deletions src/test/test.downloadable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ walk(`${__dirname}/../data/downloadable`, async (err, files) => {
const doc = loadYML(_path);
if (!doc || !doc.yaml) fail("Invalid YML syntax for " + _path);
});
try {
const resp = await fetch(
`https://breathecode.herokuapp.com/v1/marketing/downloadable`
);
const downloadables = await resp.json();

const _files = files.filter(
(f) =>
(f.indexOf(".yml") > 1 || f.indexOf(".yaml") > 1) &&
f.indexOf("additional-redirects.yml") === -1 &&
f.indexOf("call-to-actions.yml") === -1
);
const _files = files.filter(
(f) =>
(f.indexOf(".yml") > 1 || f.indexOf(".yaml") > 1) &&
f.indexOf("additional-redirects.yml") === -1 &&
f.indexOf("call-to-actions.yml") === -1
);

for (let i = 0; i < _files.length; i++) {
const _path = _files[i];
const doc = loadYML(_path);
if (!doc.yaml) fail("Invalid YML syntax for " + _path);
if (!doc.lang) fail("Missing language on yml file name for " + _path);
for (let i = 0; i < _files.length; i++) {
const _path = _files[i];
const doc = loadYML(_path);
if (!doc.yaml) fail("Invalid YML syntax for " + _path);
if (!doc.lang) fail("Missing language on yml file name for " + _path);

let meta_info_image = doc.yaml.meta_info.image;
let header_image = doc.yaml.header_data.image;
let meta_info_image = doc.yaml.meta_info.image;
let header_image = doc.yaml.header_data.image;

localizeImage(header_image, "relative_images", _path, ".");
localizeImage(meta_info_image, "relative_images", _path, "bg");
localizeImage(header_image, "relative_images", _path, ".");
localizeImage(meta_info_image, "relative_images", _path, "bg");

try {
const data = doc.yaml;
const meta_keys = Object.keys(data.meta_info);
const current_download = data.meta_info.current_download;

const resp = await fetch(
`https://breathecode.herokuapp.com/v1/marketing/downloadable`
);
const downloadables = await resp.json();
const scanResult = downloadables.some(
(el) => el.slug === current_download
);
Expand All @@ -68,10 +68,10 @@ walk(`${__dirname}/../data/downloadable`, async (err, files) => {
if (!meta_keys.includes(obj["key"]))
fail(`Missing prop ${obj["key"]} from course on ${_path}`);
});
} catch (error) {
console.error(`Error on file: ${_path}`.red);
fail(error.message || error);
}
success("All Downloadables yml have correct properties");
} catch (error) {
console.error(`Error on file: ${_path}`.red);
fail(error.message || error);
}
success("All Downloadables yml have correct properties");
});

0 comments on commit 25e45b7

Please sign in to comment.