|
|
|
|
import { do_request } from './graphql-api-request.mjs';
|
|
|
|
|
|
|
|
|
|
/// PageEventsTabPastEventsCardRendererQuery
|
|
|
|
|
export const past_render_query = async ({ pageID }) => {
|
|
|
|
|
const doc_id = '4421910857857782';
|
|
|
|
|
const resp = await do_request(doc_id, { pageID });
|
|
|
|
|
const page = resp?.data?.page?.past_events ?? null;
|
|
|
|
|
return page;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// PageEventsTabPastEventsCardPaginationQuery
|
|
|
|
|
export const past_pagination_query = async ({ pageID, cursor }) => {
|
|
|
|
|
const doc_id = '6953034388071359';
|
|
|
|
|
const count = 9;
|
|
|
|
|
const resp = await do_request(doc_id, { pageID, cursor, count });
|
|
|
|
|
const page = resp?.data?.page?.past_events ?? null;
|
|
|
|
|
return page;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// PageEventsTabUpcomingEventsCardRendererQuery
|
|
|
|
|
export const upcoming_render_query = async ({ pageID }) => {
|
|
|
|
|
const doc_id = '5182274978466320';
|
|
|
|
|
const resp = await do_request(doc_id, { pageID });
|
|
|
|
|
const page = resp?.data?.page?.upcoming_events ?? null;
|
|
|
|
|
return page;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// PageEventsTabUpcomingEventsCardPaginationQuery
|
|
|
|
|
export const upcoming_pagination_query = async ({ pageID, cursor }) => {
|
|
|
|
|
const doc_id = '6985622308176123';
|
|
|
|
|
let count = 9;
|
|
|
|
|
const resp = await do_request(doc_id, { pageID, cursor, count });
|
|
|
|
|
const page = resp?.data?.page?.upcoming_events ?? null;
|
|
|
|
|
return page;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// PageEventsTabRecurringEventsCardRendererQuery
|
|
|
|
|
export const upcoming_reoccuring_render_query = async ({ pageID }) => {
|
|
|
|
|
const doc_id = '4458618790924188';
|
|
|
|
|
const resp = await do_request(doc_id, { pageID });
|
|
|
|
|
const page = resp?.data?.page?.upcomingRecurringEvents?.edges ?? null;
|
|
|
|
|
|
|
|
|
|
if (page === null || !Array.isArray(page)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let res = [];
|
|
|
|
|
|
|
|
|
|
page.forEach(({ node }) => {
|
|
|
|
|
let { childEvents, ...parent } = node;
|
|
|
|
|
childEvents.edges.forEach(({ node }) => {
|
|
|
|
|
let event = {
|
|
|
|
|
...parent,
|
|
|
|
|
...{
|
|
|
|
|
id: node.id,
|
|
|
|
|
time_range: { start: new Date(node.currentStartTimestamp * 1000) }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
res.push(event);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const get_page_events = async ({
|
|
|
|
|
pageID,
|
|
|
|
|
get_past_events,
|
|
|
|
|
get_upcoming_events
|
|
|
|
|
}) => {
|
|
|
|
|
let res = [];
|
|
|
|
|
|
|
|
|
|
const result = await past_render_query({ pageID });
|
|
|
|
|
|
|
|
|
|
if (result !== null) {
|
|
|
|
|
let { has_next_page, end_cursor: cursor } = result.page_info;
|
|
|
|
|
let { edges } = result;
|
|
|
|
|
let retries = 0;
|
|
|
|
|
while (get_past_events && has_next_page) {
|
|
|
|
|
const paginationResult = await past_pagination_query({
|
|
|
|
|
cursor,
|
|
|
|
|
pageID
|
|
|
|
|
});
|
|
|
|
|
if (paginationResult === null) {
|
|
|
|
|
++retries;
|
|
|
|
|
console.error(retries, 'retrying');
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (retries > 10) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
retries = 0;
|
|
|
|
|
edges = [...edges, ...paginationResult.edges];
|
|
|
|
|
has_next_page = paginationResult?.page_info?.has_next_page ?? false;
|
|
|
|
|
cursor = paginationResult.page_info.end_cursor;
|
|
|
|
|
}
|
|
|
|
|
res = [...edges.map(({ node }) => node)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_upcoming_events) {
|
|
|
|
|
const result = await upcoming_render_query({ pageID });
|
|
|
|
|
if (result !== null) {
|
|
|
|
|
let { has_next_page, end_cursor: cursor } = result.page_info;
|
|
|
|
|
let { edges } = result;
|
|
|
|
|
let retries = 0;
|
|
|
|
|
while (has_next_page) {
|
|
|
|
|
const paginationResult = await upcoming_pagination_query({
|
|
|
|
|
cursor,
|
|
|
|
|
pageID
|
|
|
|
|
});
|
|
|
|
|
if (paginationResult === null) {
|
|
|
|
|
++retries;
|
|
|
|
|
console.error(retries, 'retrying');
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (retries > 10) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
edges = [...edges, ...paginationResult.edges];
|
|
|
|
|
has_next_page = paginationResult?.page_info?.has_next_page ?? false;
|
|
|
|
|
cursor = paginationResult?.page_info?.end_cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = [...edges.map(({ node }) => node)];
|
|
|
|
|
}
|
|
|
|
|
const reoccuring = await upcoming_reoccuring_render_query({ pageID });
|
|
|
|
|
if (reoccuring !== null) {
|
|
|
|
|
res = [...res, ...reoccuring];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default get_page_events;
|