diff --git a/frontend/src/components/InputConfig.tsx b/frontend/src/components/InputConfig.tsx new file mode 100644 index 00000000..ff093fa9 --- /dev/null +++ b/frontend/src/components/InputConfig.tsx @@ -0,0 +1,47 @@ +type InputTextProps = { + type: 'text' | 'number'; + name: string; + value: string | number | null; + setValue: + | React.Dispatch> + | React.Dispatch>; + oldValue: string | number | undefined; + updateCallback: (arg0: string, arg1: string | number | null) => void; +}; + +const InputConfig = ({ type, name, value, setValue, oldValue, updateCallback }: InputTextProps) => { + const handleChange = (e: React.ChangeEvent) => { + if (type === 'number') { + const inputValue = e.target.value; + + if (inputValue === '') { + setValue(null); + } else { + const numericValue = Number(inputValue); + (setValue as React.Dispatch>)(numericValue); + } + } else { + (setValue as React.Dispatch>)(e.target.value); + } + }; + + return ( +
+ +
+ {value !== null && value !== oldValue && ( + <> + + {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */} + + + )} + {oldValue !== undefined && ( + + )} +
+
+ ); +}; + +export default InputConfig; diff --git a/frontend/src/pages/ChannelAbout.tsx b/frontend/src/pages/ChannelAbout.tsx index 19e07451..e9c6460f 100644 --- a/frontend/src/pages/ChannelAbout.tsx +++ b/frontend/src/pages/ChannelAbout.tsx @@ -13,6 +13,7 @@ import FormattedNumber from '../components/FormattedNumber'; import Button from '../components/Button'; import updateChannelOverwrites from '../api/actions/updateChannelOverwrite'; import useIsAdmin from '../functions/useIsAdmin'; +import InputConfig from '../components/InputConfig'; export type ChannelBaseOutletContextType = { currentPage: number; @@ -43,7 +44,7 @@ const ChannelAbout = () => { const [channelResponse, setChannelResponse] = useState(); - const [downloadFormat, setDownloadFormat] = useState(''); + const [downloadFormat, setDownloadFormat] = useState(null); const [autoDeleteAfter, setAutoDeleteAfter] = useState(null); const [indexPlaylists, setIndexPlaylists] = useState(false); const [enableSponsorblock, setEnableSponsorblock] = useState(null); @@ -59,7 +60,7 @@ const ChannelAbout = () => { const channelResponse = await loadChannelById(channelId); setChannelResponse(channelResponse); - setDownloadFormat(channelResponse?.data?.channel_overwrites?.download_format || ''); + setDownloadFormat(channelResponse?.data?.channel_overwrites?.download_format || null); setAutoDeleteAfter(channelResponse?.data?.channel_overwrites?.autodelete_days); setIndexPlaylists(channelResponse?.data?.channel_overwrites?.index_playlists || false); setEnableSponsorblock(channelResponse?.data?.channel_overwrites?.integrate_sponsorblock); @@ -85,19 +86,6 @@ const ChannelAbout = () => { setRefresh(true); }; - const handleNumberChange = - (setValue: React.Dispatch>) => - (e: React.ChangeEvent) => { - const inputValue = e.target.value; - - if (inputValue === '') { - setValue(null); - } else { - const numericValue = Number(inputValue); - setValue(isNaN(numericValue) ? null : numericValue); - } - }; - const handleToggleSponsorBlock = async (isEnabled: boolean) => { if (isEnabled) { setEnableSponsorblock(true); @@ -251,79 +239,27 @@ const ChannelAbout = () => {

Download Format

-
- { - setDownloadFormat(event.target.value); - }} - /> -
- {downloadFormat && - downloadFormat !== channel.channel_overwrites?.download_format && ( - <> - - - - )} - {channel.channel_overwrites?.download_format !== undefined && ( - - )} -
-
+

Auto delete watched videos after x days

-
- -
- {autoDeleteAfter !== null && - autoDeleteAfter !== channel.channel_overwrites?.autodelete_days && ( - <> - - - - )} - {channel.channel_overwrites?.autodelete_days !== undefined && ( - - )} -
-
+
@@ -404,139 +340,40 @@ const ChannelAbout = () => {

Videos page size

-
- -
- {pageSizeVideo !== null && - pageSizeVideo !== channel.channel_overwrites?.subscriptions_channel_size && ( - <> - - - - )} - {channel.channel_overwrites?.subscriptions_channel_size !== undefined && ( - - )} -
-
+

Shorts page size

-
- -
- {pageSizeShorts !== null && - pageSizeShorts !== - channel.channel_overwrites?.subscriptions_shorts_channel_size && ( - <> - - - - )} - {channel.channel_overwrites?.subscriptions_shorts_channel_size !== - undefined && ( - - )} -
-
+

Live streams page size

-
- -
- {pageSizeStreams !== null && - pageSizeStreams !== - channel.channel_overwrites?.subscriptions_live_channel_size && ( - <> - - - - )} - {channel.channel_overwrites?.subscriptions_live_channel_size !== undefined && ( - - )} -
-
+
diff --git a/frontend/src/style.css b/frontend/src/style.css index 9e4f4f58..b13c8fba 100644 --- a/frontend/src/style.css +++ b/frontend/src/style.css @@ -131,7 +131,6 @@ button:hover { padding: 5px 0; display: inline-flex; gap: 5px; - width: 100%; } .unsubscribe {