fix null undefined types

This commit is contained in:
Simon 2025-01-09 23:59:29 +07:00
parent f6b5de00df
commit bf38cdc7f0
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
5 changed files with 534 additions and 520 deletions

View File

@ -2,27 +2,27 @@ import APIClient from '../../functions/APIClient';
export type AppSettingsConfigType = {
subscriptions: {
channel_size: number;
live_channel_size: number;
shorts_channel_size: number;
channel_size: number | null;
live_channel_size: number | null;
shorts_channel_size: number | null;
auto_start: boolean;
};
downloads: {
limit_speed: number | undefined;
sleep_interval: number;
autodelete_days: number;
format: string | undefined;
format_sort: string | undefined;
limit_speed: number | null;
sleep_interval: number | null;
autodelete_days: number | null;
format: string | null;
format_sort: string | null;
add_metadata: boolean;
add_thumbnail: boolean;
subtitle: string | undefined;
subtitle_source: boolean | string;
subtitle: string | null;
subtitle_source: string | null;
subtitle_index: boolean;
comment_max: string | undefined;
comment_max: string | null;
comment_sort: string;
cookie_import: boolean;
throttledratelimit: number | undefined;
extractor_lang: string | undefined;
throttledratelimit: number | null;
extractor_lang: string | null;
integrate_ryd: boolean;
integrate_sponsorblock: boolean;
};

View File

@ -5,7 +5,7 @@ type InputTextProps = {
setValue:
| React.Dispatch<React.SetStateAction<string | null>>
| React.Dispatch<React.SetStateAction<number | null>>;
oldValue: string | number | undefined;
oldValue: string | number | null;
updateCallback: (arg0: string, arg1: string | boolean | number | null) => void;
};
@ -36,9 +36,7 @@ const InputConfig = ({ type, name, value, setValue, oldValue, updateCallback }:
<button onClick={() => setValue(oldValue as any)}>Cancel</button>
</>
)}
{oldValue !== undefined && (
<button onClick={() => updateCallback(name, null)}>reset</button>
)}
{oldValue !== null && <button onClick={() => updateCallback(name, null)}>reset</button>}
</div>
</div>
);

View File

@ -60,16 +60,20 @@ const ChannelAbout = () => {
const channelResponse = await loadChannelById(channelId);
setChannelResponse(channelResponse);
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);
setPageSizeVideo(channelResponse?.data?.channel_overwrites?.subscriptions_channel_size);
setDownloadFormat(channelResponse?.data?.channel_overwrites?.download_format ?? null);
setAutoDeleteAfter(channelResponse?.data?.channel_overwrites?.autodelete_days ?? null);
setIndexPlaylists(channelResponse?.data?.channel_overwrites?.index_playlists ?? null);
setEnableSponsorblock(
channelResponse?.data?.channel_overwrites?.integrate_sponsorblock ?? null,
);
setPageSizeVideo(
channelResponse?.data?.channel_overwrites?.subscriptions_channel_size ?? null,
);
setPageSizeShorts(
channelResponse?.data?.channel_overwrites?.subscriptions_shorts_channel_size,
channelResponse?.data?.channel_overwrites?.subscriptions_shorts_channel_size ?? null,
);
setPageSizeStreams(
channelResponse?.data?.channel_overwrites?.subscriptions_live_channel_size,
channelResponse?.data?.channel_overwrites?.subscriptions_live_channel_size ?? null,
);
setRefresh(false);
@ -244,7 +248,7 @@ const ChannelAbout = () => {
name="download_format"
value={downloadFormat}
setValue={setDownloadFormat}
oldValue={channel.channel_overwrites?.download_format}
oldValue={channel.channel_overwrites?.download_format ?? null}
updateCallback={handleUpdateConfig}
/>
</div>
@ -257,7 +261,7 @@ const ChannelAbout = () => {
name="autodelete_days"
value={autoDeleteAfter}
setValue={setAutoDeleteAfter}
oldValue={channel.channel_overwrites?.autodelete_days}
oldValue={channel.channel_overwrites?.autodelete_days ?? null}
updateCallback={handleUpdateConfig}
/>
</div>
@ -300,7 +304,7 @@ const ChannelAbout = () => {
</p>
</div>
<div>
{enableSponsorblock !== undefined ? (
{enableSponsorblock !== null ? (
<div className="toggle">
<div className="toggleBox">
<input
@ -345,7 +349,7 @@ const ChannelAbout = () => {
name="subscriptions_channel_size"
value={pageSizeVideo}
setValue={setPageSizeVideo}
oldValue={channel.channel_overwrites?.subscriptions_channel_size}
oldValue={channel.channel_overwrites?.subscriptions_channel_size ?? null}
updateCallback={handleUpdateConfig}
/>
</div>
@ -358,7 +362,7 @@ const ChannelAbout = () => {
name="subscriptions_shorts_channel_size"
value={pageSizeShorts}
setValue={setPageSizeShorts}
oldValue={channel.channel_overwrites?.subscriptions_shorts_channel_size}
oldValue={channel.channel_overwrites?.subscriptions_shorts_channel_size ?? null}
updateCallback={handleUpdateConfig}
/>
</div>
@ -371,7 +375,7 @@ const ChannelAbout = () => {
name="subscriptions_live_channel_size"
value={pageSizeStreams}
setValue={setPageSizeStreams}
oldValue={channel.channel_overwrites?.subscriptions_live_channel_size}
oldValue={channel.channel_overwrites?.subscriptions_live_channel_size ?? null}
updateCallback={handleUpdateConfig}
/>
</div>

View File

@ -19,7 +19,7 @@ type ChannelOverwritesType = {
download_format?: string;
autodelete_days?: number;
index_playlists?: boolean;
integrate_sponsorblock?: boolean;
integrate_sponsorblock?: boolean | null;
subscriptions_channel_size?: number;
subscriptions_live_channel_size?: number;
subscriptions_shorts_channel_size?: number;

View File

@ -65,12 +65,12 @@ const SettingsApplication = () => {
// Subtitles
const [subtitleLang, setSubtitleLang] = useState<string | null>(null);
const [subtitleSource, setSubtitleSource] = useState('');
const [subtitleSource, setSubtitleSource] = useState<string | null>(null);
const [indexSubtitles, setIndexSubtitles] = useState(false);
// Comments
const [commentsMax, setCommentsMax] = useState<string | null>(null);
const [commentsSort, setCommentsSort] = useState('');
const [commentsSort, setCommentsSort] = useState<string>('');
// Cookie
// const [cookieImport, setCookieImport] = useState(false);
@ -93,42 +93,42 @@ const SettingsApplication = () => {
const apiToken = await loadApiToken();
// Subscriptions
setVideoPageSize(appSettingsConfig?.subscriptions.channel_size);
setLivePageSize(appSettingsConfig?.subscriptions.live_channel_size);
setShortPageSize(appSettingsConfig?.subscriptions.shorts_channel_size);
setIsAutostart(appSettingsConfig?.subscriptions.auto_start);
setVideoPageSize(appSettingsConfig.subscriptions.channel_size);
setLivePageSize(appSettingsConfig.subscriptions.live_channel_size);
setShortPageSize(appSettingsConfig.subscriptions.shorts_channel_size);
setIsAutostart(appSettingsConfig.subscriptions.auto_start);
// Downloads
setCurrentDownloadSpeed(appSettingsConfig?.downloads.limit_speed || null);
setCurrentThrottledRate(appSettingsConfig?.downloads.throttledratelimit || null);
setCurrentScrapingSleep(appSettingsConfig?.downloads.sleep_interval);
setCurrentAutodelete(appSettingsConfig?.downloads.autodelete_days);
setCurrentDownloadSpeed(appSettingsConfig.downloads.limit_speed);
setCurrentThrottledRate(appSettingsConfig.downloads.throttledratelimit);
setCurrentScrapingSleep(appSettingsConfig.downloads.sleep_interval);
setCurrentAutodelete(appSettingsConfig.downloads.autodelete_days);
// Download Format
setDownloadsFormat(appSettingsConfig?.downloads.format || null);
setDownloadsFormatSort(appSettingsConfig?.downloads.format_sort || null);
setDownloadsExtractorLang(appSettingsConfig?.downloads.extractor_lang || null);
setEmbedMetadata(appSettingsConfig?.downloads.add_metadata);
setEmbedThumbnail(appSettingsConfig?.downloads.add_thumbnail);
setDownloadsFormat(appSettingsConfig.downloads.format);
setDownloadsFormatSort(appSettingsConfig.downloads.format_sort);
setDownloadsExtractorLang(appSettingsConfig.downloads.extractor_lang);
setEmbedMetadata(appSettingsConfig.downloads.add_metadata);
setEmbedThumbnail(appSettingsConfig.downloads.add_thumbnail);
// Subtitles
setSubtitleLang(appSettingsConfig?.downloads.subtitle || null);
setSubtitleSource(appSettingsConfig?.downloads.subtitle_source.toString());
setIndexSubtitles(appSettingsConfig?.downloads.subtitle_index);
setSubtitleLang(appSettingsConfig.downloads.subtitle);
setSubtitleSource(appSettingsConfig.downloads.subtitle_source);
setIndexSubtitles(appSettingsConfig.downloads.subtitle_index);
// Comments
setCommentsMax(appSettingsConfig?.downloads.comment_max || null);
setCommentsSort(appSettingsConfig?.downloads.comment_sort);
setCommentsMax(appSettingsConfig.downloads.comment_max);
setCommentsSort(appSettingsConfig.downloads.comment_sort);
// Cookie
// setCookieImport(appSettingsConfig?.downloads.cookie_import);
// Integrations
setDownloadDislikes(appSettingsConfig?.downloads.integrate_ryd);
setEnableSponsorBlock(appSettingsConfig?.downloads.integrate_sponsorblock);
setDownloadDislikes(appSettingsConfig.downloads.integrate_ryd);
setEnableSponsorBlock(appSettingsConfig.downloads.integrate_sponsorblock);
// Snapshots
setEnableSnapshots(appSettingsConfig?.application.enable_snapshot);
setEnableSnapshots(appSettingsConfig.application.enable_snapshot);
setResponse({
snapshots: snapshotResponse,
@ -166,6 +166,7 @@ const SettingsApplication = () => {
<div className="title-bar">
<h1>Application Configurations</h1>
</div>
{appSettingsConfig && (
<div className="info-box">
<div className="info-box-item">
<h2 id="subscriptions">Subscriptions</h2>
@ -220,7 +221,10 @@ const SettingsApplication = () => {
type="checkbox"
checked={isAutostart}
onChange={event => {
handleUpdateConfig('subscriptions.auto_start', event.target.checked || false);
handleUpdateConfig(
'subscriptions.auto_start',
event.target.checked || false,
);
}}
/>
{!isAutostart && (
@ -248,7 +252,7 @@ const SettingsApplication = () => {
name="downloads.limit_speed"
value={currentDownloadSpeed}
setValue={setCurrentDownloadSpeed}
oldValue={appSettingsConfig?.downloads.limit_speed}
oldValue={appSettingsConfig.downloads.limit_speed}
updateCallback={handleUpdateConfig}
/>
</div>
@ -261,7 +265,7 @@ const SettingsApplication = () => {
name="downloads.throttledratelimit"
value={currentThrottledRate}
setValue={setCurrentThrottledRate}
oldValue={appSettingsConfig?.downloads.throttledratelimit}
oldValue={appSettingsConfig.downloads.throttledratelimit}
updateCallback={handleUpdateConfig}
/>
</div>
@ -303,7 +307,7 @@ const SettingsApplication = () => {
name="downloads.format"
value={downloadsFormat}
setValue={setDownloadsFormat}
oldValue={appSettingsConfig?.downloads.format}
oldValue={appSettingsConfig.downloads.format}
updateCallback={handleUpdateConfig}
/>
</div>
@ -316,7 +320,7 @@ const SettingsApplication = () => {
name="downloads.format_sort"
value={downloadsFormatSort}
setValue={setDownloadsFormatSort}
oldValue={appSettingsConfig?.downloads.format_sort}
oldValue={appSettingsConfig.downloads.format_sort}
updateCallback={handleUpdateConfig}
/>
</div>
@ -329,7 +333,7 @@ const SettingsApplication = () => {
name="downloads.extractor_lang"
value={downloadsExtractorLang}
setValue={setDownloadsExtractorLang}
oldValue={appSettingsConfig?.downloads.extractor_lang}
oldValue={appSettingsConfig.downloads.extractor_lang}
updateCallback={handleUpdateConfig}
/>
</div>
@ -371,7 +375,10 @@ const SettingsApplication = () => {
type="checkbox"
checked={embedThumbnail}
onChange={event => {
handleUpdateConfig('downloads.add_thumbnail', event.target.checked || false);
handleUpdateConfig(
'downloads.add_thumbnail',
event.target.checked || false,
);
}}
/>
{!embedThumbnail && (
@ -567,7 +574,10 @@ const SettingsApplication = () => {
type="checkbox"
checked={enableSponsorBlock}
onChange={event => {
handleUpdateConfig('downloads.integrate_sponsorblock', event.target.checked);
handleUpdateConfig(
'downloads.integrate_sponsorblock',
event.target.checked,
);
}}
/>
{!enableSponsorBlock && (
@ -654,7 +664,8 @@ const SettingsApplication = () => {
}}
/>{' '}
Snapshot created on:{' '}
<span className="settings-current">{snapshot.start_date}</span>, took{' '}
<span className="settings-current">{snapshot.start_date}</span>,
took{' '}
<span className="settings-current">{snapshot.duration_s}s</span> to
create. State: <i>{snapshot.state}</i>
</p>
@ -667,6 +678,7 @@ const SettingsApplication = () => {
</div>
</div>
</div>
)}
</div>
<PaginationDummy />