mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-05 01:19:29 +00:00
use synchronous playlist subscribe update, #862
This commit is contained in:
23
frontend/src/api/actions/updateBulkPlaylistSubscriptions.ts
Normal file
23
frontend/src/api/actions/updateBulkPlaylistSubscriptions.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updateBulkPlaylistSubscriptions = async (playlistIds: string, status: boolean) => {
|
||||
const playlists = [];
|
||||
const containsMultiple = playlistIds.includes('\n');
|
||||
|
||||
if (containsMultiple) {
|
||||
const youtubePlaylistIds = playlistIds.split('\n');
|
||||
|
||||
youtubePlaylistIds.forEach(playlistId => {
|
||||
playlists.push({ playlist_id: playlistId, playlist_subscribed: status });
|
||||
});
|
||||
} else {
|
||||
playlists.push({ playlist_id: playlistIds, playlist_subscribed: status });
|
||||
}
|
||||
|
||||
return APIClient('/api/playlist/', {
|
||||
method: 'POST',
|
||||
body: { data: [...playlists] },
|
||||
});
|
||||
};
|
||||
|
||||
export default updateBulkPlaylistSubscriptions;
|
||||
@@ -1,22 +1,9 @@
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updatePlaylistSubscription = async (playlistIds: string, status: boolean) => {
|
||||
const playlists = [];
|
||||
const containsMultiple = playlistIds.includes('\n');
|
||||
|
||||
if (containsMultiple) {
|
||||
const youtubePlaylistIds = playlistIds.split('\n');
|
||||
|
||||
youtubePlaylistIds.forEach(playlistId => {
|
||||
playlists.push({ playlist_id: playlistId, playlist_subscribed: status });
|
||||
});
|
||||
} else {
|
||||
playlists.push({ playlist_id: playlistIds, playlist_subscribed: status });
|
||||
}
|
||||
|
||||
return APIClient('/api/playlist/', {
|
||||
const updatePlaylistSubscription = async (playlistId: string, status: boolean) => {
|
||||
return APIClient(`/api/playlist/${playlistId}/`, {
|
||||
method: 'POST',
|
||||
body: { data: [...playlists] },
|
||||
body: { playlist_subscribed: status },
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ const PlaylistList = ({ playlistList, setRefresh }: PlaylistListProps) => {
|
||||
title={`Unsubscribe from ${playlist.playlist_name}`}
|
||||
onClick={async () => {
|
||||
await updatePlaylistSubscription(playlist.playlist_id, false);
|
||||
|
||||
setRefresh(true);
|
||||
}}
|
||||
/>
|
||||
@@ -69,10 +68,7 @@ const PlaylistList = ({ playlistList, setRefresh }: PlaylistListProps) => {
|
||||
title={`Subscribe to ${playlist.playlist_name}`}
|
||||
onClick={async () => {
|
||||
await updatePlaylistSubscription(playlist.playlist_id, true);
|
||||
|
||||
setTimeout(() => {
|
||||
setRefresh(true);
|
||||
}, 500);
|
||||
setRefresh(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ConfigType } from './Home';
|
||||
import Pagination, { PaginationType } from '../components/Pagination';
|
||||
import PlaylistList from '../components/PlaylistList';
|
||||
import { PlaylistType } from './Playlist';
|
||||
import updatePlaylistSubscription from '../api/actions/updatePlaylistSubscription';
|
||||
import updateBulkPlaylistSubscriptions from '../api/actions/updateBulkPlaylistSubscriptions';
|
||||
import createCustomPlaylist from '../api/actions/createCustomPlaylist';
|
||||
import ScrollToTopOnNavigate from '../components/ScrollToTop';
|
||||
import Button from '../components/Button';
|
||||
@@ -102,7 +102,7 @@ const Playlists = () => {
|
||||
label="Subscribe"
|
||||
type="submit"
|
||||
onClick={async () => {
|
||||
await updatePlaylistSubscription(playlistsToAddText, true);
|
||||
await updateBulkPlaylistSubscriptions(playlistsToAddText, true);
|
||||
setRefresh(true);
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user