diff --git a/src/App.tsx b/src/App.tsx index 9f5552554e..79828b6bd0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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 ( - + diff --git a/src/hooks/useApi.tsx b/src/hooks/useApi.tsx index 1e17efcc14..409b40875f 100644 --- a/src/hooks/useApi.tsx +++ b/src/hooks/useApi.tsx @@ -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({}); export const useApi = () => useContext(ApiContext); -export const ApiProvider: FC = ({ connections, children }) => { +export const ApiProvider: FC = ({ children }) => { const [ legacyApiClient, setLegacyApiClient ] = useState(); const [ api, setApi ] = useState(); const [ user, setUser ] = useState(); useEffect(() => { - connections.currentApiClient() + ServerConnections.currentApiClient() .getCurrentUser() .then(newUser => updateApiUser(undefined, newUser)) .catch(err => { @@ -37,7 +33,7 @@ export const ApiProvider: FC = ({ 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 = ({ 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); diff --git a/src/index.jsx b/src/index.jsx index 15d6b48d11..b0de802d59 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -145,7 +145,7 @@ async function onAppReady() { ReactDOM.render( - + , document.getElementById('reactRoot') );