mirror of https://github.com/FreeTubeApp/FreeTube
Profiles: Implement suplementary profile creation logic
This commit is contained in:
parent
b320578807
commit
76cde71ed5
|
@ -447,11 +447,12 @@ function runApp() {
|
|||
ipcMain.handle(IpcChannels.DB_PROFILES, async (_, { action, data }) => {
|
||||
try {
|
||||
switch (action) {
|
||||
case DBActions.GENERAL.CREATE:
|
||||
await baseHandlers.profiles.create(data)
|
||||
case DBActions.GENERAL.CREATE: {
|
||||
const newProfile = await baseHandlers.profiles.create(data)
|
||||
// TODO: Syncing
|
||||
// syncOtherWindows(IpcChannels.SYNC_PROFILES, event, { event: '_', data })
|
||||
return null
|
||||
return newProfile
|
||||
}
|
||||
|
||||
case DBActions.GENERAL.FIND:
|
||||
return await baseHandlers.profiles.find()
|
||||
|
|
|
@ -113,9 +113,8 @@ export default Vue.extend({
|
|||
|
||||
console.log(profile)
|
||||
|
||||
this.updateProfile(profile)
|
||||
|
||||
if (this.isNew) {
|
||||
this.createProfile(profile)
|
||||
this.showToast({
|
||||
message: this.$t('Profile.Profile has been created')
|
||||
})
|
||||
|
@ -123,6 +122,7 @@ export default Vue.extend({
|
|||
path: '/settings/profile/'
|
||||
})
|
||||
} else {
|
||||
this.updateProfile(profile)
|
||||
this.showToast({
|
||||
message: this.$t('Profile.Profile has been updated')
|
||||
})
|
||||
|
@ -161,6 +161,7 @@ export default Vue.extend({
|
|||
|
||||
...mapActions([
|
||||
'showToast',
|
||||
'createProfile',
|
||||
'updateProfile',
|
||||
'removeProfile',
|
||||
'updateDefaultProfile',
|
||||
|
|
|
@ -89,6 +89,15 @@ const actions = {
|
|||
commit('setProfileList', profiles)
|
||||
},
|
||||
|
||||
async createProfile({ commit }, profile) {
|
||||
try {
|
||||
const newProfile = await DBProfileHandlers.create(profile)
|
||||
commit('addProfileToList', newProfile)
|
||||
} catch (errMessage) {
|
||||
console.error(errMessage)
|
||||
}
|
||||
},
|
||||
|
||||
async updateProfile({ commit }, profile) {
|
||||
try {
|
||||
await DBProfileHandlers.upsert(profile)
|
||||
|
@ -125,6 +134,11 @@ const mutations = {
|
|||
state.activeProfile = activeProfile
|
||||
},
|
||||
|
||||
addProfileToList(state, profile) {
|
||||
state.profileList.push(profile)
|
||||
state.profileList.sort(profileSort)
|
||||
},
|
||||
|
||||
upsertProfileToList(state, updatedProfile) {
|
||||
const i = state.profileList.findIndex((p) => {
|
||||
return p._id === updatedProfile._id
|
||||
|
@ -135,6 +149,8 @@ const mutations = {
|
|||
} else {
|
||||
state.profileList.splice(i, 1, updatedProfile)
|
||||
}
|
||||
|
||||
state.profileList.sort(profileSort)
|
||||
},
|
||||
|
||||
removeProfileFromList(state, profileId) {
|
||||
|
|
Loading…
Reference in New Issue