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

Add react-router

This commit is contained in:
Bill Thornton 2022-04-14 01:19:27 -04:00
parent 6534c0a596
commit b2372a96e2
16 changed files with 176 additions and 59 deletions

View file

@ -0,0 +1,22 @@
import React, { useLayoutEffect } from 'react';
import { HistoryRouterProps, Router } from 'react-router-dom';
export function HistoryRouter({ basename, children, history }: HistoryRouterProps) {
const [state, setState] = React.useState({
action: history.action,
location: history.location
});
useLayoutEffect(() => history.listen(setState), [history]);
return (
<Router
basename={basename}
// eslint-disable-next-line react/no-children-prop
children={children}
location={state.location}
navigationType={state.action}
navigator={history}
/>
);
}

50
src/components/Page.tsx Normal file
View file

@ -0,0 +1,50 @@
import React, { FunctionComponent, useEffect, useRef } from 'react';
import viewManager from './viewManager/viewManager';
type PageProps = {
title?: string
};
/**
* Page component that handles hiding active non-react views, triggering the required events for
* navigation and appRouter state updates, and setting the correct classes and data attributes.
*/
const Page: FunctionComponent<PageProps> = ({ children, title }) => {
const element = useRef<HTMLDivElement>(null);
useEffect(() => {
// hide active non-react views
viewManager.hideView();
}, []);
useEffect(() => {
const event = {
bubbles: true,
cancelable: false,
detail: {
isRestored: false
}
};
// pagebeforeshow - hides tabs on tabless pages in libraryMenu
element.current?.dispatchEvent(new CustomEvent('pagebeforeshow', event));
// viewshow - updates state of appRouter
element.current?.dispatchEvent(new CustomEvent('viewshow', event));
// pageshow - updates header/navigation in libraryMenu
element.current?.dispatchEvent(new CustomEvent('pageshow', event));
}, [ element ]);
return (
<div
ref={element}
data-role='page'
className='mainAnimatedPage page libraryPage allLibraryPage noSecondaryNavPage'
data-title={title}
data-backbutton='true'
>
{children}
</div>
);
};
export default Page;

View file

@ -122,7 +122,7 @@ class AppRouter {
isBack: action === Action.Pop
});
} else {
console.warn('[appRouter] "%s" route not found', normalizedPath, location);
console.info('[appRouter] "%s" route not found', normalizedPath, location);
}
}
@ -139,7 +139,7 @@ class AppRouter {
Events.on(apiClient, 'requestfail', this.onRequestFail);
});
ServerConnections.connect().then(result => {
return ServerConnections.connect().then(result => {
this.firstConnectionResult = result;
// Handle the initial route

View file

@ -1,42 +0,0 @@
import React, { FunctionComponent, useState } from 'react';
import SearchFields from '../search/SearchFields';
import SearchResults from '../search/SearchResults';
import SearchSuggestions from '../search/SearchSuggestions';
import LiveTVSearchResults from '../search/LiveTVSearchResults';
type SearchProps = {
serverId?: string,
parentId?: string,
collectionType?: string
};
const SearchPage: FunctionComponent<SearchProps> = ({ serverId, parentId, collectionType }: SearchProps) => {
const [ query, setQuery ] = useState<string>();
return (
<>
<SearchFields onSearch={setQuery} />
{!query &&
<SearchSuggestions
serverId={serverId || window.ApiClient.serverId()}
parentId={parentId}
/>
}
<SearchResults
serverId={serverId || window.ApiClient.serverId()}
parentId={parentId}
collectionType={collectionType}
query={query}
/>
<LiveTVSearchResults
serverId={serverId || window.ApiClient.serverId()}
parentId={parentId}
collectionType={collectionType}
query={query}
/>
</>
);
};
export default SearchPage;

View file

@ -21,8 +21,8 @@ const CARD_OPTIONS = {
type LiveTVSearchResultsProps = {
serverId?: string;
parentId?: string;
collectionType?: string;
parentId?: string | null;
collectionType?: string | null;
query?: string;
}

View file

@ -9,8 +9,8 @@ import SearchResultsRow from './SearchResultsRow';
type SearchResultsProps = {
serverId?: string;
parentId?: string;
collectionType?: string;
parentId?: string | null;
collectionType?: string | null;
query?: string;
}

View file

@ -22,7 +22,7 @@ const createSuggestionLink = ({ name, href }: { name: string, href: string }) =>
type SearchSuggestionsProps = {
serverId?: string;
parentId?: string;
parentId?: string | null;
}
const SearchSuggestions: FunctionComponent<SearchSuggestionsProps> = ({ serverId = window.ApiClient.serverId(), parentId }: SearchSuggestionsProps) => {

View file

@ -147,6 +147,15 @@ class ViewManager {
});
}
hideView() {
if (currentView) {
dispatchViewEvent(currentView, null, 'viewbeforehide');
dispatchViewEvent(currentView, null, 'viewhide');
currentView.classList.add('hide');
currentView = null;
}
}
tryRestoreView(options, onViewChanging) {
if (options.cancel) {
return Promise.reject({ cancelled: true });