Skip to content

Commit 92bad97

Browse files
authored
feat(FilmGrid): add initial loading state and improve loading indicators (#98)
1 parent 97ad116 commit 92bad97

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/components/Film/Grid.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function FilmGrid({
1010
currentSearchPage,
1111
totalSearchPages,
1212
loading,
13+
initialLoading = false,
1314
}) {
1415
const pathname = usePathname();
1516
const searchParams = useSearchParams();
@@ -45,6 +46,17 @@ export default function FilmGrid({
4546
className={`relative z-10 mx-auto flex w-full max-w-none flex-col gap-2 @container`}
4647
>
4748
<ul className="grid grid-cols-3 gap-2 @2xl:grid-cols-4 @5xl:grid-cols-5 @6xl:grid-cols-6 @7xl:grid-cols-7">
49+
{/* Initial loading */}
50+
{initialLoading &&
51+
loading &&
52+
[...Array(20)].map((_, i) => (
53+
<span
54+
key={i}
55+
className={`aspect-poster animate-pulse rounded-xl bg-gray-400 bg-opacity-20`}
56+
></span>
57+
))}
58+
59+
{/* Results */}
4860
{films?.map((film) => {
4961
return (
5062
<li key={film.id}>
@@ -56,10 +68,11 @@ export default function FilmGrid({
5668
);
5769
})}
5870

59-
{(loading || totalSearchPages > currentSearchPage) &&
60-
[...Array(20).keys()].map((_, i) => (
71+
{/* Infinite loading */}
72+
{(!loading && totalSearchPages > currentSearchPage) &&
73+
[...Array(20)].map((_, i) => (
6174
<span
62-
key={i}
75+
key={i + 20}
6376
ref={i === 0 ? loadMoreRef : null}
6477
className={`aspect-poster animate-pulse rounded-xl bg-gray-400 bg-opacity-20`}
6578
></span>

0 commit comments

Comments
 (0)