This commit is contained in:
Peter Papp
2020-12-19 17:04:52 +01:00
parent 9098634b99
commit 08dc813af9
4 changed files with 118 additions and 229 deletions

View File

@@ -2,6 +2,7 @@ import axios from 'axios'
import {events} from '@/bus'
import i18n from '@/i18n/index.js'
import router from '@/router'
import Vue from 'vue'
const defaultState = {
authorized: undefined,
@@ -52,13 +53,14 @@ const actions = {
let addFavourites = []
let items = [folder]
if(!folder){
if(!folder)
items = context.getters.fileInfoDetail
}
items.forEach((data) => {
if(data.type === 'folder' ) {
if(context.getters.user.relationships.favourites.data.attributes.folders.find(folder => folder.unique_id === data.unique_id)) return
addFavourites.push({
'unique_id': data.unique_id
})
@@ -71,7 +73,7 @@ const actions = {
let pushToFavorites = []
//Check is favorites already don't include some of pushed folders
// Check is favorites already don't include some of pushed folders
items.map(data => {
if(!context.getters.user.relationships.favourites.data.attributes.folders.find(folder => folder.unique_id === data.unique_id)){
pushToFavorites.push(data)
@@ -86,28 +88,20 @@ const actions = {
folders: addFavourites
})
.catch(() => {
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
Vue.prototype.$isSomethingWrong()
})
},
removeFromFavourites: (context, folder) => {
removeFromFavourites: ({commit, getters, dispatch}, folder) => {
// Remove from storage
context.commit('REMOVE_ITEM_FROM_FAVOURITES', folder)
commit('REMOVE_ITEM_FROM_FAVOURITES', folder)
axios
.post(context.getters.api + '/folders/favourites/' + folder.unique_id, {
.post(getters.api + '/folders/favourites/' + folder.unique_id, {
_method: 'delete'
})
.catch(() => {
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
Vue.prototype.$isSomethingWrong()
})
},
}