diff --git a/src/frontend/src/contexts/storeContext.tsx b/src/frontend/src/contexts/storeContext.tsx index e8d3e4b64..d30ef7aa0 100644 --- a/src/frontend/src/contexts/storeContext.tsx +++ b/src/frontend/src/contexts/storeContext.tsx @@ -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); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 8e2dca38f..5b2494bbd 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -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> { 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 { +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 { 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( diff --git a/src/frontend/src/pages/MainPage/components/from-store/index.tsx b/src/frontend/src/pages/MainPage/components/from-store/index.tsx index 482b9b2f1..d567f6cf1 100644 --- a/src/frontend/src/pages/MainPage/components/from-store/index.tsx +++ b/src/frontend/src/pages/MainPage/components/from-store/index.tsx @@ -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 ?? []); diff --git a/src/frontend/src/pages/StorePage/index.tsx b/src/frontend/src/pages/StorePage/index.tsx index 61453710c..ffa6b76ba 100644 --- a/src/frontend/src/pages/StorePage/index.tsx +++ b/src/frontend/src/pages/StorePage/index.tsx @@ -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);