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

44 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-08-06 01:36:13 +03:00
import { BaseItemDtoQueryResult } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react';
import { playbackManager } from '../../components/playback/playbackmanager';
import IconButtonElement from '../../elements/IconButtonElement';
type ShuffleProps = {
itemsResult?: BaseItemDtoQueryResult;
topParentId: string | null;
}
const Shuffle: FunctionComponent<ShuffleProps> = ({ itemsResult = {}, topParentId }: ShuffleProps) => {
const element = useRef<HTMLDivElement>(null);
const shuffle = useCallback(() => {
window.ApiClient.getItem(
window.ApiClient.getCurrentUserId(),
topParentId as string
).then((item) => {
playbackManager.shuffle(item);
});
}, [topParentId]);
useEffect(() => {
2022-08-21 03:09:22 +03:00
const btnShuffle = element.current?.querySelector('.btnShuffle');
2022-08-06 01:36:13 +03:00
if (btnShuffle) {
btnShuffle.addEventListener('click', shuffle);
}
}, [itemsResult.TotalRecordCount, shuffle]);
return (
<div ref={element}>
<IconButtonElement
is='paper-icon-button-light'
2022-08-21 03:09:22 +03:00
className='btnShuffle autoSize'
2022-08-06 01:36:13 +03:00
title='Shuffle'
icon='material-icons shuffle'
/>
</div>
);
};
export default Shuffle;