diff --git a/src/components/SubscriptionButton.vue b/src/components/SubscriptionButton.vue new file mode 100644 index 0000000..0effb02 --- /dev/null +++ b/src/components/SubscriptionButton.vue @@ -0,0 +1,60 @@ + + + diff --git a/src/routes/Channel.vue b/src/routes/Channel.vue index e73d94b..485127c 100644 --- a/src/routes/Channel.vue +++ b/src/routes/Channel.vue @@ -11,12 +11,7 @@
{{ channel.name }}
- - {{ subscribed ? 'Unsubscribe' : 'Subscribe' }} - +
@@ -42,14 +37,14 @@ import { chunk as _chunk } from 'lodash-es' import ErrorHandler from '@/components/ErrorHandler' import VideoItem from '@/components/VideoItem.vue' +import SubscriptionButton from '@/components/SubscriptionButton' import { LibPiped } from '@/tools/libpiped' export default { data () { return { - channel: null, - subscribed: null + channel: null } }, metaInfo () { @@ -99,7 +94,10 @@ export default { }, mounted () { - this.getChannelData() + this.fetchChannel() + }, + watch: { + '$route.params.channelId': 'fetchChannel' }, methods: { async fetchChannel () { @@ -108,40 +106,6 @@ export default { }) }, - async fetchSubscribedStatus () { - const { channelId } = this.$route.params - if (!(channelId && this.$store.getters['auth/isCurrentlyAuthenticated'])) { - return - } - - const resp = await this.$store.dispatch('auth/makeRequest', { - path: '/subscribed', - params: { - channelId - } - }) - - this.subscribed = resp.subscribed - }, - - async subscribeHandler () { - await this.$store.dispatch('auth/makeRequest', { - method: 'POST', - path: (this.subscribed ? '/unsubscribe' : '/subscribe'), - data: { - channelId: this.channelId - } - }) - this.subscribed = !this.subscribed - }, - - async getChannelData () { - return Promise.all([ - this.fetchChannel(), - this.fetchSubscribedStatus() - ]) - }, - onRelatedStreamsEndIntersect (entries) { if (entries[0].isIntersecting) { this.fetchMoreVideos() @@ -172,6 +136,7 @@ export default { } }, components: { + SubscriptionButton, ErrorHandler, VideoItem } diff --git a/src/routes/Subscriptions.vue b/src/routes/Subscriptions.vue index 4e56f0e..fdce3a3 100644 --- a/src/routes/Subscriptions.vue +++ b/src/routes/Subscriptions.vue @@ -8,12 +8,7 @@ {{ channel.name }} - - {{ channel.subscribed ? 'Unsubscribe' : 'Subscribe' }} - + @@ -24,8 +19,12 @@