From 695f2194604247d556aeda0b8e182d5502109bf7 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 27 Oct 2023 17:36:49 -0300 Subject: [PATCH] fix(storeContext.tsx): change hasStore initial value to true to reflect correct initial state fix(API/index.ts): update API endpoint for checkHasStore function to match backend route feat(StorePage/index.tsx): add functionality to fetch and display store tags from backend --- src/frontend/src/contexts/storeContext.tsx | 4 ++-- src/frontend/src/controllers/API/index.ts | 2 +- src/frontend/src/pages/StorePage/index.tsx | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/contexts/storeContext.tsx b/src/frontend/src/contexts/storeContext.tsx index 77ca8bc81..2979fed7a 100644 --- a/src/frontend/src/contexts/storeContext.tsx +++ b/src/frontend/src/contexts/storeContext.tsx @@ -6,7 +6,7 @@ import { storeContextType } from "../types/contexts/store"; const initialValue = { savedFlows: new Set(), setSavedFlows: () => {}, - hasStore: false, + hasStore: true, setHasStore: () => {}, }; @@ -15,7 +15,7 @@ export const StoreContext = createContext(initialValue); export function StoreProvider({ children }) { const [savedFlows, setSavedFlows] = useState>(new Set()); - const [hasStore, setHasStore] = useState(false); + const [hasStore, setHasStore] = useState(true); checkHasStore().then((res) => { setHasStore(res["enabled"]); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index c10cdf277..19e1db6ce 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -685,7 +685,7 @@ export async function searchComponent( export async function checkHasStore() { try { - const res = await api.get(`${BASE_URL_API}store`); + const res = await api.get(`${BASE_URL_API}store/check/`); if (res.status === 200) { return res.data; } diff --git a/src/frontend/src/pages/StorePage/index.tsx b/src/frontend/src/pages/StorePage/index.tsx index 3c679f31c..44ff9931a 100644 --- a/src/frontend/src/pages/StorePage/index.tsx +++ b/src/frontend/src/pages/StorePage/index.tsx @@ -1,6 +1,6 @@ import { cloneDeep } from "lodash"; import { Search } from "lucide-react"; -import { useContext, useEffect, useState } from "react"; +import { useContext, useEffect, useRef, useState } from "react"; import PaginatorComponent from "../../components/PaginatorComponent"; import IconComponent from "../../components/genericIconComponent"; import Header from "../../components/headerComponent"; @@ -23,6 +23,7 @@ import { getNumberOfComponents, getStoreComponents, getStoreSavedComponents, + getStoreTags, searchComponent, } from "../../controllers/API"; import StoreApiKeyModal from "../../modals/StoreApiKeyModal"; @@ -48,6 +49,15 @@ export default function StorePage(): JSX.Element { const [errorApiKey, setErrorApiKey] = useState(false); const { setSavedFlows } = useContext(StoreContext); const [tags, setTags] = useState([]); + const tagListId = useRef<{ id: string; name: string }[]>([]); + + useEffect(() => { + getStoreTags().then((res) => { + tagListId.current = res; + let tags = res.map((tag) => tag.name); + setTags(tags); + }); + }, []); async function getSavedComponents() { setLoading(true);