Untitled
typescript
2 months ago
1.3 kB
4
Indexable
Never
export const getServerSideProps = async (): Promise<object> => { // fetchers const [ discountedBooks, bestSellerBooks, latestBooks, academicBooks, heroCarouselImagesAndBanners, ] = await Promise.all([ APIfetchBooksForSlider({ type: 'discounted' }), APIfetchBooksForSlider({ type: 'bestSelling' }), APIfetchBooksForSlider({ type: 'newest' }), APIfetchBooksForSlider({ type: 'academic' }), APIfetchHeroSliderAndBanners(), ]); // filter heroSlider const heroSliderData = heroCarouselImagesAndBanners.filter( (item: any) => item.webposition === 'CarouselBanner', ); // filter banners (sort by weposition) const bannersData = heroCarouselImagesAndBanners .filter((item: any) => item.webposition.includes('bannerRow')) .sort((a: any, b: any) => { if (a.webposition < b.webposition) { return -1; } if (a.webposition > b.webposition) { return 1; } return 0; }); return { props: { discountedBooksData: discountedBooks, bestSellerBooksData: bestSellerBooks, latestBooksData: latestBooks, academicBooksData: academicBooks, heroSliderData, bannersData, }, }; };