Skip to content

Commit

Permalink
Merge pull request #32 from ramangupta44/feature/update-apollo-client…
Browse files Browse the repository at this point in the history
…-to-delivery-endpoint

updated listing logic
  • Loading branch information
chopkarmanoj authored Aug 17, 2023
2 parents 276b042 + 2815f2c commit 520105b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sxastarter/src/components/Espire/Listing/Listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useSitecoreContext } from '@sitecore-jss/sitecore-jss-nextjs';
export const Listing = (props: ListingProps): JSX.Element => {
const [data, setData] = useState<ListingProps>();
const [loadMore, SetLoadMore] = useState('');
const [count, SetCount] = useState(5);
const [result, Setresult] = useState<ListingProps>();
const [hasnext, SetHasNext] = useState<ListingProps>();
const [items, setItems] = useState([]);
Expand All @@ -23,15 +24,14 @@ export const Listing = (props: ListingProps): JSX.Element => {
const { sitecoreContext } = useSitecoreContext();
const scope = props?.params?.Scope;
const language = sitecoreContext?.language;
const count = props?.params?.['Display Count'] ? props?.params?.['Display Count'] : 5;

const GetList = async (): Promise<unknown> => {
const { data } = await apolloClient.query({
query: Listing_Query,
variables: {
contextItem: scope,
language: language,
first: count,
first: count as number,
after: loadMore,
},
});
Expand All @@ -46,6 +46,7 @@ export const Listing = (props: ListingProps): JSX.Element => {
setData(undefined);
const result = await GetList();
if (!ignore) {
SetCount(props?.params?.['Display Count'] as unknown as number);
setData(
(result as ListingProps)?.ListingData?.children?.results as unknown as ListingProps
);
Expand Down Expand Up @@ -78,7 +79,6 @@ export const Listing = (props: ListingProps): JSX.Element => {

isHasNext();
}, [result, data]);

const LoadMore = async () => {
let finalData = [data]?.flat();
const result = await GetList();
Expand Down

0 comments on commit 520105b

Please sign in to comment.