jellyfish-web/src/view/components/SectionContainer.tsx

63 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-08-07 02:33:25 +03:00
import '../../elements/emby-itemscontainer/emby-itemscontainer';
import { BaseItemDto } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent, useEffect, useRef } from 'react';
import cardBuilder from '../../components/cardbuilder/cardBuilder';
import ItemsContainerElement from '../../elements/ItemsContainerElement';
import ItemsScrollerContainerElement from '../../elements/ItemsScrollerContainerElement';
2022-09-02 02:46:05 +03:00
import { ICardOptions } from './type';
2022-08-07 02:33:25 +03:00
2022-09-02 02:46:05 +03:00
type SectionContainerProps = {
sectionTitle: string;
2022-08-07 02:33:25 +03:00
enableScrollX: () => boolean;
items?: BaseItemDto[];
2022-09-02 02:46:05 +03:00
cardOptions?: ICardOptions;
2022-08-07 02:33:25 +03:00
}
2022-09-02 02:46:05 +03:00
const SectionContainer: FunctionComponent<SectionContainerProps> = ({
sectionTitle,
enableScrollX,
items = [],
cardOptions = {}
}: SectionContainerProps) => {
2022-08-07 02:33:25 +03:00
const element = useRef<HTMLDivElement>(null);
useEffect(() => {
cardBuilder.buildCards(items, {
itemsContainer: element.current?.querySelector('.itemsContainer'),
2022-09-02 02:46:05 +03:00
parentContainer: element.current?.querySelector('.verticalSection'),
2022-08-07 02:33:25 +03:00
scalable: true,
overlayPlayButton: true,
showTitle: true,
2022-09-02 02:46:05 +03:00
centerText: true,
cardLayout: false,
...cardOptions
2022-08-07 02:33:25 +03:00
});
2022-09-02 02:46:05 +03:00
}, [cardOptions, enableScrollX, items]);
2022-08-07 02:33:25 +03:00
return (
<div ref={element}>
2022-09-02 02:46:05 +03:00
<div className='verticalSection hide'>
2022-08-07 02:33:25 +03:00
<div className='sectionTitleContainer sectionTitleContainer-cards'>
<h2 className='sectionTitle sectionTitle-cards padded-left'>
2022-09-02 02:46:05 +03:00
{sectionTitle}
2022-08-07 02:33:25 +03:00
</h2>
</div>
{enableScrollX() ? <ItemsScrollerContainerElement
scrollerclassName='padded-top-focusscale padded-bottom-focusscale'
dataMousewheel='false'
dataCenterfocus='true'
className='itemsContainer scrollSlider focuscontainer-x'
/> : <ItemsContainerElement
className='itemsContainer focuscontainer-x padded-left padded-right vertical-wrap'
/>}
2022-08-07 02:33:25 +03:00
</div>
</div>
);
};
2022-09-02 02:46:05 +03:00
export default SectionContainer;