i have next.js project. and i need to replace infinite loader on index.tsx page with…
- User
i have next.js project. and i need to replace infinite loader on index.tsx page with paging, like on aliexpress website. note that i do not know total pages number, so i will made it like 'prev 1 2 3 ... next', 'prev 4 5 6 ... next', etc.
here is pages/index.tsx
import { MainPageDataType, MatterType, TagType } from "@/helpers/types"; import { GetServerSideProps, NextPage } from "next"; import { getMainPageData } from "@/helpers/getInstance"; import { usePlatform } from "@/helpers/platformContext"; import MattersList from "@/components/MattersList"; import InfScroll from "@/components/InfScroll"; import Loading from "@/components/Loading"; import useMatters from "@/helpers/useMatters"; import { serverApi } from "@/helpers/api"; import { useDevice } from "@/helpers/deviceContext"; import dynamic from "next/dynamic"; import Banner from "@/components/Banner"; import useToplineTransparenty from "@/helpers/useToplineTransparenty"; import EditButton from "@/components/EditButton"; import { SlugEnum } from "@/helpers/slugEnums"; import withDateToken from "@/helpers/withDateToken";
const MobileStory = dynamic(() => import("@/components/IndexPage/MobileStory")); const DayPictureMobile = dynamic( () => import("@/components/IndexPage/DayPictureMobile") ); const DayPictureDesktop = dynamic( () => import("@/components/IndexPage/DayPictureDesktop") ); const MobileBottomTabs = dynamic(() => import("@/components/MobileBottomTabs"));
const endpoint = "main_page/matters"; type PropsType = MainPageDataType & { initialMatters: MatterType[]; };
const IndexPage: NextPage = ({ day_picture, stories, initialMatters, day_picture_type, }) => { const { isMobile } = useDevice(); const { live_config, h1_title_on_main_page, settings_custom } = usePlatform(); const secondStory = stories ? stories[1]?.story : undefined; let firstItem: MatterType | TagType | undefined = day_picture[0]?.matter?.path ? day_picture[0]?.matter : undefined; if (stories && stories[0]?.story) firstItem = stories[0].story; if (live_config && (settings_custom.live_mainpage ?? true)) { firstItem = live_config; }
const otherItems = day_picture ?.filter((el) => el.matter?.path && el.matter?.path !== firstItem?.path) .map((el) => el.matter) .slice(0, 5);
const [{ matters, loading }, getMatters] = useMatters({ initialMatters, endpoint, });
useToplineTransparenty(!!day_picture && !!day_picture[0]?.matter?.path); // картины дня может не быть при ошибках на стороне api return ( <> {isMobile && firstItem ? ( <> </> ) : ( firstItem && ( ) )} {isMobile && secondStory && } <h1 className={"text-lg font-bold mb-[19px] lg:font-serif lg:text-[35px] lg:mb-[38px] max-w-[826px] mx-auto" + (isMobile ? (secondStory ? " mt-[10px]" : " mt-[30px]") : "")}> {withDateToken(h1_title_on_main_page)} <MattersList matters={matters} bannerSlug={SlugEnum.mainpage_feed} additionalBannerSlug={SlugEnum.mainpage_feed_3} showPeriod={false} initialMattersLength={ initialMatters?.length ? initialMatters.length : 0 } /> {loading && } <EditButton url={"/admin/publishers/homepage"} /> </> ); };
- Assistant
- User
i have only 10 items per page, but i want 20
- Assistant
- User
what i need to add, to pager work with url like /?page=3 if user opens this url first time
- Assistant
- User
all is good, but i have some strange bug, that items not all items replaced when page switched, some are stays from previous page, how to fix to replace all with new data
- Assistant