import { useEffect } from 'react';
import { StudioFooter } from '@edx/frontend-component-footer';
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Badge,
Button,
Breadcrumb,
Container,
Icon,
IconButton,
Stack,
} from '@openedx/paragon';
import { Add, ArrowBack, InfoOutline } from '@openedx/paragon/icons';
import { Link } from 'react-router-dom';
import Loading from '../../generic/Loading';
import ErrorAlert from '../../generic/alert-error';
import SubHeader from '../../generic/sub-header/SubHeader';
import Header from '../../header';
import NotFoundAlert from '../../generic/NotFoundAlert';
import {
ClearFiltersButton,
FilterByBlockType,
FilterByTags,
SearchContextProvider,
SearchKeywordsField,
SearchSortWidget,
} from '../../search-manager';
import { useCollection, useContentLibrary } from '../data/apiHooks';
import { useLibraryContext } from '../common/context';
import messages from './messages';
import { LibrarySidebar } from '../library-sidebar';
import LibraryCollectionComponents from './LibraryCollectionComponents';
const HeaderActions = () => {
const intl = useIntl();
const {
openAddContentSidebar,
readOnly,
} = useLibraryContext();
if (readOnly) {
return null;
}
return (
);
};
const SubHeaderTitle = ({
title,
infoClickHandler,
}: {
title: string;
infoClickHandler: () => void;
}) => {
const intl = useIntl();
const { readOnly, componentPickerMode } = useLibraryContext();
const showReadOnlyBadge = readOnly && !componentPickerMode;
return (
{title}
{showReadOnlyBadge && (
{intl.formatMessage(messages.readOnlyBadge)}
)}
);
};
const LibraryCollectionPage = () => {
const intl = useIntl();
const { libraryId, collectionId } = useLibraryContext();
if (!collectionId || !libraryId) {
// istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker.
throw new Error('Rendered without collectionId or libraryId URL parameter');
}
const {
sidebarComponentInfo,
openCollectionInfoSidebar,
componentPickerMode,
showOnlyPublished,
setCollectionId,
} = useLibraryContext();
const {
data: collectionData,
isLoading,
isError,
error,
} = useCollection(libraryId, collectionId);
useEffect(() => {
openCollectionInfoSidebar(collectionId);
}, [collectionData]);
const { data: libraryData, isLoading: isLibLoading } = useContentLibrary(libraryId);
// Only show loading if collection data is not fetched from index yet
// Loading info for search results will be handled by LibraryCollectionComponents component.
if (isLibLoading || isLoading) {
return ;
}
if (!libraryData) {
return ;
}
if (isError) {
return ;
}
const breadcumbs = !componentPickerMode ? (
` spacer.
{
label: '',
to: '',
},
]}
linkAs={Link}
/>
) : (
{ setCollectionId(undefined); },
},
]}
spacer={}
linkAs={Link}
/>
);
const extraFilter = [`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`];
if (showOnlyPublished) {
extraFilter.push('last_published IS NOT NULL');
}
return (
{!componentPickerMode && (
)}
openCollectionInfoSidebar(collectionId)}
/>
)}
breadcrumbs={breadcumbs}
headerActions={}
/>
{!!sidebarComponentInfo?.type && (
)}
);
};
export default LibraryCollectionPage;