You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.9 KiB
98 lines
2.9 KiB
|
4 years ago
|
import { do_request } from './graphql-api-request.mjs';
|
||
|
4 years ago
|
const sleep = (s) => new Promise((res) => setTimeout(res, s * 1000));
|
||
|
|
|
||
|
4 years ago
|
/// PageEventsTabPastEventsCardRendererQuery
|
||
|
|
export const past_render_query = async ({ pageID }) => {
|
||
|
4 years ago
|
const doc_id = '4421910857857782';
|
||
|
4 years ago
|
const resp = await do_request(doc_id, { pageID });
|
||
|
|
const page = resp?.data?.page?.past_events ?? null;
|
||
|
4 years ago
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
4 years ago
|
/// 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;
|
||
|
4 years ago
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
4 years ago
|
/// 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;
|
||
|
4 years ago
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
4 years ago
|
// PageEventsTabUpcomingEventsCardPaginationQuery
|
||
|
|
export const upcoming_pagination_query = async ({ pageID, cursor }) => {
|
||
|
4 years ago
|
const doc_id = '6985622308176123';
|
||
|
|
let count = 9;
|
||
|
4 years ago
|
const resp = await do_request(doc_id, { pageID, cursor, count });
|
||
|
|
const page = resp?.data?.page?.upcoming_events ?? null;
|
||
|
4 years ago
|
return page;
|
||
|
|
};
|
||
|
|
|
||
|
|
const get_page_events = async ({
|
||
|
|
pageID,
|
||
|
|
get_past_events,
|
||
|
|
get_upcoming_events
|
||
|
|
}) => {
|
||
|
|
let past_events = [];
|
||
|
|
|
||
|
|
if (get_past_events) {
|
||
|
4 years ago
|
const result = await past_render_query({ pageID });
|
||
|
4 years ago
|
|
||
|
|
if (result !== null) {
|
||
|
|
let { has_next_page, end_cursor: cursor } = result.page_info;
|
||
|
|
|
||
|
|
let { edges } = result;
|
||
|
|
while (has_next_page) {
|
||
|
|
sleep(2);
|
||
|
4 years ago
|
const paginationResult = await past_pagination_query({
|
||
|
|
cursor,
|
||
|
|
pageID
|
||
|
|
});
|
||
|
4 years ago
|
if (paginationResult === null) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
edges = [...edges, ...paginationResult.edges];
|
||
|
4 years ago
|
has_next_page = paginationResult?.page_info?.has_next_page ?? false;
|
||
|
4 years ago
|
cursor = paginationResult.page_info.end_cursor;
|
||
|
|
}
|
||
|
|
past_events = [...edges];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let upcoming_events = [];
|
||
|
|
|
||
|
|
if (get_upcoming_events) {
|
||
|
4 years ago
|
const result = await upcoming_render_query({ pageID });
|
||
|
4 years ago
|
if (result !== null) {
|
||
|
|
upcoming_events = [];
|
||
|
|
let { has_next_page, end_cursor: cursor } = result.page_info;
|
||
|
|
let { edges } = result;
|
||
|
|
while (has_next_page) {
|
||
|
|
sleep(2);
|
||
|
4 years ago
|
const paginationResult = await upcoming_pagination_query({
|
||
|
|
cursor,
|
||
|
|
pageID
|
||
|
|
});
|
||
|
4 years ago
|
if (paginationResult === null) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
edges = [...edges, ...paginationResult.edges];
|
||
|
4 years ago
|
has_next_page = paginationResult?.page_info?.has_next_page ?? false;
|
||
|
|
cursor = paginationResult?.page_info?.end_cursor;
|
||
|
4 years ago
|
}
|
||
|
|
upcoming_events = [...edges];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return [...upcoming_events, ...past_events].map(({ node }) => node);
|
||
|
|
};
|
||
|
|
|
||
|
4 years ago
|
export default get_page_events;
|