feat(storeContext.tsx): modify getStoreComponents function to accept an object with optional parameters for better readability and maintainability
fix(API/index.ts): remove unused import and modify getStoreComponents function to accept an object with optional parameters for better readability and maintainability fix(from-store/index.tsx): modify handleGetComponents function to pass an object with optional parameters to getStoreComponents for better readability and maintainability fix(StorePage/index.tsx): modify handleGetComponents function to pass an object with optional parameters to getStoreComponents for better readability and maintainability
This commit is contained in:
parent
50ededfd3e
commit
7673402a0c
4 changed files with 41 additions and 38 deletions
|
|
@ -48,7 +48,10 @@ export function StoreProvider({ children }) {
|
|||
|
||||
function getSavedComponents() {
|
||||
setLoadingSaved(true);
|
||||
getStoreComponents(null, null, null, null, null, true)
|
||||
getStoreComponents({
|
||||
sort: "-count(liked_by)",
|
||||
liked: true,
|
||||
})
|
||||
.then((data) => {
|
||||
if (data?.authorized === false) {
|
||||
setErrorApiKey(true);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { BASE_URL_API } from "../../constants/constants";
|
|||
import { api } from "../../controllers/API/api";
|
||||
import {
|
||||
APIObjectType,
|
||||
Component,
|
||||
LoginType,
|
||||
Users,
|
||||
changeUser,
|
||||
|
|
@ -590,17 +589,27 @@ export async function getFlowsStore(): Promise<AxiosResponse<FlowType[]>> {
|
|||
return await api.get(`${BASE_URL_API}store/`);
|
||||
}
|
||||
|
||||
export async function getStoreComponents(
|
||||
page?: number | null,
|
||||
limit?: number | null,
|
||||
is_component?: boolean | null,
|
||||
sort?: string | null,
|
||||
tags?: string[] | null,
|
||||
liked?: boolean | null,
|
||||
status?: string | null,
|
||||
search?: string | null,
|
||||
filterByUser?: boolean | null
|
||||
): Promise<StoreComponentResponse | undefined> {
|
||||
export async function getStoreComponents({
|
||||
page = 1,
|
||||
limit = 9999999,
|
||||
is_component = null,
|
||||
sort = "-count(liked_by)",
|
||||
tags = [] || null,
|
||||
liked = null,
|
||||
status = null,
|
||||
search = null,
|
||||
filterByUser = null,
|
||||
}: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
is_component?: boolean | null;
|
||||
sort?: string;
|
||||
tags?: string[] | null;
|
||||
liked?: boolean | null;
|
||||
status?: string | null;
|
||||
search?: string | null;
|
||||
filterByUser?: boolean | null;
|
||||
}): Promise<StoreComponentResponse | undefined> {
|
||||
try {
|
||||
let url = `${BASE_URL_API}store/components/`;
|
||||
const queryParams: any = [];
|
||||
|
|
@ -652,18 +661,6 @@ export async function getStoreComponents(
|
|||
}
|
||||
}
|
||||
|
||||
export async function postStoreComponents(component: Component) {
|
||||
try {
|
||||
const res = await api.post(`${BASE_URL_API}store/components/`, component);
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getComponent(component_id: string) {
|
||||
try {
|
||||
const res = await api.get(
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@ export default function FromStore(): JSX.Element {
|
|||
|
||||
const handleGetComponents = () => {
|
||||
setLoading(true);
|
||||
console.log("get store components");
|
||||
getStoreComponents(null, null, null, "name", null, true)
|
||||
getStoreComponents({
|
||||
liked: true,
|
||||
sort: "name",
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false);
|
||||
setData(res?.results ?? []);
|
||||
|
|
|
|||
|
|
@ -65,17 +65,18 @@ export default function StorePage(): JSX.Element {
|
|||
|
||||
function handleGetComponents() {
|
||||
setLoading(true);
|
||||
getStoreComponents(
|
||||
pageIndex,
|
||||
pageSize,
|
||||
tabActive === "All" ? null : tabActive === "Flows" ? false : true,
|
||||
pageOrder === "Popular" ? "-count(downloads)" : "name",
|
||||
filteredCategories,
|
||||
selectFilter === "likedbyme" && hasApiKey ? true : null,
|
||||
null,
|
||||
searchText === "" ? null : searchText,
|
||||
selectFilter === "createdbyme" && hasApiKey ? true : null
|
||||
)
|
||||
getStoreComponents({
|
||||
page: pageIndex,
|
||||
limit: pageSize,
|
||||
is_component:
|
||||
tabActive === "All" ? null : tabActive === "Flows" ? false : true,
|
||||
sort: pageOrder === "Popular" ? "-count(downloads)" : "name",
|
||||
tags: filteredCategories,
|
||||
liked: selectFilter === "likedbyme" && hasApiKey ? true : null,
|
||||
status: null,
|
||||
search: searchText === "" ? null : searchText,
|
||||
filterByUser: selectFilter === "createdbyme" && hasApiKey ? true : null,
|
||||
})
|
||||
.then((res) => {
|
||||
setHasApiKey(res?.authorized ?? false);
|
||||
setLoading(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue