import React, { FC, useCallback } from 'react'; import IconButton from '@mui/material/IconButton'; import MenuItem from '@mui/material/MenuItem'; import Popover from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; import Divider from '@mui/material/Divider'; import Box from '@mui/material/Box'; import InputLabel from '@mui/material/InputLabel'; import FormControl from '@mui/material/FormControl'; import Select, { SelectChangeEvent } from '@mui/material/Select'; import SortByAlphaIcon from '@mui/icons-material/SortByAlpha'; import globalize from 'scripts/globalize'; import { LibraryViewSettings } from 'types/library'; import { LibraryTab } from 'types/libraryTab'; import { ItemSortBy } from '@jellyfin/sdk/lib/models/api/item-sort-by'; import { SortOrder } from '@jellyfin/sdk/lib/generated-client'; const sortMenuOptions = [ { label: 'Name', value: ItemSortBy.SortName }, { label: 'OptionRandom', value: ItemSortBy.Random }, { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, { label: 'OptionCriticRating', value: ItemSortBy.CriticRating }, { label: 'OptionDateAdded', value: ItemSortBy.DateCreated }, { label: 'OptionDatePlayed', value: ItemSortBy.DatePlayed }, { label: 'OptionParentalRating', value: ItemSortBy.OfficialRating }, { label: 'OptionPlayCount', value: ItemSortBy.PlayCount }, { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate }, { label: 'Runtime', value: ItemSortBy.Runtime } ]; const sortOrderMenuOptions = [ { label: 'Ascending', value: SortOrder.Ascending }, { label: 'Descending', value: SortOrder.Descending } ]; interface SortButtonProps { viewType: LibraryTab; libraryViewSettings: LibraryViewSettings; setLibraryViewSettings: React.Dispatch< React.SetStateAction >; } const SortButton: FC = ({ viewType, libraryViewSettings, setLibraryViewSettings }) => { const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); const id = open ? 'sort-popover' : undefined; const handleClick = useCallback((event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }, []); const handleClose = useCallback(() => { setAnchorEl(null); }, []); const onSelectChange = useCallback( (event: SelectChangeEvent) => { const name = event.target.name; setLibraryViewSettings((prevState) => ({ ...prevState, StartIndex: 0, [name]: event.target.value })); }, [setLibraryViewSettings] ); const getVisibleSortMenu = () => { const visibleSortMenu: ItemSortBy[] = [ItemSortBy.SortName, ItemSortBy.Random, ItemSortBy.DateCreated]; if ( viewType !== LibraryTab.Photos && viewType !== LibraryTab.Videos && viewType !== LibraryTab.Books ) { visibleSortMenu.push(ItemSortBy.CommunityRating); visibleSortMenu.push(ItemSortBy.CriticRating); visibleSortMenu.push(ItemSortBy.DatePlayed); visibleSortMenu.push(ItemSortBy.OfficialRating); visibleSortMenu.push(ItemSortBy.PlayCount); visibleSortMenu.push(ItemSortBy.PremiereDate); visibleSortMenu.push(ItemSortBy.Runtime); } return visibleSortMenu; }; return ( {globalize.translate('LabelSortBy')} {globalize.translate('LabelSortOrder')} ); }; export default SortButton;