Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hat-ring-components",
"version": "4.14.1",
"version": "4.14.2",
"description": "Head App Template - RING components",
"license": "MIT",
"repository": {},
Expand Down
4 changes: 1 addition & 3 deletions src/components/widgets/Lists/GenericList/GenericList.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ const allGeneralParts = GeneralParts;
let queryFragment = '';
let response: any = null;

const isAjaxCall = UtilsHelper_getQueryParam('gridLocationWidgetType', context) === 'genericList';
const isFirstCall = UtilsHelper_getQueryParam('isFirstCall', context) === '1';
const offset = WidgetHelper_calculateOffsetForGenericListPagination(widgetConfig, currentPage, isAjaxCall, isFirstCall);
const offset = WidgetHelper_calculateOffsetForGenericListPagination(widgetConfig, currentPage);

if (offset >= 1000) {
toRender = `<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ export async function GenericList_getData(context: AppContext, queryNodeFragment
return flag.excludedFlag
}) : null;

const isAjaxCall = UtilsHelper_getQueryParam('gridLocationWidgetType', context) === 'genericList';
const isFirstCall = UtilsHelper_getQueryParam('isFirstCall', context) === '1';
const offset = WidgetHelper_calculateOffsetForGenericListPagination(widgetConfig, currentPage, isAjaxCall, isFirstCall);
const offset = WidgetHelper_calculateOffsetForGenericListPagination(widgetConfig, currentPage);
const queryForDynamicName = getQueryForDynamicName(context, widgetConfig);

const variables: any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const noMoreItems = (response?.data?.stories?.edges?.length || 0) <= 0 || (respo

<script define:vars={{buttonId, gridLocation: widgetConfig.gridLocation, isMainSeoList: widgetConfig.mainSeoList, widgetType: widgetConfig.widgetType}}>
const button = document.getElementById(buttonId);
let isFirstCall = true;
button.addEventListener('click', loadMore);

const seoObserver = new IntersectionObserver(entries => {
Expand Down Expand Up @@ -54,12 +53,7 @@ const noMoreItems = (response?.data?.stories?.edges?.length || 0) <= 0 || (respo
ajaxNextPageUrl.searchParams.set('page', nextPage);
ajaxNextPageUrl.searchParams.set('gridLocation', gridLocation);
ajaxNextPageUrl.searchParams.set('gridLocationWidgetType', widgetType);
Comment thread
persd marked this conversation as resolved.
if (isFirstCall) {
ajaxNextPageUrl.searchParams.set('isFirstCall', 1);
isFirstCall = false;
} else {
ajaxNextPageUrl.searchParams.delete('isFirstCall');
}

const fetchedData = await fetch(ajaxNextPageUrl.href);
const html = await fetchedData.text();
const parser = new DOMParser();
Expand Down
14 changes: 2 additions & 12 deletions src/helpers/GenericListHelper.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import {UtilsHelper_convertToInt, UtilsHelper_parsePositiveIntFromString} from "./UtilsHelper";
import {GenericListWidgetConfig} from "../components/widgets/Lists/GenericList/types";
const MAX_OFFSET = 1000;
export function WidgetHelper_calculateOffsetForGenericListPagination(widgetConfig: GenericListWidgetConfig, currentPage: number, isAjaxCall: boolean, isFirstCall: boolean) {
export function WidgetHelper_calculateOffsetForGenericListPagination(widgetConfig: GenericListWidgetConfig, currentPage: number) {
const perPageAllItems = UtilsHelper_convertToInt(widgetConfig?.perPageAllItems) || UtilsHelper_convertToInt(widgetConfig?.paginationElements);
const postShiftValue = UtilsHelper_convertToInt(widgetConfig?.postShift) || 0;
currentPage = UtilsHelper_parsePositiveIntFromString(currentPage) || 1;
const totalItemsBefore = perPageAllItems * (currentPage - 1);
let offset = 0;
if (isAjaxCall) {
if (isFirstCall) {
offset = totalItemsBefore;
} else {
const shiftAdjustment = postShiftValue * (currentPage - 2);
offset = totalItemsBefore - shiftAdjustment;
}
} else {
offset = totalItemsBefore + postShiftValue;
}
const offset = totalItemsBefore + postShiftValue;

return Math.min(MAX_OFFSET - perPageAllItems, Math.max(0, offset));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export async function SeoListGridPrevNext(context: AppContext) {
return {};
}
const currentPage = UtilsHelper_parsePositiveIntFromString(UtilsHelper_getQueryParam('page', context)) || 1;
const isAjaxCall = UtilsHelper_getQueryParam('gridLocationWidgetType', context) === 'genericList';
const isFirstCall = UtilsHelper_getQueryParam('isFirstCall', context) === '1';
const offset = WidgetHelper_calculateOffsetForGenericListPagination(foundGenericList, currentPage, isAjaxCall, isFirstCall);
const offset = WidgetHelper_calculateOffsetForGenericListPagination(foundGenericList, currentPage);

if (offset >= MAX_OFFSET) {
return {}
Expand Down