-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from merokudao/build-load-reduce
reducing build time load
- Loading branch information
Showing
2 changed files
with
78 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,89 @@ | ||
import { useEffect, useState } from "react"; | ||
import { AppList, Button, FeaturedLayout, PageLayout } from "../components"; | ||
import { Column } from "../components/layout/flex"; | ||
import { fetchApps } from "../fetch/fetchApps"; | ||
import { fetchCategories } from "../fetch/fetchCategories"; | ||
import { fetchFeatured } from "../fetch/fetchFeatured"; | ||
import { AppStrings } from "./constants"; | ||
|
||
const Index = ({ categoryList, featuredList, homePageApps }) => { | ||
return ( | ||
<> | ||
<FeaturedLayout featuredList={featuredList} /> | ||
<PageLayout categoryList={categoryList}> | ||
<h1 className="text-4xl mb-8 capitalize"> | ||
{AppStrings.allDapps} | ||
</h1> | ||
<div className="h-[54px] w-full" /> | ||
<AppList data={homePageApps} /> | ||
<div className="w-full my-8"> | ||
<Column className="flex items-center w-full gap-y-4"> | ||
<p className="text-md text-center"> | ||
You have seen a lot of apps. How about exploring | ||
specific categories? | ||
</p> | ||
|
||
<Button | ||
onClick={() => { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: "smooth", | ||
}); | ||
}} | ||
> | ||
Go to top | ||
</Button> | ||
</Column> | ||
</div> | ||
</PageLayout> | ||
</> | ||
); | ||
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( | ||
<div key={i} className="shimmer w-full h-[160px] rounded-lg" /> | ||
); | ||
} | ||
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 ( | ||
<> | ||
<FeaturedLayout featuredList={featuredList} /> | ||
<PageLayout categoryList={categoryList}> | ||
<h1 className="text-4xl mb-8 capitalize">{AppStrings.allDapps}</h1> | ||
<div className="h-[54px] w-full" /> | ||
{loading ? ( | ||
<div className="grid gap-8 grid-cols-1 md:grid-cols-2 3xl:grid-cols-3"> | ||
{buildLoadingItems()} | ||
</div> | ||
) : ( | ||
<AppList data={homePageApps} /> | ||
)} | ||
<div className="w-full my-8"> | ||
<Column className="flex items-center w-full gap-y-4"> | ||
<p className="text-md text-center"> | ||
You have seen a lot of apps. How about exploring specific | ||
categories? | ||
</p> | ||
|
||
<Button | ||
onClick={() => { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: "smooth", | ||
}); | ||
}} | ||
> | ||
Go to top | ||
</Button> | ||
</Column> | ||
</div> | ||
</PageLayout> | ||
</> | ||
); | ||
}; | ||
|
||
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 | ||
}; | ||
} |