1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/view/components/Sort.tsx

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-08-06 01:36:13 +03:00
import React, { FunctionComponent, useEffect, useRef } from 'react';
import IconButtonElement from '../../elements/IconButtonElement';
import libraryBrowser from '../../scripts/libraryBrowser';
import * as userSettings from '../../scripts/settings/userSettings';
import { IQuery } from './type';
type SortProps = {
2022-08-21 03:09:22 +03:00
getSortMenuOptions: () => {
name: string;
id: string;
}[];
2022-08-06 01:36:13 +03:00
query: IQuery;
2022-08-21 03:09:22 +03:00
getSettingsKey: () => string;
2022-08-06 01:36:13 +03:00
reloadItems: () => void;
}
2022-08-21 03:09:22 +03:00
const Sort: FunctionComponent<SortProps> = ({ getSortMenuOptions, query, getSettingsKey, reloadItems }: SortProps) => {
2022-08-06 01:36:13 +03:00
const element = useRef<HTMLDivElement>(null);
useEffect(() => {
const btnSort = element.current?.querySelector('.btnSort');
if (btnSort) {
btnSort.addEventListener('click', (e) => {
libraryBrowser.showSortMenu({
2022-08-21 03:09:22 +03:00
items: getSortMenuOptions(),
2022-08-06 01:36:13 +03:00
callback: () => {
query.StartIndex = 0;
2022-08-21 03:09:22 +03:00
userSettings.saveQuerySettings(getSettingsKey(), query);
2022-08-06 01:36:13 +03:00
reloadItems();
},
query: query,
button: e.target
});
});
}
2022-08-21 03:09:22 +03:00
}, [getSortMenuOptions, query, reloadItems, getSettingsKey]);
2022-08-06 01:36:13 +03:00
return (
<div ref={element}>
<IconButtonElement
is='paper-icon-button-light'
className='btnSort autoSize'
title='Sort'
icon='material-icons sort_by_alpha'
/>
</div>
);
};
export default Sort;