add synchronous channel subscribe frontend, #862
This commit is contained in:
parent
d79fbcd168
commit
0411b14c5c
|
|
@ -0,0 +1,23 @@
|
|||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updateBulkChannelSubscriptions = async (channelIds: string, status: boolean) => {
|
||||
const channels = [];
|
||||
const containsMultiple = channelIds.includes('\n');
|
||||
|
||||
if (containsMultiple) {
|
||||
const youtubeChannelIds = channelIds.split('\n');
|
||||
|
||||
youtubeChannelIds.forEach(channelId => {
|
||||
channels.push({ channel_id: channelId, channel_subscribed: status });
|
||||
});
|
||||
} else {
|
||||
channels.push({ channel_id: channelIds, channel_subscribed: status });
|
||||
}
|
||||
|
||||
return APIClient('/api/channel/', {
|
||||
method: 'POST',
|
||||
body: { data: [...channels] },
|
||||
});
|
||||
};
|
||||
|
||||
export default updateBulkChannelSubscriptions;
|
||||
|
|
@ -1,22 +1,9 @@
|
|||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updateChannelSubscription = async (channelIds: string, status: boolean) => {
|
||||
const channels = [];
|
||||
const containsMultiple = channelIds.includes('\n');
|
||||
|
||||
if (containsMultiple) {
|
||||
const youtubeChannelIds = channelIds.split('\n');
|
||||
|
||||
youtubeChannelIds.forEach(channelId => {
|
||||
channels.push({ channel_id: channelId, channel_subscribed: status });
|
||||
});
|
||||
} else {
|
||||
channels.push({ channel_id: channelIds, channel_subscribed: status });
|
||||
}
|
||||
|
||||
return APIClient('/api/channel/', {
|
||||
const updateChannelSubscription = async (channelId: string, status: boolean) => {
|
||||
return APIClient(`/api/channel/${channelId}/`, {
|
||||
method: 'POST',
|
||||
body: { data: [...channels] },
|
||||
body: { channel_subscribed: status },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -63,9 +63,7 @@ const ChannelList = ({ channelList, refreshChannelList }: ChannelListProps) => {
|
|||
title={`Unsubscribe from ${channel.channel_name}`}
|
||||
onClick={async () => {
|
||||
await updateChannelSubscription(channel.channel_id, false);
|
||||
setTimeout(() => {
|
||||
refreshChannelList(true);
|
||||
}, 1000);
|
||||
refreshChannelList(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
@ -77,10 +75,7 @@ const ChannelList = ({ channelList, refreshChannelList }: ChannelListProps) => {
|
|||
title={`Subscribe to ${channel.channel_name}`}
|
||||
onClick={async () => {
|
||||
await updateChannelSubscription(channel.channel_id, true);
|
||||
|
||||
setTimeout(() => {
|
||||
refreshChannelList(true);
|
||||
}, 500);
|
||||
refreshChannelList(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import updateChannelSubscription from '../api/actions/updateChannelSubscription'
|
|||
import FormattedNumber from './FormattedNumber';
|
||||
import Button from './Button';
|
||||
import ChannelIcon from './ChannelIcon';
|
||||
import useIsAdmin from '../functions/useIsAdmin';
|
||||
|
||||
type ChannelOverviewProps = {
|
||||
channelId: string;
|
||||
|
|
@ -11,8 +12,6 @@ type ChannelOverviewProps = {
|
|||
channelSubs: number;
|
||||
channelSubscribed: boolean;
|
||||
channelThumbUrl: string;
|
||||
showSubscribeButton?: boolean;
|
||||
isUserAdmin?: boolean;
|
||||
setRefresh: (status: boolean) => void;
|
||||
};
|
||||
|
||||
|
|
@ -22,10 +21,10 @@ const ChannelOverview = ({
|
|||
channelSubscribed,
|
||||
channelname,
|
||||
channelThumbUrl,
|
||||
showSubscribeButton = false,
|
||||
isUserAdmin,
|
||||
setRefresh,
|
||||
}: ChannelOverviewProps) => {
|
||||
const isAdmin = useIsAdmin();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="info-box-item">
|
||||
|
|
@ -41,9 +40,9 @@ const ChannelOverview = ({
|
|||
|
||||
<FormattedNumber text="Subscribers:" number={channelSubs} />
|
||||
|
||||
{showSubscribeButton && (
|
||||
{isAdmin && (
|
||||
<>
|
||||
{channelSubscribed && isUserAdmin && (
|
||||
{channelSubscribed ? (
|
||||
<Button
|
||||
label="Unsubscribe"
|
||||
className="unsubscribe"
|
||||
|
|
@ -54,9 +53,7 @@ const ChannelOverview = ({
|
|||
setRefresh(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!channelSubscribed && (
|
||||
) : (
|
||||
<Button
|
||||
label="Subscribe"
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ const ChannelAbout = () => {
|
|||
channelSubs={channel.channel_subs}
|
||||
channelSubscribed={channel.channel_subscribed}
|
||||
channelThumbUrl={channel.channel_thumb_url}
|
||||
showSubscribeButton={true}
|
||||
setRefresh={setRefresh}
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => {
|
|||
channelSubs={channel.channel_subs}
|
||||
channelSubscribed={channel.channel_subscribed}
|
||||
channelThumbUrl={channel.channel_thumb_url}
|
||||
showSubscribeButton={true}
|
||||
setRefresh={setRefresh}
|
||||
/>
|
||||
<div className="info-box-item">
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import ChannelList from '../components/ChannelList';
|
|||
import ScrollToTopOnNavigate from '../components/ScrollToTop';
|
||||
import Notifications from '../components/Notifications';
|
||||
import Button from '../components/Button';
|
||||
import updateChannelSubscription from '../api/actions/updateChannelSubscription';
|
||||
import updateBulkChannelSubscriptions from '../api/actions/updateBulkChannelSubscriptions';
|
||||
import useIsAdmin from '../functions/useIsAdmin';
|
||||
import { useUserConfigStore } from '../stores/UserConfigStore';
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ const Channels = () => {
|
|||
label="Subscribe"
|
||||
type="submit"
|
||||
onClick={async () => {
|
||||
await updateChannelSubscription(channelsToSubscribeTo, true);
|
||||
await updateBulkChannelSubscriptions(channelsToSubscribeTo, true);
|
||||
|
||||
setRefresh(true);
|
||||
}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue