2022-10-05 02:44:28 +03:00
|
|
|
import type { BaseItemDtoQueryResult } from '@jellyfin/sdk/lib/generated-client';
|
2022-10-02 19:07:42 +03:00
|
|
|
import React, { FC, useCallback, useEffect, useRef } from 'react';
|
2022-08-06 01:36:13 +03:00
|
|
|
|
|
|
|
import { playbackManager } from '../../components/playback/playbackmanager';
|
|
|
|
import IconButtonElement from '../../elements/IconButtonElement';
|
|
|
|
|
2022-10-14 02:07:54 +03:00
|
|
|
interface ShuffleProps {
|
2022-08-06 01:36:13 +03:00
|
|
|
itemsResult?: BaseItemDtoQueryResult;
|
|
|
|
topParentId: string | null;
|
|
|
|
}
|
|
|
|
|
2022-10-14 02:07:54 +03:00
|
|
|
const Shuffle: FC<ShuffleProps> = ({ itemsResult = {}, topParentId }) => {
|
2022-08-06 01:36:13 +03:00
|
|
|
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;
|