Skip to content

Commit 66e347b

Browse files
committed
refactor: remove checkIfFavorited from ComponentLibraryProvider
1 parent 838ef5c commit 66e347b

File tree

3 files changed

+0
-65
lines changed

3 files changed

+0
-65
lines changed

src/components/shared/Dialogs/ComponentDuplicateDialog.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const createMockComponentLibraryContext = (
5353
refetchUserComponents: vi.fn(),
5454
setHighlightedComponentDigest: vi.fn(),
5555
setComponentFavorite: vi.fn(),
56-
checkIfFavorited: vi.fn().mockReturnValue(false),
5756
checkIfUserComponent: vi.fn().mockReturnValue(false),
5857
checkLibraryContainsComponent: vi.fn().mockReturnValue(false),
5958
checkIfHighlighted: vi.fn().mockReturnValue(false),

src/providers/ComponentLibraryProvider/ComponentLibraryProvider.test.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -645,28 +645,5 @@ describe("ComponentLibraryProvider - Component Management", () => {
645645
favorited: true,
646646
});
647647
});
648-
649-
it("should check if component is favorited correctly", async () => {
650-
const favoritedComponent: ComponentReference = {
651-
name: "favorited-component",
652-
digest: "fav-digest",
653-
spec: mockComponentSpec,
654-
favorited: true,
655-
};
656-
657-
mockFlattenFolders.mockReturnValue([favoritedComponent]);
658-
mockFilterToUniqueByDigest.mockReturnValue([favoritedComponent]);
659-
660-
const { result } = renderHook(() => useComponentLibrary(), {
661-
wrapper: createWrapper,
662-
});
663-
664-
await waitFor(() => {
665-
expect(result.current.isLoading).toBe(false);
666-
});
667-
668-
const isFavorited = result.current.checkIfFavorited(favoritedComponent);
669-
expect(isFavorited).toBe(true);
670-
});
671648
});
672649
});

src/providers/ComponentLibraryProvider/ComponentLibraryProvider.tsx

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ type ComponentLibraryContextType = {
9393
component: ComponentReference,
9494
favorited: boolean,
9595
) => void;
96-
/**
97-
* @deprecated
98-
*/
99-
checkIfFavorited: (component: ComponentReference) => boolean;
10096
checkIfUserComponent: (component: ComponentReference) => boolean;
10197
checkLibraryContainsComponent: (component: ComponentReference) => boolean;
10298
checkIfHighlighted: (component: ComponentReference) => boolean;
@@ -341,41 +337,6 @@ export const ComponentLibraryProvider = ({
341337
[refreshComponentLibrary, refreshUserComponents],
342338
);
343339

344-
const checkIfFavorited = useCallback(
345-
(component: ComponentReference) => {
346-
if (componentLibrary) {
347-
const uniqueLibraryComponents = filterToUniqueByDigest(
348-
flattenFolders(componentLibrary),
349-
);
350-
351-
const isFavourited = uniqueLibraryComponents.some(
352-
(c) => c.digest === component.digest && c.favorited,
353-
);
354-
355-
if (isFavourited) {
356-
return true;
357-
}
358-
}
359-
360-
if (userComponentsFolder) {
361-
const uniqueUserComponents = filterToUniqueByDigest(
362-
flattenFolders(userComponentsFolder),
363-
);
364-
365-
const isFavourited = uniqueUserComponents.some(
366-
(c) => c.digest === component.digest && c.favorited,
367-
);
368-
369-
if (isFavourited) {
370-
return true;
371-
}
372-
}
373-
374-
return false;
375-
},
376-
[componentLibrary, userComponentsFolder],
377-
);
378-
379340
const checkIfUserComponent = useCallback(
380341
(component: ComponentReference) => {
381342
if (!userComponentsFolder) return false;
@@ -651,7 +612,6 @@ export const ComponentLibraryProvider = ({
651612
refetchUserComponents,
652613
setHighlightedComponentDigest,
653614
setComponentFavorite,
654-
checkIfFavorited,
655615
checkIfUserComponent,
656616
checkLibraryContainsComponent,
657617
checkIfHighlighted,
@@ -674,7 +634,6 @@ export const ComponentLibraryProvider = ({
674634
refetchUserComponents,
675635
setHighlightedComponentDigest,
676636
setComponentFavorite,
677-
checkIfFavorited,
678637
checkIfUserComponent,
679638
checkLibraryContainsComponent,
680639
checkIfHighlighted,

0 commit comments

Comments
 (0)