From cbb365833112c569c48f7e41090f49ce50b5eaea Mon Sep 17 00:00:00 2001 From: David Stensland Date: Sun, 25 Feb 2024 15:45:18 -0800 Subject: [PATCH 1/2] use emby-input/Input instead of InputElement --- src/apps/dashboard/routes/users/add.tsx | 12 +-- src/apps/dashboard/routes/users/profile.tsx | 29 ++++---- src/apps/stable/routes/quickConnect/index.tsx | 35 +++++---- .../dashboard/users/UserPasswordForm.tsx | 20 ++--- src/elements/InputElement.tsx | 74 ------------------- 5 files changed, 51 insertions(+), 119 deletions(-) delete mode 100644 src/elements/InputElement.tsx diff --git a/src/apps/dashboard/routes/users/add.tsx b/src/apps/dashboard/routes/users/add.tsx index ffb8d3dc0..c2ad8df5e 100644 --- a/src/apps/dashboard/routes/users/add.tsx +++ b/src/apps/dashboard/routes/users/add.tsx @@ -6,7 +6,7 @@ import globalize from '../../../../lib/globalize'; import loading from '../../../../components/loading/loading'; import toast from '../../../../components/toast/toast'; import SectionTitleContainer from '../../../../elements/SectionTitleContainer'; -import InputElement from '../../../../elements/InputElement'; +import Input from '../../../../elements/emby-input/Input'; import ButtonElement from '../../../../elements/ButtonElement'; import AccessContainer from '../../../../components/dashboard/users/AccessContainer'; import CheckBoxElement from '../../../../elements/CheckBoxElement'; @@ -194,18 +194,18 @@ const UserNew = () => {
-
-
{
-
@@ -416,11 +416,14 @@ const UserEdit = () => {
-
{globalize.translate('LabelRemoteClientBitrateLimitHelp')} @@ -517,11 +520,11 @@ const UserEdit = () => {
-
{globalize.translate('OptionLoginAttemptsBeforeLockout')} @@ -534,11 +537,11 @@ const UserEdit = () => {
-
{globalize.translate('OptionMaxActiveSessions')} diff --git a/src/apps/stable/routes/quickConnect/index.tsx b/src/apps/stable/routes/quickConnect/index.tsx index a76488d21..5429be9c8 100644 --- a/src/apps/stable/routes/quickConnect/index.tsx +++ b/src/apps/stable/routes/quickConnect/index.tsx @@ -1,10 +1,10 @@ import { getQuickConnectApi } from '@jellyfin/sdk/lib/utils/api/quick-connect-api'; -import React, { FC, FormEvent, useCallback, useMemo, useState } from 'react'; +import React, { FC, FormEvent, useCallback, useState } from 'react'; import { Link, useSearchParams } from 'react-router-dom'; import Page from 'components/Page'; import globalize from 'lib/globalize'; -import InputElement from 'elements/InputElement'; +import Input from 'elements/emby-input/Input'; import ButtonElement from 'elements/ButtonElement'; import { useApi } from 'hooks/useApi'; @@ -13,14 +13,12 @@ import './quickConnect.scss'; const QuickConnectPage: FC = () => { const { api, user } = useApi(); const [ searchParams ] = useSearchParams(); - // eslint-disable-next-line react-hooks/exhaustive-deps - const initialValue = useMemo(() => searchParams.get('code') ?? '', []); - const [ code, setCode ] = useState(initialValue); + const [ code, setCode ] = useState(searchParams.get('code') ?? ''); const [ error, setError ] = useState(); const [ success, setSuccess ] = useState(false); - const onCodeChange = useCallback((value: string) => { - setCode(value); + const onCodeChange = useCallback((event: React.ChangeEvent) => { + setCode(event.currentTarget.value); }, []); const onSubmitCode = useCallback((e: FormEvent) => { @@ -90,15 +88,20 @@ const QuickConnectPage: FC = () => {
) : ( <> - +
+ +
= ({ userId }: IProps) => { >
-
-
-

diff --git a/src/elements/InputElement.tsx b/src/elements/InputElement.tsx deleted file mode 100644 index ae7e757b6..000000000 --- a/src/elements/InputElement.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import React, { type FC, useCallback, useEffect, useMemo, useRef } from 'react'; - -import globalize from 'lib/globalize'; - -interface CreateInputElementParams { - type?: string - id?: string - label?: string - initialValue?: string - options?: string -} - -const createInputElement = ({ type, id, label, initialValue, options }: CreateInputElementParams) => ({ - __html: `` -}); - -type InputElementProps = { - containerClassName?: string - onChange?: (value: string) => void -} & CreateInputElementParams; - -const InputElement: FC = ({ - containerClassName, - initialValue, - onChange = () => { /* no-op */ }, - type, - id, - label, - options = '' -}) => { - const container = useRef(null); - - // NOTE: We need to memoize the input html because any re-render will break the webcomponent - const inputHtml = useMemo(() => ( - createInputElement({ - type, - id, - label: globalize.translate(label), - initialValue, - options - }) - // eslint-disable-next-line react-hooks/exhaustive-deps - ), []); - - const onInput = useCallback((e: Event) => { - onChange((e.target as HTMLInputElement).value); - }, [ onChange ]); - - useEffect(() => { - const inputElement = container?.current?.querySelector('input'); - inputElement?.addEventListener('input', onInput); - - return () => { - inputElement?.removeEventListener('input', onInput); - }; - }, [ container, onInput ]); - - return ( -
- ); -}; - -export default InputElement; From 9d604b5a516bd38e31a309269e85298afda1d327 Mon Sep 17 00:00:00 2001 From: David Stensland Date: Sun, 25 Feb 2024 16:56:14 -0800 Subject: [PATCH 2/2] use emby-button/Button instead of ButtonElement --- src/apps/dashboard/routes/users/access.tsx | 6 +-- src/apps/dashboard/routes/users/add.tsx | 10 ++--- .../routes/users/parentalcontrol.tsx | 6 +-- src/apps/dashboard/routes/users/profile.tsx | 10 ++--- src/apps/stable/routes/quickConnect/index.tsx | 4 +- src/apps/stable/routes/user/userprofile.tsx | 10 ++--- .../dashboard/users/UserPasswordForm.tsx | 10 ++--- src/elements/ButtonElement.tsx | 42 ------------------- 8 files changed, 28 insertions(+), 70 deletions(-) delete mode 100644 src/elements/ButtonElement.tsx diff --git a/src/apps/dashboard/routes/users/access.tsx b/src/apps/dashboard/routes/users/access.tsx index f2394f966..cac8e71f3 100644 --- a/src/apps/dashboard/routes/users/access.tsx +++ b/src/apps/dashboard/routes/users/access.tsx @@ -6,7 +6,7 @@ import loading from '../../../../components/loading/loading'; import globalize from '../../../../lib/globalize'; import toast from '../../../../components/toast/toast'; import SectionTabs from '../../../../components/dashboard/users/SectionTabs'; -import ButtonElement from '../../../../elements/ButtonElement'; +import Button from '../../../../elements/emby-button/Button'; import SectionTitleContainer from '../../../../elements/SectionTitleContainer'; import AccessContainer from '../../../../components/dashboard/users/AccessContainer'; import CheckBoxElement from '../../../../elements/CheckBoxElement'; @@ -316,10 +316,10 @@ const UserLibraryAccess = () => {
-
diff --git a/src/apps/dashboard/routes/users/add.tsx b/src/apps/dashboard/routes/users/add.tsx index c2ad8df5e..f1d105253 100644 --- a/src/apps/dashboard/routes/users/add.tsx +++ b/src/apps/dashboard/routes/users/add.tsx @@ -7,7 +7,7 @@ import loading from '../../../../components/loading/loading'; import toast from '../../../../components/toast/toast'; import SectionTitleContainer from '../../../../elements/SectionTitleContainer'; import Input from '../../../../elements/emby-input/Input'; -import ButtonElement from '../../../../elements/ButtonElement'; +import Button from '../../../../elements/emby-button/Button'; import AccessContainer from '../../../../components/dashboard/users/AccessContainer'; import CheckBoxElement from '../../../../elements/CheckBoxElement'; import Page from '../../../../components/Page'; @@ -248,16 +248,16 @@ const UserNew = () => { ))}
- -
diff --git a/src/apps/dashboard/routes/users/parentalcontrol.tsx b/src/apps/dashboard/routes/users/parentalcontrol.tsx index 116c61522..2e4954259 100644 --- a/src/apps/dashboard/routes/users/parentalcontrol.tsx +++ b/src/apps/dashboard/routes/users/parentalcontrol.tsx @@ -8,7 +8,7 @@ import { useSearchParams } from 'react-router-dom'; import globalize from '../../../../lib/globalize'; import AccessScheduleList from '../../../../components/dashboard/users/AccessScheduleList'; import TagList from '../../../../components/dashboard/users/TagList'; -import ButtonElement from '../../../../elements/ButtonElement'; +import Button from '../../../../elements/emby-button/Button'; import SectionTitleContainer from '../../../../elements/SectionTitleContainer'; import SectionTabs from '../../../../components/dashboard/users/SectionTabs'; import loading from '../../../../components/loading/loading'; @@ -480,10 +480,10 @@ const UserParentalControl = () => {
-
diff --git a/src/apps/dashboard/routes/users/profile.tsx b/src/apps/dashboard/routes/users/profile.tsx index 984f4b858..32556467c 100644 --- a/src/apps/dashboard/routes/users/profile.tsx +++ b/src/apps/dashboard/routes/users/profile.tsx @@ -5,7 +5,7 @@ import { useSearchParams } from 'react-router-dom'; import Dashboard from '../../../../utils/dashboard'; import globalize from '../../../../lib/globalize'; -import ButtonElement from '../../../../elements/ButtonElement'; +import Button from '../../../../elements/emby-button/Button'; import CheckBoxElement from '../../../../elements/CheckBoxElement'; import LinkButton from '../../../../elements/emby-button/LinkButton'; import Input from '../../../../elements/emby-input/Input'; @@ -553,16 +553,16 @@ const UserEdit = () => {

- -
diff --git a/src/apps/stable/routes/quickConnect/index.tsx b/src/apps/stable/routes/quickConnect/index.tsx index 5429be9c8..b4dd7d0b9 100644 --- a/src/apps/stable/routes/quickConnect/index.tsx +++ b/src/apps/stable/routes/quickConnect/index.tsx @@ -5,7 +5,7 @@ import { Link, useSearchParams } from 'react-router-dom'; import Page from 'components/Page'; import globalize from 'lib/globalize'; import Input from 'elements/emby-input/Input'; -import ButtonElement from 'elements/ButtonElement'; +import Button from 'elements/emby-button/Button'; import { useApi } from 'hooks/useApi'; import './quickConnect.scss'; @@ -102,7 +102,7 @@ const QuickConnectPage: FC = () => { autoComplete='off' />
- { {userName}
- -
diff --git a/src/components/dashboard/users/UserPasswordForm.tsx b/src/components/dashboard/users/UserPasswordForm.tsx index 4202e84b4..b6e05e41d 100644 --- a/src/components/dashboard/users/UserPasswordForm.tsx +++ b/src/components/dashboard/users/UserPasswordForm.tsx @@ -5,7 +5,7 @@ import globalize from '../../../lib/globalize'; import confirm from '../../confirm/confirm'; import loading from '../../loading/loading'; import toast from '../../toast/toast'; -import ButtonElement from '../../../elements/ButtonElement'; +import Button from '../../../elements/emby-button/Button'; import Input from '../../../elements/emby-input/Input'; type IProps = { @@ -183,16 +183,16 @@ const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => {

- -
diff --git a/src/elements/ButtonElement.tsx b/src/elements/ButtonElement.tsx deleted file mode 100644 index 379f4f799..000000000 --- a/src/elements/ButtonElement.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React, { FunctionComponent } from 'react'; - -import globalize from 'lib/globalize'; - -const createButtonElement = ({ type, id, className, title, leftIcon, rightIcon }: IProps) => ({ - __html: `` -}); - -type IProps = { - type?: string; - id?: string; - className?: string; - title?: string; - leftIcon?: string; - rightIcon?: string; -}; - -const ButtonElement: FunctionComponent = ({ type, id, className, title, leftIcon, rightIcon }: IProps) => { - return ( -