Skip to content

Commit

Permalink
fix: add context defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Dec 10, 2024
1 parent a4b53a3 commit 829cb5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/library-authoring/common/context/LibraryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ComponentEditorInfo {

export type LibraryContextData = {
/** The ID of the current library */
libraryId: string;
libraryId?: undefined | string;
libraryData?: ContentLibrary;
readOnly: boolean;
isLoadingLibraryData: boolean;
Expand Down Expand Up @@ -141,7 +141,20 @@ export function useLibraryContext(): LibraryContextData {
const ctx = useContext(LibraryContext);
if (ctx === undefined) {
/* istanbul ignore next */
throw new Error('useLibraryContext() was used in a component without a <LibraryProvider> ancestor.');
return {
libraryId: undefined,
readOnly: true,
isLoadingLibraryData: false,
collectionId: undefined,
setCollectionId: () => {},
showOnlyPublished: false,
isCreateCollectionModalOpen: false,
openCreateCollectionModal: () => {},
closeCreateCollectionModal: () => {},
componentBeingEdited: undefined,
openComponentEditor: () => {},
closeComponentEditor: () => {},
};
}
return ctx;
}
11 changes: 10 additions & 1 deletion src/library-authoring/common/context/SidebarContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,16 @@ export function useSidebarContext(): SidebarContextData {
const ctx = useContext(SidebarContext);
if (ctx === undefined) {
/* istanbul ignore next */
throw new Error('useSidebarContext() was used in a component without a <SidebarProvider> ancestor.');
return {
closeLibrarySidebar: () => {},
openAddContentSidebar: () => {},
openInfoSidebar: () => {},
openComponentInfoSidebar: () => {},
openCollectionInfoSidebar: () => {},
resetSidebarAdditionalActions: () => {},
setSidebarCurrentTab: () => {},
sidebarComponentInfo: undefined,
};
}
return ctx;
}

0 comments on commit 829cb5a

Please sign in to comment.