Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirmation popup before unsubscribing #4896

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 47 additions & 28 deletions src/renderer/components/ft-subscribe-button/ft-subscribe-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineComponent } from 'vue'
import { mapActions } from 'vuex'

import FtButton from '../../components/ft-button/ft-button.vue'
import FtPrompt from '../../components/ft-prompt/ft-prompt.vue'

import { MAIN_PROFILE_ID } from '../../../constants'
import { deepCopy, showToast } from '../../helpers/utils'
Expand All @@ -11,7 +12,8 @@ import { getFirstCharacter } from '../../helpers/strings'
export default defineComponent({
name: 'FtSubscribeButton',
components: {
'ft-button': FtButton
'ft-button': FtButton,
'ft-prompt': FtPrompt
},
props: {
channelId: {
Expand Down Expand Up @@ -42,7 +44,8 @@ export default defineComponent({
},
data: function () {
return {
isProfileDropdownOpen: false
isProfileDropdownOpen: false,
showUnsubscribePopupForProfile: null
}
},
computed: {
Expand Down Expand Up @@ -108,34 +111,14 @@ export default defineComponent({
return
}

const currentProfile = deepCopy(profile)

if (this.isProfileSubscribed(profile)) {
currentProfile.subscriptions = currentProfile.subscriptions.filter((channel) => {
return channel.id !== this.channelId
})

this.updateProfile(currentProfile)
showToast(this.$t('Channel.Channel has been removed from your subscriptions'))

if (profile._id === MAIN_PROFILE_ID) {
// Check if a subscription exists in a different profile.
// Remove from there as well.
let duplicateSubscriptions = 0

this.profileList.forEach((profileInList) => {
if (profileInList._id === MAIN_PROFILE_ID) {
return
}
duplicateSubscriptions += this.unsubscribe(profileInList, this.channelId)
})

if (duplicateSubscriptions > 0) {
const message = this.$t('Channel.Removed subscription from {count} other channel(s)', { count: duplicateSubscriptions })
showToast(message)
}
if (this.$store.getters.getUnsubscriptionPopupStatus) {
this.showUnsubscribePopupForProfile = profile
} else {
this.handleUnsubscription(profile)
}
} else {
const currentProfile = deepCopy(profile)
const subscription = {
id: this.channelId,
name: this.channelName,
Expand Down Expand Up @@ -173,10 +156,46 @@ export default defineComponent({
}
},

toggleProfileDropdown: function() {
toggleProfileDropdown: function () {
this.isProfileDropdownOpen = !this.isProfileDropdownOpen
},

handleUnsubscribeConfirmation: async function (value) {
const profile = this.showUnsubscribePopupForProfile
this.showUnsubscribePopupForProfile = null
if (value === 'yes') {
this.handleUnsubscription(profile)
}
},

handleUnsubscription: function (profile) {
const currentProfile = deepCopy(profile)
currentProfile.subscriptions = currentProfile.subscriptions.filter((channel) => {
return channel.id !== this.channelId
})

this.updateProfile(currentProfile)
showToast(this.$t('Channel.Channel has been removed from your subscriptions'))

if (profile._id === MAIN_PROFILE_ID) {
// Check if a subscription exists in a different profile.
// Remove from there as well.
let duplicateSubscriptions = 0

this.profileList.forEach((profileInList) => {
if (profileInList._id === MAIN_PROFILE_ID) {
return
}
duplicateSubscriptions += this.unsubscribe(profileInList, this.channelId)
})

if (duplicateSubscriptions > 0) {
const message = this.$t('Channel.Removed subscription from {count} other channel(s)', { count: duplicateSubscriptions })
showToast(message)
}
}
},

isActiveProfile: function (profile) {
return profile._id === this.activeProfile._id
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
text-color="var(--text-with-main-color)"
@click="handleSubscription"
/>
<ft-prompt
v-if="showUnsubscribePopupForProfile !== null"
:label="$t('Channels.Unsubscribe Prompt', { channelName: channelName })"
:option-names="[$t('Yes'), $t('No')]"
:option-values="['yes', 'no']"
:autosize="true"
@click="handleUnsubscribeConfirmation"
/>
<ft-button
v-if="isProfileDropdownEnabled"
:no-border="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export default defineComponent({
},
fetchSubscriptionsAutomatically: function () {
return this.$store.getters.getFetchSubscriptionsAutomatically
},
unsubscriptionPopupStatus: function () {
return this.$store.getters.getUnsubscriptionPopupStatus
}
},
methods: {
...mapActions([
'updateHideWatchedSubs',
'updateUseRssFeeds',
'updateFetchSubscriptionsAutomatically',
'updateOnlyShowLatestFromChannel'
'updateOnlyShowLatestFromChannel',
'updateUnsubscriptionPopupStatus'
])
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
@change="updateOnlyShowLatestFromChannel"
/>
</div>
<div class="switchColumn">
<ft-toggle-switch
:label="$t('Settings.Subscription Settings.Avoid Accidental Unsubscription')"
:default-value="unsubscriptionPopupStatus"
:compact="true"
@change="updateUnsubscriptionPopupStatus"
/>
</div>
</div>
</ft-settings-section>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const state = {
hideVideoLikesAndDislikes: false,
hideVideoViews: false,
hideWatchedSubs: false,
unsubscriptionPopupStatus: false,
hideLabelsSideBar: false,
hideChapters: false,
showDistractionFreeTitles: false,
Expand Down
1 change: 1 addition & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ Settings:
Manage Subscriptions: Manage Subscriptions
Fetch Automatically: Fetch Feed Automatically
Only Show Latest Video for Each Channel: Only Show Latest Video for Each Channel
Avoid Accidental Unsubscription: Avoid Accidental Unsubscription
Distraction Free Settings:
Distraction Free Settings: Distraction Free Settings
Sections:
Expand Down