Add trim to subscribe textarea fields #908

This commit is contained in:
MerlinScheurer 2025-03-28 01:26:34 +01:00
parent 04ea6254b7
commit 0aa5ef5b31
7 changed files with 36 additions and 20 deletions

View File

@ -3,7 +3,7 @@ import APIClient from '../../functions/APIClient';
const createCustomPlaylist = async (playlistId: string) => {
return APIClient('/api/playlist/custom/', {
method: 'POST',
body: { playlist_name: playlistId },
body: { playlist_name: playlistId.trim() },
});
};

View File

@ -8,7 +8,9 @@ const updateBulkChannelSubscriptions = async (channelIds: string, status: boolea
const youtubeChannelIds = channelIds.split('\n');
youtubeChannelIds.forEach(channelId => {
channels.push({ channel_id: channelId, channel_subscribed: status });
if (channelId.trim()) {
channels.push({ channel_id: channelId, channel_subscribed: status });
}
});
} else {
channels.push({ channel_id: channelIds, channel_subscribed: status });

View File

@ -8,7 +8,9 @@ const updateBulkPlaylistSubscriptions = async (playlistIds: string, status: bool
const youtubePlaylistIds = playlistIds.split('\n');
youtubePlaylistIds.forEach(playlistId => {
playlists.push({ playlist_id: playlistId, playlist_subscribed: status });
if (playlistId.trim()) {
playlists.push({ playlist_id: playlistId, playlist_subscribed: status });
}
});
} else {
playlists.push({ playlist_id: playlistIds, playlist_subscribed: status });

View File

@ -8,7 +8,9 @@ const updateDownloadQueue = async (youtubeIdStrings: string, autostart: boolean)
const youtubeIds = youtubeIdStrings.split('\n');
youtubeIds.forEach(youtubeId => {
urls.push({ youtube_id: youtubeId, status: 'pending' });
if (youtubeId.trim()) {
urls.push({ youtube_id: youtubeId, status: 'pending' });
}
});
} else {
urls.push({ youtube_id: youtubeIdStrings, status: 'pending' });

View File

@ -119,10 +119,12 @@ const Channels = () => {
label="Subscribe"
type="submit"
onClick={async () => {
await updateBulkChannelSubscriptions(channelsToSubscribeTo, true);
if (channelsToSubscribeTo.trim()) {
await updateBulkChannelSubscriptions(channelsToSubscribeTo, true);
setShowNotification(true);
setShowAddForm(false);
setShowNotification(true);
setShowAddForm(false);
}
}}
/>
</div>

View File

@ -200,19 +200,23 @@ const Download = () => {
<Button
label="Add to queue"
onClick={async () => {
await updateDownloadQueue(downloadQueueText, false);
setDownloadQueueText('');
setRefresh(true);
setShowHiddenForm(false);
if (downloadQueueText.trim()) {
await updateDownloadQueue(downloadQueueText, false);
setDownloadQueueText('');
setRefresh(true);
setShowHiddenForm(false);
}
}}
/>{' '}
<Button
label="Download now"
onClick={async () => {
await updateDownloadQueue(downloadQueueText, true);
setDownloadQueueText('');
setRefresh(true);
setShowHiddenForm(false);
if (downloadQueueText.trim()) {
await updateDownloadQueue(downloadQueueText, true);
setDownloadQueueText('');
setRefresh(true);
setShowHiddenForm(false);
}
}}
/>
</div>

View File

@ -102,9 +102,11 @@ const Playlists = () => {
label="Subscribe"
type="submit"
onClick={async () => {
await updateBulkPlaylistSubscriptions(playlistsToAddText, true);
setShowNotification(true);
setShowAddForm(false);
if (playlistsToAddText.trim()) {
await updateBulkPlaylistSubscriptions(playlistsToAddText, true);
setShowNotification(true);
setShowAddForm(false);
}
}}
/>
</div>
@ -125,8 +127,10 @@ const Playlists = () => {
label="Create"
type="submit"
onClick={async () => {
await createCustomPlaylist(customPlaylistsToAddText);
setRefresh(true);
if (customPlaylistsToAddText.trim()) {
await createCustomPlaylist(customPlaylistsToAddText);
setRefresh(true);
}
}}
/>
</div>