FreeTube/src/renderer/views/ProfileEdit/ProfileEdit.js

94 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-08-21 14:51:20 +02:00
import Vue from 'vue'
2020-08-24 04:56:33 +02:00
import { mapActions } from 'vuex'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtProfileEdit from '../../components/ft-profile-edit/ft-profile-edit.vue'
import FtProfileChannelList from '../../components/ft-profile-channel-list/ft-profile-channel-list.vue'
import FtProfileFilterChannelsList from '../../components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.vue'
2020-08-21 14:51:20 +02:00
export default Vue.extend({
name: 'ProfileEdit',
components: {
2020-08-24 04:56:33 +02:00
'ft-loader': FtLoader,
'ft-profile-edit': FtProfileEdit,
'ft-profile-channel-list': FtProfileChannelList,
'ft-profile-filter-channels-list': FtProfileFilterChannelsList
2020-08-24 04:56:33 +02:00
},
data: function () {
return {
isLoading: false,
isNew: false,
profileId: '',
profile: {}
2020-08-24 04:56:33 +02:00
}
},
computed: {
profileList: function () {
return this.$store.getters.getProfileList
2020-08-24 04:56:33 +02:00
},
isMainProfile: function () {
return this.profileId === 'allChannels'
2020-08-24 04:56:33 +02:00
}
},
watch: {
profileList: {
handler: function () {
this.grabProfileInfo(this.profileId).then((profile) => {
if (profile === null) {
this.showToast({
message: this.$t('Profile.Profile could not be found')
})
this.$router.push({
path: '/settings/profile/'
})
}
this.profile = profile
})
},
deep: true
2020-08-24 04:56:33 +02:00
}
2020-08-21 14:51:20 +02:00
},
mounted: async function () {
2020-08-24 04:56:33 +02:00
this.isLoading = true
const profileType = this.$route.name
this.deletePromptLabel = `${this.$t('Profile.Are you sure you want to delete this profile?')} ${this.$t('Profile["All subscriptions will also be deleted."]')}`
2020-08-24 04:56:33 +02:00
if (profileType === 'newProfile') {
this.isNew = true
const bgColor = await this.getRandomColor()
const textColor = await this.calculateColorLuminance(bgColor)
this.profile = {
name: '',
bgColor: bgColor,
textColor: textColor,
subscriptions: []
}
this.isLoading = false
2020-08-24 04:56:33 +02:00
} else {
this.isNew = false
this.profileId = this.$route.params.id
this.grabProfileInfo(this.profileId).then((profile) => {
if (profile === null) {
this.showToast({
message: this.$t('Profile.Profile could not be found')
})
this.$router.push({
path: '/settings/profile/'
})
}
this.profile = profile
2020-08-24 04:56:33 +02:00
this.isLoading = false
})
}
},
methods: {
...mapActions([
'showToast',
'grabProfileInfo',
'getRandomColor',
'calculateColorLuminance'
2020-08-24 04:56:33 +02:00
])
2020-08-21 14:51:20 +02:00
}
})