({});
+export const useApi = () => useContext(ApiContext);
+
+export const ApiProvider: FC = ({ children }) => {
+ const [ legacyApiClient, setLegacyApiClient ] = useState
();
+ const [ api, setApi ] = useState();
+ const [ user, setUser ] = useState();
+
+ useEffect(() => {
+ ServerConnections.currentApiClient()
+ ?.getCurrentUser()
+ .then(newUser => updateApiUser(undefined, newUser))
+ .catch(err => {
+ console.info('[ApiProvider] Could not get current user', err);
+ });
+
+ const updateApiUser = (_e: Event | undefined, newUser: UserDto) => {
+ setUser(newUser);
+
+ if (newUser.ServerId) {
+ setLegacyApiClient(ServerConnections.getApiClient(newUser.ServerId));
+ }
+ };
+
+ const resetApiUser = () => {
+ setLegacyApiClient(undefined);
+ setUser(undefined);
+ };
+
+ events.on(ServerConnections, 'localusersignedin', updateApiUser);
+ events.on(ServerConnections, 'localusersignedout', resetApiUser);
+
+ return () => {
+ events.off(ServerConnections, 'localusersignedin', updateApiUser);
+ events.off(ServerConnections, 'localusersignedout', resetApiUser);
+ };
+ }, [ setLegacyApiClient, setUser ]);
+
+ useEffect(() => {
+ setApi(legacyApiClient ? toApi(legacyApiClient) : undefined);
+ }, [ legacyApiClient, setApi ]);
+
+ return (
+
+ {children}
+
+ );
+};
diff --git a/src/index.jsx b/src/index.jsx
index 2c786b736..b0de802d5 100644
--- a/src/index.jsx
+++ b/src/index.jsx
@@ -37,8 +37,7 @@ import './legacy/htmlMediaElement';
import './legacy/vendorStyles';
import { currentSettings } from './scripts/settings/userSettings';
import taskButton from './scripts/taskbutton';
-import { HistoryRouter } from './components/HistoryRouter.tsx';
-import AppRoutes from './routes/index.tsx';
+import App from './App.tsx';
function loadCoreDictionary() {
const languages = ['af', 'ar', 'be-by', 'bg-bg', 'bn_bd', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en-gb', 'en-us', 'eo', 'es', 'es-419', 'es-ar', 'es_do', 'es-mx', 'et', 'eu', 'fa', 'fi', 'fil', 'fr', 'fr-ca', 'gl', 'gsw', 'he', 'hi-in', 'hr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt-lt', 'lv', 'mr', 'ms', 'nb', 'nl', 'nn', 'pl', 'pr', 'pt', 'pt-br', 'pt-pt', 'ro', 'ru', 'sk', 'sl-si', 'sq', 'sv', 'ta', 'th', 'tr', 'uk', 'ur_pk', 'vi', 'zh-cn', 'zh-hk', 'zh-tw'];
@@ -146,9 +145,7 @@ async function onAppReady() {
ReactDOM.render(
-
-
-
+
,
document.getElementById('reactRoot')
);
diff --git a/src/plugins/syncPlay/core/Manager.js b/src/plugins/syncPlay/core/Manager.js
index af39d422d..740e0709d 100644
--- a/src/plugins/syncPlay/core/Manager.js
+++ b/src/plugins/syncPlay/core/Manager.js
@@ -71,7 +71,7 @@ class Manager {
/**
* Update active ApiClient.
- * @param {Object} apiClient The ApiClient.
+ * @param {ApiClient|undefined} apiClient The ApiClient.
*/
updateApiClient(apiClient) {
if (!apiClient) {
diff --git a/src/routes/search.tsx b/src/routes/search.tsx
index 059a81783..d154018b4 100644
--- a/src/routes/search.tsx
+++ b/src/routes/search.tsx
@@ -21,7 +21,6 @@ const Search: FunctionComponent = () => {
{!query &&
}
diff --git a/src/utils/jellyfin-apiclient/compat.ts b/src/utils/jellyfin-apiclient/compat.ts
new file mode 100644
index 000000000..444dbee45
--- /dev/null
+++ b/src/utils/jellyfin-apiclient/compat.ts
@@ -0,0 +1,23 @@
+import { Api, Jellyfin } from '@jellyfin/sdk';
+import { ApiClient } from 'jellyfin-apiclient';
+
+/**
+ * Returns an SDK Api instance using the same parameters as the provided ApiClient.
+ * @param {ApiClient} apiClient The (legacy) ApiClient.
+ * @returns {Api} An equivalent SDK Api instance.
+ */
+export const toApi = (apiClient: ApiClient): Api => {
+ return (new Jellyfin({
+ clientInfo: {
+ name: apiClient.appName(),
+ version: apiClient.appVersion()
+ },
+ deviceInfo: {
+ name: apiClient.deviceName(),
+ id: apiClient.deviceId()
+ }
+ })).createApi(
+ apiClient.serverAddress(),
+ apiClient.accessToken()
+ );
+};
diff --git a/webpack.common.js b/webpack.common.js
index 4c15134b5..2548961b8 100644
--- a/webpack.common.js
+++ b/webpack.common.js
@@ -146,7 +146,7 @@ const config = {
},
{
test: /\.(js|jsx)$/,
- exclude: /node_modules[\\/](?!@uupaa[\\/]dynamic-import-polyfill|@remix-run[\\/]router|blurhash|date-fns|dom7|epubjs|flv.js|libarchive.js|marked|react-router|screenfull|ssr-window|swiper)/,
+ exclude: /node_modules[\\/](?!@uupaa[\\/]dynamic-import-polyfill|@remix-run[\\/]router|blurhash|compare-versions|date-fns|dom7|epubjs|flv.js|libarchive.js|marked|react-router|screenfull|ssr-window|swiper)/,
use: [{
loader: 'babel-loader',
options: {