2020-08-21 12:51:20 +00:00
import Vue from 'vue'
2020-08-24 02:56:33 +00:00
import { mapActions } from 'vuex'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
2020-09-16 02:07:54 +00:00
import FtProfileEdit from '../../components/ft-profile-edit/ft-profile-edit.vue'
import FtProfileChannelList from '../../components/ft-profile-channel-list/ft-profile-channel-list.vue'
2021-03-06 18:00:52 +00:00
import FtProfileFilterChannelsList from '../../components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.vue'
2020-08-21 12:51:20 +00:00
export default Vue . extend ( {
name : 'ProfileEdit' ,
components : {
2020-08-24 02:56:33 +00:00
'ft-loader' : FtLoader ,
2020-09-16 02:07:54 +00:00
'ft-profile-edit' : FtProfileEdit ,
'ft-profile-channel-list' : FtProfileChannelList ,
2021-03-06 18:00:52 +00:00
'ft-profile-filter-channels-list' : FtProfileFilterChannelsList
2020-08-24 02:56:33 +00:00
} ,
data : function ( ) {
return {
isLoading : false ,
isNew : false ,
profileId : '' ,
2020-09-16 02:07:54 +00:00
profile : { }
2020-08-24 02:56:33 +00:00
}
} ,
computed : {
2020-09-16 02:07:54 +00:00
profileList : function ( ) {
return this . $store . getters . getProfileList
2020-08-24 02:56:33 +00:00
} ,
2020-09-16 02:07:54 +00:00
isMainProfile : function ( ) {
return this . profileId === 'allChannels'
2020-08-24 02:56:33 +00:00
}
} ,
watch : {
2020-09-16 02:07:54 +00:00
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 02:56:33 +00:00
}
2020-08-21 12:51:20 +00:00
} ,
2020-08-31 21:35:22 +00:00
mounted : async function ( ) {
2020-08-24 02:56:33 +00:00
this . isLoading = true
const profileType = this . $route . name
2020-09-02 03:20:21 +00:00
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-31 21:35:22 +00:00
2020-08-24 02:56:33 +00:00
if ( profileType === 'newProfile' ) {
this . isNew = true
2020-09-16 02:07:54 +00:00
const bgColor = await this . getRandomColor ( )
const textColor = await this . calculateColorLuminance ( bgColor )
this . profile = {
name : '' ,
bgColor : bgColor ,
textColor : textColor ,
subscriptions : [ ]
}
2020-08-31 21:35:22 +00:00
this . isLoading = false
2020-08-24 02:56:33 +00:00
} else {
this . isNew = false
this . profileId = this . $route . params . id
this . grabProfileInfo ( this . profileId ) . then ( ( profile ) => {
2020-08-31 21:35:22 +00:00
if ( profile === null ) {
this . showToast ( {
2020-09-02 03:20:21 +00:00
message : this . $t ( 'Profile.Profile could not be found' )
2020-08-31 21:35:22 +00:00
} )
this . $router . push ( {
path : '/settings/profile/'
} )
}
2020-09-16 02:07:54 +00:00
this . profile = profile
2020-08-24 02:56:33 +00:00
this . isLoading = false
} )
}
} ,
methods : {
... mapActions ( [
'showToast' ,
'grabProfileInfo' ,
2020-09-16 02:07:54 +00:00
'getRandomColor' ,
'calculateColorLuminance'
2020-08-24 02:56:33 +00:00
] )
2020-08-21 12:51:20 +00:00
}
} )