mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix complexity warnings in UserPasswordForm
This commit is contained in:
parent
448e3b1b86
commit
a6c8c63d2e
1 changed files with 33 additions and 47 deletions
|
@ -1,4 +1,3 @@
|
|||
import type { UserDto } from '@jellyfin/sdk/lib/generated-client';
|
||||
import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react';
|
||||
import Dashboard from '../../../utils/dashboard';
|
||||
import globalize from '../../../scripts/globalize';
|
||||
|
@ -17,7 +16,7 @@ type IProps = {
|
|||
const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
|
||||
const element = useRef<HTMLDivElement>(null);
|
||||
|
||||
const loadUser = useCallback(() => {
|
||||
const loadUser = useCallback(async () => {
|
||||
const page = element.current;
|
||||
|
||||
if (!page) {
|
||||
|
@ -25,14 +24,11 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
|
|||
return;
|
||||
}
|
||||
|
||||
window.ApiClient.getUser(userId).then(function (user) {
|
||||
Dashboard.getCurrentUser().then(function (loggedInUser: UserDto) {
|
||||
if (!user.Policy) {
|
||||
throw new Error('Unexpected null user.Policy');
|
||||
}
|
||||
const user = await window.ApiClient.getUser(userId);
|
||||
const loggedInUser = await Dashboard.getCurrentUser();
|
||||
|
||||
if (!user.Configuration) {
|
||||
throw new Error('Unexpected null user.Configuration');
|
||||
if (!user.Policy || !user.Configuration) {
|
||||
throw new Error('Unexpected null user policy or configuration');
|
||||
}
|
||||
|
||||
LibraryMenu.setTitle(user.Name);
|
||||
|
@ -48,17 +44,9 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
|
|||
(page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide');
|
||||
}
|
||||
|
||||
if (loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess) {
|
||||
(page.querySelector('.passwordSection') as HTMLDivElement).classList.remove('hide');
|
||||
} else {
|
||||
(page.querySelector('.passwordSection') as HTMLDivElement).classList.add('hide');
|
||||
}
|
||||
|
||||
if (showLocalAccessSection && (loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess)) {
|
||||
(page.querySelector('.localAccessSection') as HTMLDivElement).classList.remove('hide');
|
||||
} else {
|
||||
(page.querySelector('.localAccessSection') as HTMLDivElement).classList.add('hide');
|
||||
}
|
||||
const canChangePassword = loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess;
|
||||
(page.querySelector('.passwordSection') as HTMLDivElement).classList.toggle('hide', !canChangePassword);
|
||||
(page.querySelector('.localAccessSection') as HTMLDivElement).classList.toggle('hide', !(showLocalAccessSection && canChangePassword));
|
||||
|
||||
const txtEasyPassword = page.querySelector('#txtEasyPassword') as HTMLInputElement;
|
||||
txtEasyPassword.value = '';
|
||||
|
@ -79,8 +67,6 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
|
|||
import('../../autoFocuser').then(({ default: autoFocuser }) => {
|
||||
autoFocuser.autoFocus(page);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
(page.querySelector('#txtCurrentPassword') as HTMLInputElement).value = '';
|
||||
(page.querySelector('#txtNewPassword') as HTMLInputElement).value = '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue