diff options
Diffstat (limited to 'app/assets/javascripts/frequent_items/store/actions.js')
-rw-r--r-- | app/assets/javascripts/frequent_items/store/actions.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/assets/javascripts/frequent_items/store/actions.js b/app/assets/javascripts/frequent_items/store/actions.js index babc2ef2e32..e5ef49ec402 100644 --- a/app/assets/javascripts/frequent_items/store/actions.js +++ b/app/assets/javascripts/frequent_items/store/actions.js @@ -12,6 +12,10 @@ export const setStorageKey = ({ commit }, key) => { commit(types.SET_STORAGE_KEY, key); }; +export const toggleItemsListEditablity = ({ commit }) => { + commit(types.TOGGLE_ITEMS_LIST_EDITABILITY); +}; + export const requestFrequentItems = ({ commit }) => { commit(types.REQUEST_FREQUENT_ITEMS); }; @@ -81,3 +85,28 @@ export const setSearchQuery = ({ commit, dispatch }, query) => { dispatch('fetchFrequentItems'); } }; + +export const removeFrequentItemSuccess = ({ commit }, itemId) => { + commit(types.RECEIVE_REMOVE_FREQUENT_ITEM_SUCCESS, itemId); +}; + +export const removeFrequentItemError = ({ commit }) => { + commit(types.RECEIVE_REMOVE_FREQUENT_ITEM_ERROR); +}; + +export const removeFrequentItem = ({ state, dispatch }, itemId) => { + if (AccessorUtilities.canUseLocalStorage()) { + try { + const storedRawItems = JSON.parse(localStorage.getItem(state.storageKey)); + localStorage.setItem( + state.storageKey, + JSON.stringify(storedRawItems.filter((item) => item.id !== itemId)), + ); + dispatch('removeFrequentItemSuccess', itemId); + } catch { + dispatch('removeFrequentItemError'); + } + } else { + dispatch('removeFrequentItemError'); + } +}; |