|
1 |
| -import { syncBlocksWithDefaults, useRegisteredChaiBlocks } from "@chaibuilder/runtime"; |
| 1 | +import { syncBlocksWithDefaults } from "@chaibuilder/runtime"; |
2 | 2 | import { CaretRightIcon } from "@radix-ui/react-icons";
|
3 | 3 | import { useFeature } from "flagged";
|
4 | 4 | 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"; |
6 | 6 | import { Loader } from "lucide-react";
|
7 |
| -import { useCallback, useRef, useState } from "react"; |
| 7 | +import { useCallback, useEffect, useRef, useState } from "react"; |
8 | 8 | import { ScrollArea, Skeleton, Tooltip, TooltipContent, TooltipTrigger } from "../../../../../ui";
|
9 | 9 | import { cn } from "../../../../functions/Functions.ts";
|
10 | 10 | import { useAddBlock, useBuilderProp, useSelectedBlockIds } from "../../../../hooks";
|
@@ -128,13 +128,17 @@ const BlockCard = ({
|
128 | 128 | const UILibrarySection = ({ parentId, position }: { parentId?: string; position?: number }) => {
|
129 | 129 | const [selectedLibrary, setLibrary] = useAtom(selectedLibraryAtom);
|
130 | 130 | const uiLibraries = useBuilderProp("uiLibraries", []);
|
131 |
| - const registeredBlocks = useRegisteredChaiBlocks(); |
132 |
| - const customBlocks = values(registeredBlocks).filter((block) => block.category === "custom"); |
133 | 131 | const library = uiLibraries.find((library) => library.id === selectedLibrary) || first(uiLibraries);
|
134 | 132 | const { data: libraryBlocks, isLoading } = useLibraryBlocks(library);
|
135 | 133 |
|
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 | + |
138 | 142 | const blocks = get(mergedGroups, selectedGroup, []);
|
139 | 143 | const timeoutRef = useRef(null);
|
140 | 144 | const { t } = useTranslation();
|
|
0 commit comments