diff --git a/src/fetch/fetchApps.ts b/src/fetch/fetchApps.ts index 8e12eed..01b1804 100644 --- a/src/fetch/fetchApps.ts +++ b/src/fetch/fetchApps.ts @@ -1,10 +1,10 @@ import { ApiEndpoints } from "../api/constants"; -const MEROKU_BASE_URL = process.env.API_HOST; +const MEROKU_BASE_URL = process.env.NEXT_PUBLIC_API_HOST; export async function fetchApps() { const res = await fetch( - `${MEROKU_BASE_URL}/${ApiEndpoints.APP_LIST}?limit=300`, + `${MEROKU_BASE_URL}/${ApiEndpoints.APP_LIST}?limit=100`, { headers: { apiKey: process.env.NEXT_PUBLIC_MEROKU_API_KEY || "", diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 77de08f..3f46748 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,3 +1,4 @@ +import { useEffect, useState } from "react"; import { AppList, Button, FeaturedLayout, PageLayout } from "../components"; import { Column } from "../components/layout/flex"; import { fetchApps } from "../fetch/fetchApps"; @@ -5,53 +6,84 @@ import { fetchCategories } from "../fetch/fetchCategories"; import { fetchFeatured } from "../fetch/fetchFeatured"; import { AppStrings } from "./constants"; -const Index = ({ categoryList, featuredList, homePageApps }) => { - return ( - <> - - -

- {AppStrings.allDapps} -

-
- -
- -

- You have seen a lot of apps. How about exploring - specific categories? -

- - -
-
- - - ); +const Index = ({ categoryList, featuredList }) => { + const [homePageApps, setHomePageApps] = useState([]); + const [loading, setLoading] = useState(false); + + const buildLoadingItems = (count: number = 10) => { + const _items: any[] = []; + for (let i = 0; i < count; i++) { + _items.push( +
+ ); + } + return _items; + }; + + const fetchDapps = async () => { + try { + setLoading(true); + const homePageApp = await fetchApps(); + setHomePageApps(homePageApp); + setLoading(false); + } catch (e) { + setLoading(false); + console.log; + } + }; + + useEffect(() => { + fetchDapps(); + }, []); + + return ( + <> + + +

{AppStrings.allDapps}

+
+ {loading ? ( +
+ {buildLoadingItems()} +
+ ) : ( + + )} +
+ +

+ You have seen a lot of apps. How about exploring specific + categories? +

+ + +
+
+ + + ); }; export default Index; export async function getStaticProps() { - const categories = await fetchCategories(); - const featured = await fetchFeatured(); - const homePageApps = await fetchApps(); - - return { - props: { - categoryList: categories, - featuredList: featured, - homePageApps: homePageApps, - }, - revalidate: 86400, // revalidate once every day - }; + const categories = await fetchCategories(); + const featured = await fetchFeatured(); + + return { + props: { + categoryList: categories, + featuredList: featured, + }, + revalidate: 86400, // revalidate once every day + }; }