1
0
Fork 0
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:
Bill Thornton 2023-04-26 15:47:21 -04:00
parent 448e3b1b86
commit a6c8c63d2e

View file

@ -1,4 +1,3 @@
import type { UserDto } from '@jellyfin/sdk/lib/generated-client';
import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react'; import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react';
import Dashboard from '../../../utils/dashboard'; import Dashboard from '../../../utils/dashboard';
import globalize from '../../../scripts/globalize'; import globalize from '../../../scripts/globalize';
@ -17,7 +16,7 @@ type IProps = {
const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => { const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
const element = useRef<HTMLDivElement>(null); const element = useRef<HTMLDivElement>(null);
const loadUser = useCallback(() => { const loadUser = useCallback(async () => {
const page = element.current; const page = element.current;
if (!page) { if (!page) {
@ -25,14 +24,11 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
return; return;
} }
window.ApiClient.getUser(userId).then(function (user) { const user = await window.ApiClient.getUser(userId);
Dashboard.getCurrentUser().then(function (loggedInUser: UserDto) { const loggedInUser = await Dashboard.getCurrentUser();
if (!user.Policy) {
throw new Error('Unexpected null user.Policy');
}
if (!user.Configuration) { if (!user.Policy || !user.Configuration) {
throw new Error('Unexpected null user.Configuration'); throw new Error('Unexpected null user policy or configuration');
} }
LibraryMenu.setTitle(user.Name); LibraryMenu.setTitle(user.Name);
@ -48,17 +44,9 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
(page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide'); (page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide');
} }
if (loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess) { const canChangePassword = loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess;
(page.querySelector('.passwordSection') as HTMLDivElement).classList.remove('hide'); (page.querySelector('.passwordSection') as HTMLDivElement).classList.toggle('hide', !canChangePassword);
} else { (page.querySelector('.localAccessSection') as HTMLDivElement).classList.toggle('hide', !(showLocalAccessSection && canChangePassword));
(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 txtEasyPassword = page.querySelector('#txtEasyPassword') as HTMLInputElement; const txtEasyPassword = page.querySelector('#txtEasyPassword') as HTMLInputElement;
txtEasyPassword.value = ''; txtEasyPassword.value = '';
@ -79,8 +67,6 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
import('../../autoFocuser').then(({ default: autoFocuser }) => { import('../../autoFocuser').then(({ default: autoFocuser }) => {
autoFocuser.autoFocus(page); autoFocuser.autoFocus(page);
}); });
});
});
(page.querySelector('#txtCurrentPassword') as HTMLInputElement).value = ''; (page.querySelector('#txtCurrentPassword') as HTMLInputElement).value = '';
(page.querySelector('#txtNewPassword') as HTMLInputElement).value = ''; (page.querySelector('#txtNewPassword') as HTMLInputElement).value = '';