Fix implicit any TypeScript error

This commit is contained in:
Dmitry Lyzo 2022-02-18 14:27:39 +03:00
parent e30a252c8a
commit 57895e724c
23 changed files with 72 additions and 48 deletions

View file

@ -114,7 +114,7 @@ const NewUserPage: FunctionComponent = () => {
});
};
const onSubmit = (e) => {
const onSubmit = (e: Event) => {
loading.show();
saveUser();
e.preventDefault();

View file

@ -1,3 +1,4 @@
import { UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent, useCallback, useEffect, useState, useRef } from 'react';
import Dashboard from '../../scripts/clientUtils';
import globalize from '../../scripts/globalize';
@ -32,7 +33,7 @@ const UserEditPage: FunctionComponent = () => {
const element = useRef(null);
const triggerChange = (select) => {
const triggerChange = (select: HTMLInputElement) => {
const evt = document.createEvent('HTMLEvents');
evt.initEvent('change', false, true);
select.dispatchEvent(evt);
@ -163,7 +164,15 @@ const UserEditPage: FunctionComponent = () => {
toast(globalize.translate('SettingsSaved'));
}
const saveUser = (user) => {
const saveUser = (user: UserDto) => {
if (!user.Id) {
throw new Error('Unexpected null user.Id');
}
if (!user.Policy) {
throw new Error('Unexpected null user.Policy');
}
user.Name = element?.current?.querySelector('#txtUserName').value;
user.Policy.IsAdministrator = element?.current?.querySelector('.chkIsAdmin').checked;
user.Policy.IsHidden = element?.current?.querySelector('.chkIsHidden').checked;
@ -200,7 +209,7 @@ const UserEditPage: FunctionComponent = () => {
});
};
const onSubmit = (e) => {
const onSubmit = (e: Event) => {
loading.show();
getUser().then(function (result) {
saveUser(result);

View file

@ -1,3 +1,4 @@
import { UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent, useCallback, useEffect, useState, useRef } from 'react';
import loading from '../loading/loading';
@ -26,7 +27,7 @@ const UserLibraryAccessPage: FunctionComponent = () => {
const element = useRef(null);
const triggerChange = (select) => {
const triggerChange = (select: HTMLInputElement) => {
const evt = document.createEvent('HTMLEvents');
evt.initEvent('change', false, true);
select.dispatchEvent(evt);
@ -131,7 +132,7 @@ const UserLibraryAccessPage: FunctionComponent = () => {
useEffect(() => {
loadData();
const onSubmit = (e) => {
const onSubmit = (e: Event) => {
loading.show();
const userId = appRouter.param('userId');
window.ApiClient.getUser(userId).then(function (result) {
@ -142,7 +143,15 @@ const UserLibraryAccessPage: FunctionComponent = () => {
return false;
};
const saveUser = (user) => {
const saveUser = (user: UserDto) => {
if (!user.Id) {
throw new Error('Unexpected null user.Id');
}
if (!user.Policy) {
throw new Error('Unexpected null user.Policy');
}
user.Policy.EnableAllFolders = element?.current?.querySelector('.chkEnableAllFolders').checked;
user.Policy.EnabledFolders = user.Policy.EnableAllFolders ? [] : Array.prototype.filter.call(element?.current?.querySelectorAll('.chkFolder'), function (c) {
return c.checked;

View file

@ -1,3 +1,4 @@
import { AccessSchedule, UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent, useCallback, useEffect, useState, useRef } from 'react';
import globalize from '../../scripts/globalize';
import LibraryMenu from '../../scripts/libraryMenu';
@ -108,7 +109,7 @@ const UserParentalControl: FunctionComponent = () => {
for (const btnDeleteTag of blockedTagsElem.querySelectorAll('.btnDeleteTag')) {
btnDeleteTag.addEventListener('click', function () {
const tag = btnDeleteTag.getAttribute('data-tag');
const newTags = tags.filter(function (t) {
const newTags = tags.filter(function (t: string) {
return t != tag;
});
loadBlockedTags(newTags);
@ -125,7 +126,7 @@ const UserParentalControl: FunctionComponent = () => {
btnDelete.addEventListener('click', function () {
const index = parseInt(btnDelete.getAttribute('data-index'));
schedules.splice(index, 1);
const newindex = schedules.filter(function (i) {
const newindex = schedules.filter(function (i: number) {
return i != index;
});
renderAccessSchedule(newindex);
@ -181,7 +182,15 @@ const UserParentalControl: FunctionComponent = () => {
toast(globalize.translate('SettingsSaved'));
};
const saveUser = (user) => {
const saveUser = (user: UserDto) => {
if (!user.Id) {
throw new Error('Unexpected null user.Id');
}
if (!user.Policy) {
throw new Error('Unexpected null user.Policy');
}
user.Policy.MaxParentalRating = element?.current?.querySelector('.selectMaxParentalRating').value || null;
user.Policy.BlockUnratedItems = Array.prototype.filter.call(element?.current?.querySelectorAll('.chkUnratedItem'), function (i) {
return i.checked;
@ -195,7 +204,7 @@ const UserParentalControl: FunctionComponent = () => {
});
};
const showSchedulePopup = (schedule, index) => {
const showSchedulePopup = (schedule: AccessSchedule, index: number) => {
schedule = schedule || {};
import('../../components/accessSchedule/accessSchedule').then(({default: accessschedule}) => {
accessschedule.show({
@ -244,7 +253,7 @@ const UserParentalControl: FunctionComponent = () => {
});
};
const onSubmit = (e) => {
const onSubmit = (e: Event) => {
loading.show();
const userId = appRouter.param('userId');
window.ApiClient.getUser(userId).then(function (result) {

View file

@ -36,7 +36,7 @@ const UserProfilesPage: FunctionComponent = () => {
useEffect(() => {
loadData();
const showUserMenu = (elem) => {
const showUserMenu = (elem: HTMLElement) => {
const card = dom.parentWithClass(elem, 'card');
const userId = card.getAttribute('data-userid');
@ -67,7 +67,7 @@ const UserProfilesPage: FunctionComponent = () => {
actionsheet.show({
items: menuItems,
positionTo: card,
callback: function (id) {
callback: function (id: string) {
switch (id) {
case 'open':
Dashboard.navigate('useredit.html?userId=' + userId);
@ -89,7 +89,7 @@ const UserProfilesPage: FunctionComponent = () => {
});
};
const deleteUser = (id) => {
const deleteUser = (id: string) => {
const msg = globalize.translate('DeleteUserConfirmation');
confirm({