Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const createMockComponentLibraryContext = (
refetchUserComponents: vi.fn(),
setHighlightedComponentDigest: vi.fn(),
setComponentFavorite: vi.fn(),
checkIfFavorited: vi.fn().mockReturnValue(false),
checkIfUserComponent: vi.fn().mockReturnValue(false),
checkLibraryContainsComponent: vi.fn().mockReturnValue(false),
checkIfHighlighted: vi.fn().mockReturnValue(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,28 +645,5 @@ describe("ComponentLibraryProvider - Component Management", () => {
favorited: true,
});
});

it("should check if component is favorited correctly", async () => {
const favoritedComponent: ComponentReference = {
name: "favorited-component",
digest: "fav-digest",
spec: mockComponentSpec,
favorited: true,
};

mockFlattenFolders.mockReturnValue([favoritedComponent]);
mockFilterToUniqueByDigest.mockReturnValue([favoritedComponent]);

const { result } = renderHook(() => useComponentLibrary(), {
wrapper: createWrapper,
});

await waitFor(() => {
expect(result.current.isLoading).toBe(false);
});

const isFavorited = result.current.checkIfFavorited(favoritedComponent);
expect(isFavorited).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ type ComponentLibraryContextType = {
component: ComponentReference,
favorited: boolean,
) => void;
/**
* @deprecated
*/
checkIfFavorited: (component: ComponentReference) => boolean;
checkIfUserComponent: (component: ComponentReference) => boolean;
checkLibraryContainsComponent: (component: ComponentReference) => boolean;
checkIfHighlighted: (component: ComponentReference) => boolean;
Expand Down Expand Up @@ -341,41 +337,6 @@ export const ComponentLibraryProvider = ({
[refreshComponentLibrary, refreshUserComponents],
);

const checkIfFavorited = useCallback(
(component: ComponentReference) => {
if (componentLibrary) {
const uniqueLibraryComponents = filterToUniqueByDigest(
flattenFolders(componentLibrary),
);

const isFavourited = uniqueLibraryComponents.some(
(c) => c.digest === component.digest && c.favorited,
);

if (isFavourited) {
return true;
}
}

if (userComponentsFolder) {
const uniqueUserComponents = filterToUniqueByDigest(
flattenFolders(userComponentsFolder),
);

const isFavourited = uniqueUserComponents.some(
(c) => c.digest === component.digest && c.favorited,
);

if (isFavourited) {
return true;
}
}

return false;
},
[componentLibrary, userComponentsFolder],
);

const checkIfUserComponent = useCallback(
(component: ComponentReference) => {
if (!userComponentsFolder) return false;
Expand Down Expand Up @@ -651,7 +612,6 @@ export const ComponentLibraryProvider = ({
refetchUserComponents,
setHighlightedComponentDigest,
setComponentFavorite,
checkIfFavorited,
checkIfUserComponent,
checkLibraryContainsComponent,
checkIfHighlighted,
Expand All @@ -674,7 +634,6 @@ export const ComponentLibraryProvider = ({
refetchUserComponents,
setHighlightedComponentDigest,
setComponentFavorite,
checkIfFavorited,
checkIfUserComponent,
checkLibraryContainsComponent,
checkIfHighlighted,
Expand Down
Loading