mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Remove global ApiClient reference
This commit is contained in:
parent
adb22abdc2
commit
d52c56eb2e
2 changed files with 27 additions and 11 deletions
|
@ -17,6 +17,7 @@ import CheckBoxElement from '../../../../elements/CheckBoxElement';
|
||||||
import SelectElement from '../../../../elements/SelectElement';
|
import SelectElement from '../../../../elements/SelectElement';
|
||||||
import Page from '../../../../components/Page';
|
import Page from '../../../../components/Page';
|
||||||
import prompt from '../../../../components/prompt/prompt';
|
import prompt from '../../../../components/prompt/prompt';
|
||||||
|
import ServerConnections from 'components/ServerConnections';
|
||||||
|
|
||||||
type UnratedItem = {
|
type UnratedItem = {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -487,23 +488,26 @@ const UserParentalControl: FunctionComponent = () => {
|
||||||
|
|
||||||
function handleSaveUser(page: HTMLDivElement, getSchedulesFromPage: () => AccessSchedule[], getAllowedTagsFromPage: () => string[], getBlockedTagsFromPage: () => string[], onSaveComplete: () => void) {
|
function handleSaveUser(page: HTMLDivElement, getSchedulesFromPage: () => AccessSchedule[], getAllowedTagsFromPage: () => string[], getBlockedTagsFromPage: () => string[], onSaveComplete: () => void) {
|
||||||
return (user: UserDto) => {
|
return (user: UserDto) => {
|
||||||
if (!user.Id || !user.Policy) {
|
const userId = user.Id;
|
||||||
|
const userPolicy = user.Policy;
|
||||||
|
if (!userId || !userPolicy) {
|
||||||
throw new Error('Unexpected null user id or policy');
|
throw new Error('Unexpected null user id or policy');
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentalRating = parseInt((page.querySelector('#selectMaxParentalRating') as HTMLSelectElement).value, 10);
|
const parentalRating = parseInt((page.querySelector('#selectMaxParentalRating') as HTMLSelectElement).value, 10);
|
||||||
user.Policy.MaxParentalRating = Number.isNaN(parentalRating) ? null : parentalRating;
|
userPolicy.MaxParentalRating = Number.isNaN(parentalRating) ? null : parentalRating;
|
||||||
user.Policy.BlockUnratedItems = Array.prototype.filter.call(page.querySelectorAll('.chkUnratedItem'), function (i) {
|
userPolicy.BlockUnratedItems = Array.prototype.filter.call(page.querySelectorAll('.chkUnratedItem'), function (i) {
|
||||||
return i.checked;
|
return i.checked;
|
||||||
}).map(function (i) {
|
}).map(function (i) {
|
||||||
return i.getAttribute('data-itemtype');
|
return i.getAttribute('data-itemtype');
|
||||||
});
|
});
|
||||||
user.Policy.AccessSchedules = getSchedulesFromPage();
|
userPolicy.AccessSchedules = getSchedulesFromPage();
|
||||||
user.Policy.AllowedTags = getAllowedTagsFromPage();
|
userPolicy.AllowedTags = getAllowedTagsFromPage();
|
||||||
user.Policy.BlockedTags = getBlockedTagsFromPage();
|
userPolicy.BlockedTags = getBlockedTagsFromPage();
|
||||||
window.ApiClient.updateUserPolicy(user.Id, user.Policy).then(function () {
|
ServerConnections.getCurrentApiClientAsync()
|
||||||
onSaveComplete();
|
.then(apiClient => apiClient.updateUserPolicy(userId, userPolicy))
|
||||||
}).catch(err => {
|
.then(() => onSaveComplete())
|
||||||
|
.catch(err => {
|
||||||
console.error('[userparentalcontrol] failed to update user policy', err);
|
console.error('[userparentalcontrol] failed to update user policy', err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -104,6 +104,18 @@ class ServerConnections extends ConnectionManager {
|
||||||
return apiClient;
|
return apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ApiClient that is currently connected or throws if not defined.
|
||||||
|
* @async
|
||||||
|
* @returns {Promise<ApiClient>} The current ApiClient instance.
|
||||||
|
*/
|
||||||
|
async getCurrentApiClientAsync() {
|
||||||
|
const apiClient = this.currentApiClient();
|
||||||
|
if (!apiClient) throw new Error('[ServerConnection] No current ApiClient instance');
|
||||||
|
|
||||||
|
return apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
onLocalUserSignedIn(user) {
|
onLocalUserSignedIn(user) {
|
||||||
const apiClient = this.getApiClient(user.ServerId);
|
const apiClient = this.getApiClient(user.ServerId);
|
||||||
this.setLocalApiClient(apiClient);
|
this.setLocalApiClient(apiClient);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue