diff --git a/frontend/src/api/actions/updateBulkChannelSubscriptions.ts b/frontend/src/api/actions/updateBulkChannelSubscriptions.ts new file mode 100644 index 00000000..a49f9599 --- /dev/null +++ b/frontend/src/api/actions/updateBulkChannelSubscriptions.ts @@ -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; diff --git a/frontend/src/api/actions/updateChannelSubscription.ts b/frontend/src/api/actions/updateChannelSubscription.ts index 32d26f44..184f182a 100644 --- a/frontend/src/api/actions/updateChannelSubscription.ts +++ b/frontend/src/api/actions/updateChannelSubscription.ts @@ -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 }, }); }; diff --git a/frontend/src/components/ChannelList.tsx b/frontend/src/components/ChannelList.tsx index 15f605c5..538f3e8c 100644 --- a/frontend/src/components/ChannelList.tsx +++ b/frontend/src/components/ChannelList.tsx @@ -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); }} /> )} diff --git a/frontend/src/components/ChannelOverview.tsx b/frontend/src/components/ChannelOverview.tsx index f575a6f8..1caecdbf 100644 --- a/frontend/src/components/ChannelOverview.tsx +++ b/frontend/src/components/ChannelOverview.tsx @@ -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 ( <>