use sortmenu instead of libraryBrowse .showSortMenu

This commit is contained in:
grafixeyehero 2022-10-03 01:23:59 +03:00
parent de4a359c98
commit df4de415b2
7 changed files with 113 additions and 167 deletions

View File

@ -1,5 +1,5 @@
import { BaseItemDto } from '@thornbill/jellyfin-sdk/dist/generated-client'; import { BaseItemDto } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent, useEffect, useRef } from 'react'; import React, { FC, useEffect, useRef } from 'react';
import ItemsContainerElement from '../../elements/ItemsContainerElement'; import ItemsContainerElement from '../../elements/ItemsContainerElement';
import cardBuilder from '../../components/cardbuilder/cardBuilder'; import cardBuilder from '../../components/cardbuilder/cardBuilder';
@ -9,7 +9,7 @@ import imageLoader from '../../components/images/imageLoader';
import '../../elements/emby-itemscontainer/emby-itemscontainer'; import '../../elements/emby-itemscontainer/emby-itemscontainer';
import { QueryI } from './interface'; import { QueryI } from './interface';
type ItemsContainerProps = { interface ItemsContainerI {
getCurrentViewStyle: () => string; getCurrentViewStyle: () => string;
query: QueryI; query: QueryI;
getContext: () => string | null; getContext: () => string | null;
@ -17,7 +17,7 @@ type ItemsContainerProps = {
noItemsMessage?: string; noItemsMessage?: string;
} }
const ItemsContainer: FunctionComponent<ItemsContainerProps> = ({ getCurrentViewStyle, query, getContext, items = [], noItemsMessage }: ItemsContainerProps) => { const ItemsContainer: FC<ItemsContainerI> = ({ getCurrentViewStyle, query, getContext, items = [], noItemsMessage }) => {
const element = useRef<HTMLDivElement>(null); const element = useRef<HTMLDivElement>(null);
const viewStyle = getCurrentViewStyle(); const viewStyle = getCurrentViewStyle();

View File

@ -1,40 +1,44 @@
import React, { FC, useEffect, useRef } from 'react'; import React, { FC, useCallback, useEffect, useRef } from 'react';
import IconButtonElement from '../../elements/IconButtonElement'; import IconButtonElement from '../../elements/IconButtonElement';
import libraryBrowser from '../../scripts/libraryBrowser';
import * as userSettings from '../../scripts/settings/userSettings';
import { QueryI } from './interface';
interface SortI { interface SortI {
getSortMenuOptions: () => { getSortMenuOptions: () => {
name: string; name: string;
id: string; value: string;
}[]; }[]
query: QueryI; getSortValues: () => {
sortBy: string;
sortOrder: string;
}
getSettingsKey: () => string; getSettingsKey: () => string;
reloadItems: () => void; reloadItems: () => void;
} }
const Sort: FC<SortI> = ({ getSortMenuOptions, query, getSettingsKey, reloadItems }) => { const Sort: FC<SortI> = ({ getSortMenuOptions, getSortValues, getSettingsKey, reloadItems }) => {
const element = useRef<HTMLDivElement>(null); const element = useRef<HTMLDivElement>(null);
const showSortMenu = useCallback(() => {
import('../../components/sortmenu/sortmenu').then(({default: SortMenu}) => {
const sortMenu = new SortMenu();
sortMenu.show({
settingsKey: getSettingsKey(),
settings: getSortValues(),
sortOptions: getSortMenuOptions()
}).then(() => {
reloadItems();
});
});
}, [getSettingsKey, getSortMenuOptions, getSortValues, reloadItems]);
useEffect(() => { useEffect(() => {
const btnSort = element.current?.querySelector('.btnSort'); const btnSort = element.current?.querySelector('.btnSort');
if (btnSort) { btnSort?.addEventListener('click', showSortMenu);
btnSort.addEventListener('click', (e) => {
libraryBrowser.showSortMenu({ return () => {
items: getSortMenuOptions(), btnSort?.removeEventListener('click', showSortMenu);
callback: () => { };
query.StartIndex = 0; }, [showSortMenu]);
userSettings.saveQuerySettings(getSettingsKey(), query);
reloadItems();
},
query: query,
button: e.target
});
});
}
}, [getSortMenuOptions, query, reloadItems, getSettingsKey]);
return ( return (
<div ref={element}> <div ref={element}>

View File

@ -1,5 +1,5 @@
import { BaseItemDtoQueryResult } from '@thornbill/jellyfin-sdk/dist/generated-client'; import { BaseItemDtoQueryResult } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import React, { FC, useCallback, useEffect, useRef, useState } from 'react';
import loading from '../../components/loading/loading'; import loading from '../../components/loading/loading';
import * as userSettings from '../../scripts/settings/userSettings'; import * as userSettings from '../../scripts/settings/userSettings';
@ -12,6 +12,7 @@ import Shuffle from './Shuffle';
import Sort from './Sort'; import Sort from './Sort';
import { QueryI } from './interface'; import { QueryI } from './interface';
import NewCollection from './NewCollection'; import NewCollection from './NewCollection';
import globalize from '../../scripts/globalize';
interface ViewItemsContainerI { interface ViewItemsContainerI {
topParentId: string | null; topParentId: string | null;
@ -22,10 +23,6 @@ interface ViewItemsContainerI {
getBasekey: () => string; getBasekey: () => string;
getFilterMode: () => string; getFilterMode: () => string;
getItemTypes: () => string; getItemTypes: () => string;
getSortMenuOptions: () => {
name: string;
id: string;
}[];
getNoItemsMessage: () => string; getNoItemsMessage: () => string;
} }
@ -38,7 +35,6 @@ const ViewItemsContainer: FC<ViewItemsContainerI> = ({
getBasekey, getBasekey,
getFilterMode, getFilterMode,
getItemTypes, getItemTypes,
getSortMenuOptions,
getNoItemsMessage getNoItemsMessage
}) => { }) => {
const [ itemsResult, setItemsResult ] = useState<BaseItemDtoQueryResult>({}); const [ itemsResult, setItemsResult ] = useState<BaseItemDtoQueryResult>({});
@ -53,24 +49,74 @@ const ViewItemsContainer: FC<ViewItemsContainerI> = ({
return `${getSettingsKey()} -view`; return `${getSettingsKey()} -view`;
}, [getSettingsKey]); }, [getSettingsKey]);
let query = useMemo<QueryI>(() => ({ const getDefaultSortBy = useCallback(() => {
SortBy: 'SortName,ProductionYear', return 'SortName';
SortOrder: 'Ascending', }, []);
IncludeItemTypes: getItemTypes(),
Recursive: true,
Fields: 'PrimaryImageAspectRatio,MediaSourceCount,BasicSyncInfo',
ImageTypeLimit: 1,
EnableImageTypes: 'Primary,Backdrop,Banner,Thumb',
Limit: userSettings.libraryPageSize(undefined),
StartIndex: 0,
ParentId: topParentId
}), [getItemTypes, topParentId]);
if (getBasekey() === 'favorites') { const getSortValues = useCallback(() => {
query.IsFavorite = true; const basekey = getSettingsKey();
}
query = userSettings.loadQuerySettings(getSettingsKey(), query); return {
sortBy: userSettings.getFilter(basekey + '-sortby') || getDefaultSortBy(),
sortOrder: userSettings.getFilter(basekey + '-sortorder') === 'Descending' ? 'Descending' : 'Ascending'
};
}, [getDefaultSortBy, getSettingsKey]);
const getQuery = useCallback(() => {
const query: QueryI = {
SortBy: getSortValues().sortBy,
SortOrder: getSortValues().sortOrder,
IncludeItemTypes: getItemTypes(),
Recursive: true,
Fields: 'PrimaryImageAspectRatio,MediaSourceCount,BasicSyncInfo',
ImageTypeLimit: 1,
EnableImageTypes: 'Primary,Backdrop,Banner,Thumb',
Limit: userSettings.libraryPageSize(undefined),
StartIndex: 0,
ParentId: topParentId
};
if (getBasekey() === 'favorites') {
query.IsFavorite = true;
}
userSettings.loadQuerySettings(getSettingsKey(), query);
return query;
}, [getSortValues, getItemTypes, topParentId, getBasekey, getSettingsKey]);
const getSortMenuOptions = useCallback(() => {
return [{
name: globalize.translate('Name'),
value: 'SortName,ProductionYear'
}, {
name: globalize.translate('OptionRandom'),
value: 'Random'
}, {
name: globalize.translate('OptionImdbRating'),
value: 'CommunityRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionCriticRating'),
value: 'CriticRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionDateAdded'),
value: 'DateCreated,SortName,ProductionYear'
}, {
name: globalize.translate('OptionDatePlayed'),
value: 'DatePlayed,SortName,ProductionYear'
}, {
name: globalize.translate('OptionParentalRating'),
value: 'OfficialRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionPlayCount'),
value: 'PlayCount,SortName,ProductionYear'
}, {
name: globalize.translate('OptionReleaseDate'),
value: 'PremiereDate,SortName,ProductionYear'
}, {
name: globalize.translate('Runtime'),
value: 'Runtime,SortName,ProductionYear'
}];
}, []);
const getCurrentViewStyle = useCallback(() => { const getCurrentViewStyle = useCallback(() => {
return userSettings.get(getViewSettings(), false) || 'Poster'; return userSettings.get(getViewSettings(), false) || 'Poster';
@ -93,6 +139,7 @@ const ViewItemsContainer: FC<ViewItemsContainerI> = ({
return; return;
} }
loading.show(); loading.show();
const query = getQuery();
window.ApiClient.getItems(window.ApiClient.getCurrentUserId(), query).then((result) => { window.ApiClient.getItems(window.ApiClient.getCurrentUserId(), query).then((result) => {
setItemsResult(result); setItemsResult(result);
window.scrollTo(0, 0); window.scrollTo(0, 0);
@ -103,7 +150,7 @@ const ViewItemsContainer: FC<ViewItemsContainerI> = ({
autoFocuser.autoFocus(page); autoFocuser.autoFocus(page);
}); });
}); });
}, [query]); }, [getQuery]);
useEffect(() => { useEffect(() => {
reloadItems(); reloadItems();
@ -112,30 +159,36 @@ const ViewItemsContainer: FC<ViewItemsContainerI> = ({
return ( return (
<div ref={element}> <div ref={element}>
<div className='flex align-items-center justify-content-center flex-wrap-wrap padded-top padded-left padded-right padded-bottom focuscontainer-x'> <div className='flex align-items-center justify-content-center flex-wrap-wrap padded-top padded-left padded-right padded-bottom focuscontainer-x'>
<Pagination itemsResult= {itemsResult} query={query} reloadItems={reloadItems} /> <Pagination itemsResult= {itemsResult} query={getQuery()} reloadItems={reloadItems} />
{isBtnShuffleEnabled && <Shuffle itemsResult={itemsResult} topParentId={topParentId} />} {isBtnShuffleEnabled && <Shuffle itemsResult={itemsResult} topParentId={topParentId} />}
<SelectView getCurrentViewStyle={getCurrentViewStyle} getViewSettings={getViewSettings} query={query} reloadItems={reloadItems} /> <SelectView getCurrentViewStyle={getCurrentViewStyle} getViewSettings={getViewSettings} query={getQuery()} reloadItems={reloadItems} />
<Sort getSortMenuOptions={getSortMenuOptions} query={query} getSettingsKey={getSettingsKey} reloadItems={reloadItems} />
{isBtnFilterEnabled && <Filter query={query} getFilterMode={getFilterMode} reloadItems={reloadItems} />} <Sort
getSortMenuOptions={getSortMenuOptions}
getSortValues={getSortValues}
getSettingsKey={getSettingsKey}
reloadItems={reloadItems}
/>
{isBtnFilterEnabled && <Filter query={getQuery()} getFilterMode={getFilterMode} reloadItems={reloadItems} />}
{isBtnNewCollectionEnabled && <NewCollection />} {isBtnNewCollectionEnabled && <NewCollection />}
</div> </div>
{isAlphaPickerEnabled && <AlphaPickerContainer query={query} reloadItems={reloadItems} />} {isAlphaPickerEnabled && <AlphaPickerContainer query={getQuery()} reloadItems={reloadItems} />}
<ItemsContainer <ItemsContainer
getCurrentViewStyle={getCurrentViewStyle} getCurrentViewStyle={getCurrentViewStyle}
query={query} query={getQuery()}
getContext={getContext} getContext={getContext}
items={itemsResult?.Items} items={itemsResult?.Items}
noItemsMessage={getNoItemsMessage()} noItemsMessage={getNoItemsMessage()}
/> />
<div className='flex align-items-center justify-content-center flex-wrap-wrap padded-top padded-left padded-right padded-bottom focuscontainer-x'> <div className='flex align-items-center justify-content-center flex-wrap-wrap padded-top padded-left padded-right padded-bottom focuscontainer-x'>
<Pagination itemsResult= {itemsResult} query={query} reloadItems={reloadItems} /> <Pagination itemsResult= {itemsResult} query={getQuery()} reloadItems={reloadItems} />
</div> </div>
</div> </div>
); );

View File

@ -1,6 +1,5 @@
import React, { FC, useCallback } from 'react'; import React, { FC, useCallback } from 'react';
import globalize from '../../scripts/globalize';
import ViewItemsContainer from '../components/ViewItemsContainer'; import ViewItemsContainer from '../components/ViewItemsContainer';
interface CollectionsViewI { interface CollectionsViewI {
@ -24,16 +23,6 @@ const CollectionsView: FC<CollectionsViewI> = ({ topParentId }) => {
return 'MessageNoCollectionsAvailable'; return 'MessageNoCollectionsAvailable';
}, []); }, []);
const getSortMenuOptions = useCallback(() => {
return [{
name: globalize.translate('Name'),
id: 'SortName'
}, {
name: globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName'
}];
}, []);
return ( return (
<ViewItemsContainer <ViewItemsContainer
topParentId={topParentId} topParentId={topParentId}
@ -43,7 +32,6 @@ const CollectionsView: FC<CollectionsViewI> = ({ topParentId }) => {
getBasekey={getBasekey} getBasekey={getBasekey}
getFilterMode={getFilterMode} getFilterMode={getFilterMode}
getItemTypes={getItemTypes} getItemTypes={getItemTypes}
getSortMenuOptions={getSortMenuOptions}
getNoItemsMessage={getNoItemsMessage} getNoItemsMessage={getNoItemsMessage}
/> />
); );

View File

@ -1,6 +1,5 @@
import React, { FC, useCallback } from 'react'; import React, { FC, useCallback } from 'react';
import globalize from '../../scripts/globalize';
import ViewItemsContainer from '../components/ViewItemsContainer'; import ViewItemsContainer from '../components/ViewItemsContainer';
interface FavoritesViewI { interface FavoritesViewI {
@ -24,47 +23,12 @@ const FavoritesView: FC<FavoritesViewI> = ({ topParentId }) => {
return 'MessageNoFavoritesAvailable'; return 'MessageNoFavoritesAvailable';
}, []); }, []);
const getSortMenuOptions = useCallback(() => {
return [{
name: globalize.translate('Name'),
id: 'SortName,ProductionYear'
}, {
name: globalize.translate('OptionRandom'),
id: 'Random'
}, {
name: globalize.translate('OptionImdbRating'),
id: 'CommunityRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionCriticRating'),
id: 'CriticRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName,ProductionYear'
}, {
name: globalize.translate('OptionDatePlayed'),
id: 'DatePlayed,SortName,ProductionYear'
}, {
name: globalize.translate('OptionParentalRating'),
id: 'OfficialRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName,ProductionYear'
}, {
name: globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName,ProductionYear'
}, {
name: globalize.translate('Runtime'),
id: 'Runtime,SortName,ProductionYear'
}];
}, []);
return ( return (
<ViewItemsContainer <ViewItemsContainer
topParentId={topParentId} topParentId={topParentId}
getBasekey={getBasekey} getBasekey={getBasekey}
getFilterMode={getFilterMode} getFilterMode={getFilterMode}
getItemTypes={getItemTypes} getItemTypes={getItemTypes}
getSortMenuOptions={getSortMenuOptions}
getNoItemsMessage={getNoItemsMessage} getNoItemsMessage={getNoItemsMessage}
/> />
); );

View File

@ -1,5 +1,4 @@
import React, { FC, useCallback } from 'react'; import React, { FC, useCallback } from 'react';
import globalize from '../../scripts/globalize';
import ViewItemsContainer from '../components/ViewItemsContainer'; import ViewItemsContainer from '../components/ViewItemsContainer';
@ -24,40 +23,6 @@ const MoviesView: FC<MoviesViewI> = ({ topParentId }) => {
return 'MessageNoItemsAvailable'; return 'MessageNoItemsAvailable';
}, []); }, []);
const getSortMenuOptions = useCallback(() => {
return [{
name: globalize.translate('Name'),
id: 'SortName,ProductionYear'
}, {
name: globalize.translate('OptionRandom'),
id: 'Random'
}, {
name: globalize.translate('OptionImdbRating'),
id: 'CommunityRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionCriticRating'),
id: 'CriticRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName,ProductionYear'
}, {
name: globalize.translate('OptionDatePlayed'),
id: 'DatePlayed,SortName,ProductionYear'
}, {
name: globalize.translate('OptionParentalRating'),
id: 'OfficialRating,SortName,ProductionYear'
}, {
name: globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName,ProductionYear'
}, {
name: globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName,ProductionYear'
}, {
name: globalize.translate('Runtime'),
id: 'Runtime,SortName,ProductionYear'
}];
}, []);
return ( return (
<ViewItemsContainer <ViewItemsContainer
topParentId={topParentId} topParentId={topParentId}
@ -65,7 +30,6 @@ const MoviesView: FC<MoviesViewI> = ({ topParentId }) => {
getBasekey={getBasekey} getBasekey={getBasekey}
getFilterMode={getFilterMode} getFilterMode={getFilterMode}
getItemTypes={getItemTypes} getItemTypes={getItemTypes}
getSortMenuOptions={getSortMenuOptions}
getNoItemsMessage={getNoItemsMessage} getNoItemsMessage={getNoItemsMessage}
/> />
); );

View File

@ -1,7 +1,6 @@
import React, { FC, useCallback } from 'react'; import React, { FC, useCallback } from 'react';
import globalize from '../../scripts/globalize';
import ViewItemsContainer from '../components/ViewItemsContainer'; import ViewItemsContainer from '../components/ViewItemsContainer';
interface TrailersViewI { interface TrailersViewI {
@ -25,38 +24,12 @@ const TrailersView: FC<TrailersViewI> = ({ topParentId }) => {
return 'MessageNoTrailersFound'; return 'MessageNoTrailersFound';
}, []); }, []);
const getSortMenuOptions = useCallback(() => {
return [{
name: globalize.translate('Name'),
id: 'SortName'
}, {
name: globalize.translate('OptionImdbRating'),
id: 'CommunityRating,SortName'
}, {
name: globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName'
}, {
name: globalize.translate('OptionDatePlayed'),
id: 'DatePlayed,SortName'
}, {
name: globalize.translate('OptionParentalRating'),
id: 'OfficialRating,SortName'
}, {
name: globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName'
}, {
name: globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName'
}];
}, []);
return ( return (
<ViewItemsContainer <ViewItemsContainer
topParentId={topParentId} topParentId={topParentId}
getBasekey={getBasekey} getBasekey={getBasekey}
getFilterMode={getFilterMode} getFilterMode={getFilterMode}
getItemTypes={getItemTypes} getItemTypes={getItemTypes}
getSortMenuOptions={getSortMenuOptions}
getNoItemsMessage={getNoItemsMessage} getNoItemsMessage={getNoItemsMessage}
/> />
); );