fix(StorePage): fix pagination bug where incorrect index and pageSize were passed to getStoreComponents function
feat(StorePage): add support for dynamic pagination in StorePage by implementing handleChangePagination function feat(StorePage): add support for resetting filter in StorePage by implementing resetFilter function feat(StorePage): add support for displaying total rows count in StorePage feat(StorePage): add support for displaying loading message while fetching data in StorePage feat(StorePage): add support for displaying error message when there is an error fetching data in StorePage feat(StorePage): add support for displaying search input and search button in StorePage feat(StorePage): add support for filtering components by type in StorePage feat(StorePage): add support for displaying badges for each component type in StorePage feat(StorePage): add support for displaying market card components in StorePage feat(StorePage): add support for displaying paginator component in StorePage feat(StorePage): add support for displaying loading message while fetching data with API key in StorePage fix(types): add storeComponent property to PaginatorComponentType to differentiate between store and other components
This commit is contained in:
parent
3e315012e1
commit
1b69f02b16
2 changed files with 129 additions and 97 deletions
|
|
@ -45,20 +45,19 @@ export default function StorePage(): JSX.Element {
|
||||||
const [size, setPageSize] = useState(10);
|
const [size, setPageSize] = useState(10);
|
||||||
const [index, setPageIndex] = useState(1);
|
const [index, setPageIndex] = useState(1);
|
||||||
|
|
||||||
function handleChangePagination(pageIndex: number, pageSize: number) {}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleGetComponents();
|
handleGetComponents();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleGetComponents = () => {
|
const handleGetComponents = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
getStoreComponents(1, 10)
|
getStoreComponents(index - 1, 10000)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setSearchData(res);
|
setSearchData(res.slice(0, 10));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setErrorApiKey(false);
|
setErrorApiKey(false);
|
||||||
setData(res);
|
setData(res);
|
||||||
|
setTotalRowsCount(res.length);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setSearchData([]);
|
setSearchData([]);
|
||||||
|
|
@ -84,6 +83,34 @@ export default function StorePage(): JSX.Element {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function handleChangePagination(pageIndex: number, pageSize: number) {
|
||||||
|
setLoading(true);
|
||||||
|
getStoreComponents(pageIndex, pageSize)
|
||||||
|
.then((res) => {
|
||||||
|
setPageIndex(pageIndex);
|
||||||
|
setPageSize(pageSize);
|
||||||
|
setSearchData(res);
|
||||||
|
setLoading(false);
|
||||||
|
setErrorApiKey(false);
|
||||||
|
setData(res);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setSearchData([]);
|
||||||
|
setLoading(false);
|
||||||
|
setErrorApiKey(true);
|
||||||
|
setErrorData({
|
||||||
|
title: "Error to get components.",
|
||||||
|
list: [err["response"]["data"]["detail"]],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetFilter() {
|
||||||
|
setPageIndex(1);
|
||||||
|
setPageSize(10);
|
||||||
|
handleGetComponents();
|
||||||
|
}
|
||||||
|
|
||||||
const loadingWithApiKey = loading;
|
const loadingWithApiKey = loading;
|
||||||
const renderComponents = !loading;
|
const renderComponents = !loading;
|
||||||
|
|
||||||
|
|
@ -113,7 +140,6 @@ export default function StorePage(): JSX.Element {
|
||||||
<span className="community-page-description-text">
|
<span className="community-page-description-text">
|
||||||
Search flows and components from the community.
|
Search flows and components from the community.
|
||||||
</span>
|
</span>
|
||||||
{renderComponents && (
|
|
||||||
<div className="flex w-full flex-col gap-4 p-4">
|
<div className="flex w-full flex-col gap-4 p-4">
|
||||||
<div className="flex items-center justify-center gap-4">
|
<div className="flex items-center justify-center gap-4">
|
||||||
<div className="flex w-[13%] items-center justify-center gap-3 text-sm">
|
<div className="flex w-[13%] items-center justify-center gap-3 text-sm">
|
||||||
|
|
@ -148,9 +174,7 @@ export default function StorePage(): JSX.Element {
|
||||||
<Select
|
<Select
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
const filter = value === "Flow" ? false : true;
|
const filter = value === "Flow" ? false : true;
|
||||||
const search = data.filter(
|
const search = data.filter((f) => f.is_component === filter);
|
||||||
(f) => f.is_component === filter
|
|
||||||
);
|
|
||||||
value === "" ? setSearchData(data) : setSearchData(search);
|
value === "" ? setSearchData(data) : setSearchData(search);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -197,6 +221,9 @@ export default function StorePage(): JSX.Element {
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{renderComponents && (
|
||||||
|
<>
|
||||||
<div className="mt-6 grid w-full gap-4 md:grid-cols-2 lg:grid-cols-3">
|
<div className="mt-6 grid w-full gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||||
{searchData
|
{searchData
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -208,8 +235,13 @@ export default function StorePage(): JSX.Element {
|
||||||
<MarketCardComponent key={idx} data={item} />
|
<MarketCardComponent key={idx} data={item} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{totalRowsCount > 0 && !loading && (
|
||||||
|
<div className="relative bottom-2">
|
||||||
<PaginatorComponent
|
<PaginatorComponent
|
||||||
|
storeComponent={true}
|
||||||
pageIndex={index}
|
pageIndex={index}
|
||||||
pageSize={size}
|
pageSize={size}
|
||||||
totalRowsCount={totalRowsCount}
|
totalRowsCount={totalRowsCount}
|
||||||
|
|
@ -219,7 +251,6 @@ export default function StorePage(): JSX.Element {
|
||||||
></PaginatorComponent>
|
></PaginatorComponent>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{loadingWithApiKey && (
|
{loadingWithApiKey && (
|
||||||
<div className="flex w-full flex-col gap-4 p-4">Loading...</div>
|
<div className="flex w-full flex-col gap-4 p-4">Loading...</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,7 @@ export type PaginatorComponentType = {
|
||||||
rowsCount?: number[];
|
rowsCount?: number[];
|
||||||
totalRowsCount: number;
|
totalRowsCount: number;
|
||||||
paginate: (pageIndex: number, pageSize: number) => void;
|
paginate: (pageIndex: number, pageSize: number) => void;
|
||||||
|
storeComponent?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConfirmationModalType = {
|
export type ConfirmationModalType = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue