Blame view

pages/index.js 1.85 KB
jay committed
1 2
import Home from "../components/home/Home";
import Layout from "../components/layout/Layout";
jaymehta committed
3
import { getActivitiesByVendor, getActivitiesForEndUser } from "../redux/actions/activityAction";
4
import { getAllCategories } from "../redux/actions/categoriesAction";
Ravindra Kanojiya committed
5
import { getHomeBanner } from "../redux/actions/homeBannerAction";
6
import { getTestimonial } from "../redux/actions/testimonialAction";
jaymehta committed
7
import { loadUser } from "../redux/actions/userActions";
jay committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import { wrapper } from "../redux/store";

export default function IndexPage() {
  /** Client side rendering, traditional API call. */
  // const dispatch = useDispatch();
  // useEffect(() => {
  //   const fetchData = async () => {
  //     await dispatch(getProjects({ currentPage: 1, featuredOnHome: true }));
  //   };
  //   fetchData();
  // });

  return (
    <Layout>
      <Home />
    </Layout>
  );
}

/** For server side rendering */
28
export const getServerSideProps = wrapper.getServerSideProps(store => async ({ req, query }) => {
29 30 31
  try {
    await store.dispatch(getAllCategories())
    await store.dispatch(getTestimonial())
jaymehta committed
32
    await store.dispatch(getActivitiesForEndUser())
Ravindra Kanojiya committed
33
    await store.dispatch(getHomeBanner())
jay committed
34 35

  return {
Ravindra Kanojiya committed
36
    props: {},
37 38 39 40 41 42 43
    // Next.js will attempt to re-generate the page:
    // - Any requests to the page after the initial request and before 10 seconds are also cached and instantaneous.
    // - After the 10-second window, the next request will still show the cached (stale) page
    // - Next.js triggers a regeneration of the page in the background.
    // - Once the page generates successfully, Next.js will invalidate the cache and show the updated page. If the background regeneration fails, the old page would still be unaltered.
    // In seconds
    // revalidate: Number(process.env.NEXT_PUBLIC_ISR_REVALIDATE_AFTER)
jay committed
44
  };
45 46 47
} catch (error) {
  console.log("index.js", error);
}
jay committed
48
});