Skip to content

Commit e190ed9

Browse files
committed
refactor: simplify UILibrariesPanel by removing unused registeredBlocks
1 parent 2fea7a5 commit e190ed9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/core/components/sidepanels/panels/add-blocks/UILibrariesPanel.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { syncBlocksWithDefaults, useRegisteredChaiBlocks } from "@chaibuilder/runtime";
1+
import { syncBlocksWithDefaults } from "@chaibuilder/runtime";
22
import { CaretRightIcon } from "@radix-ui/react-icons";
33
import { useFeature } from "flagged";
44
import { useAtom } from "jotai";
5-
import { capitalize, filter, first, get, groupBy, has, isEmpty, map, noop, values } from "lodash-es";
5+
import { capitalize, filter, first, get, groupBy, has, isEmpty, keys, map, noop } from "lodash-es";
66
import { Loader } from "lucide-react";
7-
import { useCallback, useRef, useState } from "react";
7+
import { useCallback, useEffect, useRef, useState } from "react";
88
import { ScrollArea, Skeleton, Tooltip, TooltipContent, TooltipTrigger } from "../../../../../ui";
99
import { cn } from "../../../../functions/Functions.ts";
1010
import { useAddBlock, useBuilderProp, useSelectedBlockIds } from "../../../../hooks";
@@ -128,13 +128,17 @@ const BlockCard = ({
128128
const UILibrarySection = ({ parentId, position }: { parentId?: string; position?: number }) => {
129129
const [selectedLibrary, setLibrary] = useAtom(selectedLibraryAtom);
130130
const uiLibraries = useBuilderProp("uiLibraries", []);
131-
const registeredBlocks = useRegisteredChaiBlocks();
132-
const customBlocks = values(registeredBlocks).filter((block) => block.category === "custom");
133131
const library = uiLibraries.find((library) => library.id === selectedLibrary) || first(uiLibraries);
134132
const { data: libraryBlocks, isLoading } = useLibraryBlocks(library);
135133

136-
const mergedGroups = groupBy([...libraryBlocks, ...customBlocks], "group");
137-
const [selectedGroup, setGroup] = useState("Hero");
134+
const mergedGroups = groupBy([...libraryBlocks], "group");
135+
const [selectedGroup, setGroup] = useState(null);
136+
137+
useEffect(() => {
138+
if (selectedGroup) return;
139+
setGroup(first(keys(mergedGroups)));
140+
}, [mergedGroups, selectedGroup]);
141+
138142
const blocks = get(mergedGroups, selectedGroup, []);
139143
const timeoutRef = useRef(null);
140144
const { t } = useTranslation();

0 commit comments

Comments
 (0)