mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-08 20:49:27 +00:00
Refac split channel subscribing input by line break and send ids in bulk
This commit is contained in:
@@ -1,29 +1,42 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
import getApiUrl from '../../configuration/getApiUrl';
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||||
import getCookie from '../../functions/getCookie';
|
import getCookie from '../../functions/getCookie';
|
||||||
|
|
||||||
const updateChannelSubscription = async (channelId: string, status: boolean) => {
|
const updateChannelSubscription = async (channelIds: string, status: boolean) => {
|
||||||
const apiUrl = getApiUrl();
|
const apiUrl = getApiUrl();
|
||||||
const csrfCookie = getCookie('csrftoken');
|
const csrfCookie = getCookie('csrftoken');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/`, {
|
const channels = [];
|
||||||
method: 'POST',
|
const containsMultiple = channelIds.includes('\n');
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
if (containsMultiple) {
|
||||||
'X-CSRFToken': csrfCookie || '',
|
const youtubeChannelIds = channelIds.split('\n');
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
youtubeChannelIds.forEach(channelId => {
|
||||||
|
channels.push({ channel_id: channelId, channel_subscribed: status });
|
||||||
body: JSON.stringify({
|
});
|
||||||
data: [{ channel_id: channelId, channel_subscribed: status }],
|
} else {
|
||||||
}),
|
channels.push({ channel_id: channelIds, channel_subscribed: status });
|
||||||
});
|
}
|
||||||
|
|
||||||
const channelSubscription = await response.json();
|
const response = await fetch(`${apiUrl}/api/channel/`, {
|
||||||
console.log('updateChannelSubscription', channelSubscription);
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
return channelSubscription;
|
...defaultHeaders,
|
||||||
};
|
'X-CSRFToken': csrfCookie || '',
|
||||||
|
},
|
||||||
export default updateChannelSubscription;
|
credentials: getFetchCredentials(),
|
||||||
|
|
||||||
|
body: JSON.stringify({
|
||||||
|
data: [...channels],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const channelSubscription = await response.json();
|
||||||
|
console.log('updateChannelSubscription', channelSubscription);
|
||||||
|
|
||||||
|
return channelSubscription;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default updateChannelSubscription;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import ChannelList from '../components/ChannelList';
|
|||||||
import ScrollToTopOnNavigate from '../components/ScrollToTop';
|
import ScrollToTopOnNavigate from '../components/ScrollToTop';
|
||||||
import Notifications from '../components/Notifications';
|
import Notifications from '../components/Notifications';
|
||||||
import Button from '../components/Button';
|
import Button from '../components/Button';
|
||||||
|
import updateChannelSubscription from '../api/actions/updateChannelSubscription';
|
||||||
|
|
||||||
type ChannelOverwritesType = {
|
type ChannelOverwritesType = {
|
||||||
download_format?: string;
|
download_format?: string;
|
||||||
@@ -62,6 +63,7 @@ const Channels = () => {
|
|||||||
const [view, setView] = useState<ViewLayoutType>(userMeConfig.view_style_channel || 'grid');
|
const [view, setView] = useState<ViewLayoutType>(userMeConfig.view_style_channel || 'grid');
|
||||||
const [showAddForm, setShowAddForm] = useState(false);
|
const [showAddForm, setShowAddForm] = useState(false);
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [refresh, setRefresh] = useState(false);
|
||||||
|
const [channelsToSubscribeTo, setChannelsToSubscribeTo] = useState('');
|
||||||
|
|
||||||
const channels = channelListResponse?.data;
|
const channels = channelListResponse?.data;
|
||||||
const pagination = channelListResponse?.paginate;
|
const pagination = channelListResponse?.paginate;
|
||||||
@@ -123,10 +125,25 @@ const Channels = () => {
|
|||||||
<div className="show-form">
|
<div className="show-form">
|
||||||
<div>
|
<div>
|
||||||
<label>Subscribe to channels:</label>
|
<label>Subscribe to channels:</label>
|
||||||
<textarea rows={3} placeholder="Input channel ID, URL or Video of a channel" />
|
<textarea
|
||||||
|
value={channelsToSubscribeTo}
|
||||||
|
onChange={e => {
|
||||||
|
setChannelsToSubscribeTo(e.currentTarget.value);
|
||||||
|
}}
|
||||||
|
rows={3}
|
||||||
|
placeholder="Input channel ID, URL or Video of a channel"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button label="Subscribe" type="submit" />
|
<Button
|
||||||
|
label="Subscribe"
|
||||||
|
type="submit"
|
||||||
|
onClick={async () => {
|
||||||
|
await updateChannelSubscription(channelsToSubscribeTo, true);
|
||||||
|
|
||||||
|
setRefresh(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user