mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix home page loading with lazy
This commit is contained in:
parent
175b2d6c85
commit
255d982687
5 changed files with 18 additions and 70 deletions
32
package-lock.json
generated
32
package-lock.json
generated
|
@ -19,7 +19,6 @@
|
||||||
"@fontsource/noto-sans-tc": "5.0.19",
|
"@fontsource/noto-sans-tc": "5.0.19",
|
||||||
"@jellyfin/libass-wasm": "4.2.1",
|
"@jellyfin/libass-wasm": "4.2.1",
|
||||||
"@jellyfin/sdk": "0.0.0-unstable.202407020501",
|
"@jellyfin/sdk": "0.0.0-unstable.202407020501",
|
||||||
"@loadable/component": "5.16.4",
|
|
||||||
"@mui/icons-material": "5.15.19",
|
"@mui/icons-material": "5.15.19",
|
||||||
"@mui/material": "5.15.19",
|
"@mui/material": "5.15.19",
|
||||||
"@mui/x-data-grid": "7.6.1",
|
"@mui/x-data-grid": "7.6.1",
|
||||||
|
@ -4124,27 +4123,6 @@
|
||||||
"integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==",
|
"integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@loadable/component": {
|
|
||||||
"version": "5.16.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/@loadable/component/-/component-5.16.4.tgz",
|
|
||||||
"integrity": "sha512-fJWxx9b5WHX90QKmizo9B+es2so8DnBthI1mbflwCoOyvzEwxiZ/SVDCTtXEnHG72/kGBdzr297SSIekYtzSOQ==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@babel/runtime": "^7.12.18",
|
|
||||||
"hoist-non-react-statics": "^3.3.1",
|
|
||||||
"react-is": "^16.12.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/gregberge"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": "^16.3.0 || ^17.0.0 || ^18.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@mapbox/node-pre-gyp": {
|
"node_modules/@mapbox/node-pre-gyp": {
|
||||||
"version": "1.0.10",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz",
|
"resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz",
|
||||||
|
@ -26986,16 +26964,6 @@
|
||||||
"integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==",
|
"integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@loadable/component": {
|
|
||||||
"version": "5.16.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/@loadable/component/-/component-5.16.4.tgz",
|
|
||||||
"integrity": "sha512-fJWxx9b5WHX90QKmizo9B+es2so8DnBthI1mbflwCoOyvzEwxiZ/SVDCTtXEnHG72/kGBdzr297SSIekYtzSOQ==",
|
|
||||||
"requires": {
|
|
||||||
"@babel/runtime": "^7.12.18",
|
|
||||||
"hoist-non-react-statics": "^3.3.1",
|
|
||||||
"react-is": "^16.12.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@mapbox/node-pre-gyp": {
|
"@mapbox/node-pre-gyp": {
|
||||||
"version": "1.0.10",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz",
|
"resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz",
|
||||||
|
|
|
@ -81,7 +81,6 @@
|
||||||
"@fontsource/noto-sans-tc": "5.0.19",
|
"@fontsource/noto-sans-tc": "5.0.19",
|
||||||
"@jellyfin/libass-wasm": "4.2.1",
|
"@jellyfin/libass-wasm": "4.2.1",
|
||||||
"@jellyfin/sdk": "0.0.0-unstable.202407020501",
|
"@jellyfin/sdk": "0.0.0-unstable.202407020501",
|
||||||
"@loadable/component": "5.16.4",
|
|
||||||
"@mui/icons-material": "5.15.19",
|
"@mui/icons-material": "5.15.19",
|
||||||
"@mui/material": "5.15.19",
|
"@mui/material": "5.15.19",
|
||||||
"@mui/x-data-grid": "7.6.1",
|
"@mui/x-data-grid": "7.6.1",
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import loadable from '@loadable/component';
|
|
||||||
import { AsyncRoute, AsyncRouteType } from '../../../../components/router/AsyncRoute';
|
import { AsyncRoute, AsyncRouteType } from '../../../../components/router/AsyncRoute';
|
||||||
|
|
||||||
export const ASYNC_USER_ROUTES: AsyncRoute[] = [
|
export const ASYNC_USER_ROUTES: AsyncRoute[] = [
|
||||||
{
|
{ path: 'home.html', page: 'home', type: AsyncRouteType.Experimental },
|
||||||
path: 'home.html',
|
|
||||||
// FIXME: The use of tab manager for the home screen breaks when using lazy route handling
|
|
||||||
Component: loadable(() => import('../home'))
|
|
||||||
},
|
|
||||||
{ path: 'quickconnect', page: 'quickConnect' },
|
{ path: 'quickconnect', page: 'quickConnect' },
|
||||||
{ path: 'search.html', page: 'search' },
|
{ path: 'search.html', page: 'search' },
|
||||||
{ path: 'userprofile.html', page: 'user/userprofile' },
|
{ path: 'userprofile.html', page: 'user/userprofile' },
|
||||||
|
|
|
@ -2,14 +2,13 @@ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
import globalize from '../../../scripts/globalize';
|
import globalize from '../../../scripts/globalize';
|
||||||
import LibraryMenu from '../../../scripts/libraryMenu';
|
|
||||||
import { clearBackdrop } from '../../../components/backdrop/backdrop';
|
import { clearBackdrop } from '../../../components/backdrop/backdrop';
|
||||||
import layoutManager from '../../../components/layoutManager';
|
import layoutManager from '../../../components/layoutManager';
|
||||||
import * as mainTabsManager from '../../../components/maintabsmanager';
|
import Page from '../../../components/Page';
|
||||||
|
|
||||||
import '../../../elements/emby-tabs/emby-tabs';
|
import '../../../elements/emby-tabs/emby-tabs';
|
||||||
import '../../../elements/emby-button/emby-button';
|
import '../../../elements/emby-button/emby-button';
|
||||||
import '../../../elements/emby-scroller/emby-scroller';
|
import '../../../elements/emby-scroller/emby-scroller';
|
||||||
import Page from '../../../components/Page';
|
|
||||||
|
|
||||||
type OnResumeOptions = {
|
type OnResumeOptions = {
|
||||||
autoFocus?: boolean;
|
autoFocus?: boolean;
|
||||||
|
@ -29,12 +28,14 @@ const Home = () => {
|
||||||
const [ searchParams ] = useSearchParams();
|
const [ searchParams ] = useSearchParams();
|
||||||
const initialTabIndex = parseInt(searchParams.get('tab') ?? '0', 10);
|
const initialTabIndex = parseInt(searchParams.get('tab') ?? '0', 10);
|
||||||
|
|
||||||
|
const libraryMenu = useMemo(async () => ((await import('../../../scripts/libraryMenu')).default), []);
|
||||||
|
const mainTabsManager = useMemo(() => import('../../../components/maintabsmanager'), []);
|
||||||
const tabController = useRef<ControllerProps | null>();
|
const tabController = useRef<ControllerProps | null>();
|
||||||
const tabControllers = useMemo<ControllerProps[]>(() => [], []);
|
const tabControllers = useMemo<ControllerProps[]>(() => [], []);
|
||||||
const element = useRef<HTMLDivElement>(null);
|
const element = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const setTitle = () => {
|
const setTitle = async () => {
|
||||||
LibraryMenu.setTitle(null);
|
(await libraryMenu).setTitle(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTabs = () => {
|
const getTabs = () => {
|
||||||
|
@ -78,18 +79,6 @@ const Home = () => {
|
||||||
});
|
});
|
||||||
}, [ tabControllers ]);
|
}, [ tabControllers ]);
|
||||||
|
|
||||||
const onViewDestroy = useCallback(() => {
|
|
||||||
if (tabControllers) {
|
|
||||||
tabControllers.forEach(function (t) {
|
|
||||||
if (t.destroy) {
|
|
||||||
t.destroy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
tabController.current = null;
|
|
||||||
}, [ tabControllers ]);
|
|
||||||
|
|
||||||
const loadTab = useCallback((index: number, previousIndex: number | null) => {
|
const loadTab = useCallback((index: number, previousIndex: number | null) => {
|
||||||
getTabController(index).then((controller) => {
|
getTabController(index).then((controller) => {
|
||||||
const refresh = !controller.refreshed;
|
const refresh = !controller.refreshed;
|
||||||
|
@ -118,19 +107,23 @@ const Home = () => {
|
||||||
loadTab(newIndex, previousIndex);
|
loadTab(newIndex, previousIndex);
|
||||||
}, [ loadTab, tabControllers ]);
|
}, [ loadTab, tabControllers ]);
|
||||||
|
|
||||||
const onResume = useCallback(() => {
|
const onSetTabs = useCallback(async () => {
|
||||||
setTitle();
|
(await mainTabsManager).setTabs(element.current, initialTabIndex, getTabs, getTabContainers, null, onTabChange, false);
|
||||||
|
}, [ initialTabIndex, mainTabsManager, onTabChange ]);
|
||||||
|
|
||||||
|
const onResume = useCallback(async () => {
|
||||||
|
void setTitle();
|
||||||
clearBackdrop();
|
clearBackdrop();
|
||||||
|
|
||||||
const currentTabController = tabController.current;
|
const currentTabController = tabController.current;
|
||||||
|
|
||||||
if (!currentTabController) {
|
if (!currentTabController) {
|
||||||
mainTabsManager.selectedTabIndex(initialTabIndex);
|
(await mainTabsManager).selectedTabIndex(initialTabIndex);
|
||||||
} else if (currentTabController?.onResume) {
|
} else if (currentTabController?.onResume) {
|
||||||
currentTabController.onResume({});
|
currentTabController.onResume({});
|
||||||
}
|
}
|
||||||
(document.querySelector('.skinHeader') as HTMLDivElement).classList.add('noHomeButtonHeader');
|
(document.querySelector('.skinHeader') as HTMLDivElement).classList.add('noHomeButtonHeader');
|
||||||
}, [ initialTabIndex ]);
|
}, [ initialTabIndex, mainTabsManager ]);
|
||||||
|
|
||||||
const onPause = useCallback(() => {
|
const onPause = useCallback(() => {
|
||||||
const currentTabController = tabController.current;
|
const currentTabController = tabController.current;
|
||||||
|
@ -141,13 +134,13 @@ const Home = () => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mainTabsManager.setTabs(element.current, initialTabIndex, getTabs, getTabContainers, null, onTabChange, false);
|
void onSetTabs();
|
||||||
|
|
||||||
onResume();
|
void onResume();
|
||||||
return () => {
|
return () => {
|
||||||
onPause();
|
onPause();
|
||||||
};
|
};
|
||||||
}, [ initialTabIndex, onPause, onResume, onTabChange, onViewDestroy ]);
|
}, [ onPause, onResume, onSetTabs ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={element}>
|
<div ref={element}>
|
||||||
|
|
|
@ -16,8 +16,6 @@ export interface AsyncRoute {
|
||||||
page?: string
|
page?: string
|
||||||
/** The page type used to load the correct page element. */
|
/** The page type used to load the correct page element. */
|
||||||
type?: AsyncRouteType
|
type?: AsyncRouteType
|
||||||
/** Override for pages that don't support lazy importing */
|
|
||||||
Component?: React.ComponentType | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const importPage = (page: string, type: AsyncRouteType) => {
|
const importPage = (page: string, type: AsyncRouteType) => {
|
||||||
|
@ -34,13 +32,8 @@ const importPage = (page: string, type: AsyncRouteType) => {
|
||||||
export const toAsyncPageRoute = ({
|
export const toAsyncPageRoute = ({
|
||||||
path,
|
path,
|
||||||
page,
|
page,
|
||||||
Component,
|
|
||||||
type = AsyncRouteType.Stable
|
type = AsyncRouteType.Stable
|
||||||
}: AsyncRoute): RouteObject => {
|
}: AsyncRoute): RouteObject => {
|
||||||
if (Component) {
|
|
||||||
return { path, Component };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
lazy: async () => {
|
lazy: async () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue