mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Remove connections prop
This commit is contained in:
parent
9bf0a6bf4d
commit
516bd2aab8
3 changed files with 12 additions and 17 deletions
|
@ -2,13 +2,12 @@ import { History } from '@remix-run/router';
|
|||
import React from 'react';
|
||||
|
||||
import { HistoryRouter } from './components/HistoryRouter';
|
||||
import ServerConnections from './components/ServerConnections';
|
||||
import { ApiProvider } from './hooks/useApi';
|
||||
import AppRoutes from './routes/index';
|
||||
|
||||
const App = ({ history, connections }: { history: History, connections: typeof ServerConnections }) => {
|
||||
const App = ({ history }: { history: History }) => {
|
||||
return (
|
||||
<ApiProvider connections={connections}>
|
||||
<ApiProvider>
|
||||
<HistoryRouter history={history}>
|
||||
<AppRoutes />
|
||||
</HistoryRouter>
|
||||
|
|
|
@ -3,14 +3,10 @@ import type { UserDto } from '@jellyfin/sdk/lib/generated-client';
|
|||
import type { ApiClient, Event } from 'jellyfin-apiclient';
|
||||
import React, { createContext, FC, useContext, useEffect, useState } from 'react';
|
||||
|
||||
import type ServerConnections from '../components/ServerConnections';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
import events from '../utils/events';
|
||||
import { toApi } from '../utils/jellyfin-apiclient/compat';
|
||||
|
||||
interface ApiProviderProps {
|
||||
connections: typeof ServerConnections
|
||||
}
|
||||
|
||||
interface JellyfinApiContext {
|
||||
__legacyApiClient__?: ApiClient
|
||||
api?: Api
|
||||
|
@ -20,13 +16,13 @@ interface JellyfinApiContext {
|
|||
export const ApiContext = createContext<JellyfinApiContext>({});
|
||||
export const useApi = () => useContext(ApiContext);
|
||||
|
||||
export const ApiProvider: FC<ApiProviderProps> = ({ connections, children }) => {
|
||||
export const ApiProvider: FC = ({ children }) => {
|
||||
const [ legacyApiClient, setLegacyApiClient ] = useState<ApiClient>();
|
||||
const [ api, setApi ] = useState<Api>();
|
||||
const [ user, setUser ] = useState<UserDto>();
|
||||
|
||||
useEffect(() => {
|
||||
connections.currentApiClient()
|
||||
ServerConnections.currentApiClient()
|
||||
.getCurrentUser()
|
||||
.then(newUser => updateApiUser(undefined, newUser))
|
||||
.catch(err => {
|
||||
|
@ -37,7 +33,7 @@ export const ApiProvider: FC<ApiProviderProps> = ({ connections, children }) =>
|
|||
setUser(newUser);
|
||||
|
||||
if (newUser.ServerId) {
|
||||
setLegacyApiClient(connections.getApiClient(newUser.ServerId));
|
||||
setLegacyApiClient(ServerConnections.getApiClient(newUser.ServerId));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -46,14 +42,14 @@ export const ApiProvider: FC<ApiProviderProps> = ({ connections, children }) =>
|
|||
setUser(undefined);
|
||||
};
|
||||
|
||||
events.on(connections, 'localusersignedin', updateApiUser);
|
||||
events.on(connections, 'localusersignedout', resetApiUser);
|
||||
events.on(ServerConnections, 'localusersignedin', updateApiUser);
|
||||
events.on(ServerConnections, 'localusersignedout', resetApiUser);
|
||||
|
||||
return () => {
|
||||
events.off(connections, 'localusersignedin', updateApiUser);
|
||||
events.off(connections, 'localusersignedout', resetApiUser);
|
||||
events.off(ServerConnections, 'localusersignedin', updateApiUser);
|
||||
events.off(ServerConnections, 'localusersignedout', resetApiUser);
|
||||
};
|
||||
}, [ connections, setLegacyApiClient, setUser ]);
|
||||
}, [ setLegacyApiClient, setUser ]);
|
||||
|
||||
useEffect(() => {
|
||||
setApi(legacyApiClient ? toApi(legacyApiClient) : undefined);
|
||||
|
|
|
@ -145,7 +145,7 @@ async function onAppReady() {
|
|||
|
||||
ReactDOM.render(
|
||||
<StrictMode>
|
||||
<App connections={ServerConnections} history={history} />
|
||||
<App history={history} />
|
||||
</StrictMode>,
|
||||
document.getElementById('reactRoot')
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue