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 = { export type AppSettingsConfigType = {
subscriptions: { subscriptions: {
channel_size: number; channel_size: number | null;
live_channel_size: number; live_channel_size: number | null;
shorts_channel_size: number; shorts_channel_size: number | null;
auto_start: boolean; auto_start: boolean;
}; };
downloads: { downloads: {
limit_speed: number | undefined; limit_speed: number | null;
sleep_interval: number; sleep_interval: number | null;
autodelete_days: number; autodelete_days: number | null;
format: string | undefined; format: string | null;
format_sort: string | undefined; format_sort: string | null;
add_metadata: boolean; add_metadata: boolean;
add_thumbnail: boolean; add_thumbnail: boolean;
subtitle: string | undefined; subtitle: string | null;
subtitle_source: boolean | string; subtitle_source: string | null;
subtitle_index: boolean; subtitle_index: boolean;
comment_max: string | undefined; comment_max: string | null;
comment_sort: string; comment_sort: string;
cookie_import: boolean; cookie_import: boolean;
throttledratelimit: number | undefined; throttledratelimit: number | null;
extractor_lang: string | undefined; extractor_lang: string | null;
integrate_ryd: boolean; integrate_ryd: boolean;
integrate_sponsorblock: boolean; integrate_sponsorblock: boolean;
}; };

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff