Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated listing logic #32

Merged
merged 2 commits into from
Aug 17, 2023
Merged
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
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