mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Update to React 18
This commit is contained in:
parent
b5d6e37fb3
commit
be891c3a98
36 changed files with 339 additions and 311 deletions
|
@ -1,6 +1,6 @@
|
|||
import type { AccessSchedule, ParentalRating, UserDto } from '@jellyfin/sdk/lib/generated-client';
|
||||
import { UnratedItem, type AccessSchedule, type ParentalRating, type UserDto } from '@jellyfin/sdk/lib/generated-client';
|
||||
import { DynamicDayOfWeek } from '@jellyfin/sdk/lib/generated-client/models/dynamic-day-of-week';
|
||||
import React, { FunctionComponent, useCallback, useEffect, useState, useRef } from 'react';
|
||||
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
||||
import escapeHTML from 'escape-html';
|
||||
|
||||
import globalize from '../../../../scripts/globalize';
|
||||
|
@ -19,9 +19,12 @@ import Page from '../../../../components/Page';
|
|||
import prompt from '../../../../components/prompt/prompt';
|
||||
import ServerConnections from 'components/ServerConnections';
|
||||
|
||||
type UnratedItem = {
|
||||
type ItemArr = {
|
||||
name: string;
|
||||
value: string;
|
||||
value: UnratedItem;
|
||||
};
|
||||
|
||||
type UnratedItemArr = ItemArr & {
|
||||
checkedAttribute: string
|
||||
};
|
||||
|
||||
|
@ -56,17 +59,17 @@ function handleSaveUser(
|
|||
};
|
||||
}
|
||||
|
||||
const UserParentalControl: FunctionComponent = () => {
|
||||
const UserParentalControl = () => {
|
||||
const [ userName, setUserName ] = useState('');
|
||||
const [ parentalRatings, setParentalRatings ] = useState<ParentalRating[]>([]);
|
||||
const [ unratedItems, setUnratedItems ] = useState<UnratedItem[]>([]);
|
||||
const [ unratedItems, setUnratedItems ] = useState<UnratedItemArr[]>([]);
|
||||
const [ accessSchedules, setAccessSchedules ] = useState<AccessSchedule[]>([]);
|
||||
const [ allowedTags, setAllowedTags ] = useState<string[]>([]);
|
||||
const [ blockedTags, setBlockedTags ] = useState<string[]>([]);
|
||||
|
||||
const element = useRef<HTMLDivElement>(null);
|
||||
|
||||
const populateRatings = useCallback((allParentalRatings) => {
|
||||
const populateRatings = useCallback((allParentalRatings: ParentalRating[]) => {
|
||||
let rating;
|
||||
const ratings: ParentalRating[] = [];
|
||||
|
||||
|
@ -91,7 +94,7 @@ const UserParentalControl: FunctionComponent = () => {
|
|||
setParentalRatings(ratings);
|
||||
}, []);
|
||||
|
||||
const loadUnratedItems = useCallback((user) => {
|
||||
const loadUnratedItems = useCallback((user: UserDto) => {
|
||||
const page = element.current;
|
||||
|
||||
if (!page) {
|
||||
|
@ -99,33 +102,33 @@ const UserParentalControl: FunctionComponent = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const items = [{
|
||||
const items: ItemArr[] = [{
|
||||
name: globalize.translate('Books'),
|
||||
value: 'Book'
|
||||
value: UnratedItem.Book
|
||||
}, {
|
||||
name: globalize.translate('Channels'),
|
||||
value: 'ChannelContent'
|
||||
value: UnratedItem.ChannelContent
|
||||
}, {
|
||||
name: globalize.translate('LiveTV'),
|
||||
value: 'LiveTvChannel'
|
||||
value: UnratedItem.LiveTvChannel
|
||||
}, {
|
||||
name: globalize.translate('Movies'),
|
||||
value: 'Movie'
|
||||
value: UnratedItem.Movie
|
||||
}, {
|
||||
name: globalize.translate('Music'),
|
||||
value: 'Music'
|
||||
value: UnratedItem.Music
|
||||
}, {
|
||||
name: globalize.translate('Trailers'),
|
||||
value: 'Trailer'
|
||||
value: UnratedItem.Trailer
|
||||
}, {
|
||||
name: globalize.translate('Shows'),
|
||||
value: 'Series'
|
||||
value: UnratedItem.Series
|
||||
}];
|
||||
|
||||
const itemsArr: UnratedItem[] = [];
|
||||
const itemsArr: UnratedItemArr[] = [];
|
||||
|
||||
for (const item of items) {
|
||||
const isChecked = user.Policy.BlockUnratedItems.indexOf(item.value) != -1;
|
||||
const isChecked = user.Policy?.BlockUnratedItems?.indexOf(item.value) != -1;
|
||||
const checkedAttribute = isChecked ? ' checked="checked"' : '';
|
||||
itemsArr.push({
|
||||
value: item.value,
|
||||
|
@ -182,7 +185,7 @@ const UserParentalControl: FunctionComponent = () => {
|
|||
}
|
||||
}, []);
|
||||
|
||||
const renderAccessSchedule = useCallback((schedules) => {
|
||||
const renderAccessSchedule = useCallback((schedules: AccessSchedule[]) => {
|
||||
const page = element.current;
|
||||
|
||||
if (!page) {
|
||||
|
@ -198,7 +201,7 @@ const UserParentalControl: FunctionComponent = () => {
|
|||
btnDelete.addEventListener('click', function () {
|
||||
const index = parseInt(btnDelete.getAttribute('data-index') ?? '0', 10);
|
||||
schedules.splice(index, 1);
|
||||
const newindex = schedules.filter((i: number) => i != index);
|
||||
const newindex = schedules.filter((_, i) => i != index);
|
||||
renderAccessSchedule(newindex);
|
||||
});
|
||||
}
|
||||
|
@ -229,7 +232,7 @@ const UserParentalControl: FunctionComponent = () => {
|
|||
});
|
||||
}
|
||||
|
||||
(page.querySelector('#selectMaxParentalRating') as HTMLSelectElement).value = ratingValue;
|
||||
(page.querySelector('#selectMaxParentalRating') as HTMLSelectElement).value = String(ratingValue);
|
||||
|
||||
if (user.Policy?.IsAdministrator) {
|
||||
(page.querySelector('.accessScheduleSection') as HTMLDivElement).classList.add('hide');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue