diff --git a/app/src/components/layout/sidebarLeft/Assets.tsx b/app/src/components/layout/sidebarLeft/Assets.tsx index 2d4aa34..4e946d3 100644 --- a/app/src/components/layout/sidebarLeft/Assets.tsx +++ b/app/src/components/layout/sidebarLeft/Assets.tsx @@ -21,6 +21,8 @@ import { HangTagIcon, NavigationIcon, } from "../../icons/ExportCommonIcons"; +import { assert } from "console"; +import { getCategoryDecals } from "../../../services/factoryBuilder/asset/decals/getCategoryDecals"; // ------------------------------------- interface AssetProp { @@ -47,6 +49,7 @@ const Assets: React.FC = () => { const [searchValue, setSearchValue] = useState(""); const [selectedCategory, setSelectedCategory] = useState(null); const [categoryAssets, setCategoryAssets] = useState([]); + const [filtereredAssets, setFiltereredAssets] = useState([]); const [categoryList, setCategoryList] = useState([]); const [isLoading, setisLoading] = useState(false); // Loading state for assets @@ -118,6 +121,20 @@ const Assets: React.FC = () => { setisLoading(false); } }; + const fetchCategoryDecals = async (asset: any) => { + setisLoading(true); + // setSelectedCategory(asset); + try { + const res = await getCategoryDecals(asset); + setCategoryAssets(res); + setFiltereredAssets(res); + setisLoading(false); // End loading + // eslint-disable-next-line + } catch (error) { + echo.error("failed to fetch assets"); + setisLoading(false); + } + }; const activeSubcategories = [ { name: "Safety", icon: }, @@ -209,9 +226,13 @@ const Assets: React.FC = () => { {activeSubcategories.map((cat, index) => (
setSelectedSubCategory(cat.name)} + className={`catogory-asset-filter-wrapper ${ + selectedSubCategory === cat.name ? "active" : "" + }`} + onClick={() => { + fetchCategoryDecals(cat.name); + setSelectedSubCategory(cat.name); + }} >
{cat.icon}
{cat.name}
@@ -220,49 +241,96 @@ const Assets: React.FC = () => {
)} -
- {categoryAssets?.map((asset: any, index: number) => ( -
- {asset.filename} { - setSelectedItem({ - name: asset.filename, - id: asset.AssetID, - type: - asset.type === "undefined" - ? undefined - : asset.type, - category: asset.category, - subType: asset.subType, - }); - }} - /> -
- {asset.filename - .split("_") - .map( - (word: any) => - word.charAt(0).toUpperCase() + word.slice(1) - ) - .join(" ")} + + {selectedCategory !== "Decals" && !selectedSubCategory ? ( +
+ {categoryAssets?.map((asset: any, index: number) => ( +
+ {asset.filename} { + setSelectedItem({ + name: asset.filename, + id: asset.AssetID, + type: + asset.type === "undefined" + ? undefined + : asset.type, + category: asset.category, + subType: asset.subType, + }); + }} + /> +
+ {asset.filename + .split("_") + .map( + (word: any) => + word.charAt(0).toUpperCase() + word.slice(1) + ) + .join(" ")} +
-
- ))} - {categoryAssets.length === 0 && ( -
- 🚧 The asset shelf is empty. We're working on filling it - up! -
- )} -
+ ))} + {categoryAssets.length === 0 && ( +
+ 🚧 The asset shelf is empty. We're working on filling + it up! +
+ )} +
+ ) : ( +
+ {categoryAssets?.map((asset: any, index: number) => ( +
+ {asset.decalName} { + setSelectedItem({ + name: asset.decalName, + id: asset.id, + type: + asset.type === "undefined" + ? undefined + : asset.type, + category: asset.category, + // subType: asset.subType, + }); + }} + /> +
+ {asset.decalName + .split("_") + .map( + (word: any) => + word.charAt(0).toUpperCase() + word.slice(1) + ) + .join(" ")} +
+
+ ))} + {categoryAssets.length === 0 && ( +
+ 🚧 The asset shelf is empty. We're working on filling + it up! +
+ )} +
+ )}
); } @@ -282,7 +350,9 @@ const Assets: React.FC = () => { key={`${index}-${category}`} className="category" id={category} - onClick={() => fetchCategoryAssets(category)} + onClick={() => { + fetchCategoryAssets(category); + }} > { + try { + const response = await fetch( + `${BackEnd_url}/api/v1/categoryDecalDatas/${category}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ); + + const result = await response.json(); + return result; + } catch (error: any) { + echo.error("Failed to get category asset"); + console.log(error.message); + } +}; \ No newline at end of file