mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
clean up GenresView & GenresItemsContainer
This commit is contained in:
parent
1c6b1fc478
commit
071e7d15d9
4 changed files with 101 additions and 142 deletions
|
@ -1,54 +1,40 @@
|
|||
import type { BaseItemDtoQueryResult } from '@jellyfin/sdk/lib/generated-client';
|
||||
import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import React, { FC, useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import loading from '../../components/loading/loading';
|
||||
import * as userSettings from '../../scripts/settings/userSettings';
|
||||
import GenresItemsContainer from '../../components/common/GenresItemsContainer';
|
||||
import { LibraryViewProps, Query } from '../../types/interface';
|
||||
import { LibraryViewProps } from '../../types/interface';
|
||||
|
||||
const GenresView: FC<LibraryViewProps> = ({ topParentId }) => {
|
||||
const [ itemsResult, setItemsResult ] = useState<BaseItemDtoQueryResult>({});
|
||||
const element = useRef<HTMLDivElement>(null);
|
||||
|
||||
const getSettingsKey = useCallback(() => {
|
||||
return topParentId + '-genres';
|
||||
}, [topParentId]);
|
||||
|
||||
const getViewSettings = useCallback(() => {
|
||||
return getSettingsKey() + '-view';
|
||||
}, [getSettingsKey]);
|
||||
|
||||
let query = useMemo<Query>(() => ({
|
||||
SortBy: 'SortName',
|
||||
SortOrder: 'Ascending',
|
||||
IncludeItemTypes: 'Movie',
|
||||
Recursive: true,
|
||||
EnableTotalRecordCount: false,
|
||||
Limit: userSettings.libraryPageSize(undefined),
|
||||
StartIndex: 0,
|
||||
ParentId: topParentId }), [topParentId]);
|
||||
|
||||
query = userSettings.loadQuerySettings(getSettingsKey(), query);
|
||||
|
||||
const getCurrentViewStyle = useCallback(() => {
|
||||
return userSettings.get(getViewSettings(), false) || 'Poster';
|
||||
}, [getViewSettings]);
|
||||
|
||||
const reloadItems = useCallback(() => {
|
||||
loading.show();
|
||||
window.ApiClient.getGenres(window.ApiClient.getCurrentUserId(), query).then((result) => {
|
||||
window.ApiClient.getGenres(
|
||||
window.ApiClient.getCurrentUserId(),
|
||||
{
|
||||
SortBy: 'SortName',
|
||||
SortOrder: 'Ascending',
|
||||
IncludeItemTypes: 'Movie',
|
||||
Recursive: true,
|
||||
EnableTotalRecordCount: false,
|
||||
ParentId: topParentId
|
||||
}
|
||||
).then((result) => {
|
||||
setItemsResult(result);
|
||||
loading.hide();
|
||||
});
|
||||
}, [query]);
|
||||
}, [topParentId]);
|
||||
|
||||
useEffect(() => {
|
||||
reloadItems();
|
||||
}, [reloadItems]);
|
||||
|
||||
return (
|
||||
<div ref={element}>
|
||||
<GenresItemsContainer topParentId={topParentId} getCurrentViewStyle={getCurrentViewStyle} itemsResult={itemsResult} />
|
||||
</div>
|
||||
<GenresItemsContainer
|
||||
topParentId={topParentId}
|
||||
itemsResult={itemsResult}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue