Skip to content

Commit

Permalink
added paginator loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Dec 12, 2024
1 parent d64696d commit c9812fd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/app/modules/components/Paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Paginator = ({ total_count, take, onChange, page }: PaginatorProps)

const [_totalCount, _setTotalCount] = useState<number>(total_count);
const [_take, _setTake] = useState<number>(take);
const [_display, _setDisplay] = useState<boolean>(true);
const [_display, _setDisplay] = useState<boolean>(false);


useEffect(() => {
Expand All @@ -43,7 +43,7 @@ export const Paginator = ({ total_count, take, onChange, page }: PaginatorProps)
let itpage = _page > 2 && pages_count > 4 ? _page - 2 : 0;
for (let x = itpage; x < 5 + itpage; x++) {
data.push(
<p style={x == _page ? { backgroundColor: "var(--main-element-color)", padding: ".5rem" } : x < pages_count ? {} : { visibility: "hidden" }}
<p style={x == Math.max(0, _page) ? { backgroundColor: "var(--main-element-color)", padding: ".5rem" } : x < pages_count ? {} : { visibility: "hidden" }}
key={x}
className={Styles.page}
onClick={() => _setPage(x)}>
Expand All @@ -56,13 +56,21 @@ export const Paginator = ({ total_count, take, onChange, page }: PaginatorProps)
onChange(page);
}, [_page, _totalCount, _take]);

return _display ? <div className={Styles.container}>
{_pages.length > 0 && <>
const loadingPages = Array.from({ length: 5 }, (_, index) =>
<p
key={index}
className={`${Styles.page} ${Styles.page_loading}`} />
);

return <div className={Styles.container}>
<>
<IconChevronLeft className={`${Styles.page} ${Styles.arrow}`} onClick={() => _setPage(last => Math.max(0, last - 1))} />
{_pages}
{_display ?
_pages : loadingPages
}
<IconChevronRight className={`${Styles.page} ${Styles.arrow}`} onClick={() => _setPage(last => Math.min(last + 1, Math.ceil(_totalCount / _take) - 1))} />
</>
}
</div> : null;

</div>;

};
21 changes: 21 additions & 0 deletions src/app/styles/paginator.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@
background-color: var(--main-card-color);
}

.page_loading {
aspect-ratio: 1;
cursor: default;
background-color: var(--main-card-color);
animation: loading 3s infinite ease-in-out;
}

@keyframes loading {

0%,
50%,
100% {
opacity: 1;
}

25%,
75% {
opacity: .3;
}
}

@media(max-width: 767px) {
.page {
font-size: 1rem;
Expand Down
4 changes: 2 additions & 2 deletions src/app/workshop/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ export default function Home() {
onChangeTake={setTake}
onChangeSort={setSort}
onChangeFilters={setFilters} />
{elements && elements.length > 0 &&
<Paginator total_count={totalCount} take={take} onChange={setPage} page={page} />}

<Paginator total_count={totalCount} take={take} onChange={setPage} page={page} />
{elements && elements.length > 0 ?
<SimpleGrid>{elements}</SimpleGrid> :
<TheresNothingHere elements={elements} />
Expand Down

0 comments on commit c9812fd

Please sign in to comment.