orderiom-api-package 0.4.24 → 0.4.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.4.24",
3
+ "version": "0.4.25",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -243,7 +243,7 @@ const mutations = {
243
243
  }
244
244
  };
245
245
  const actions = {
246
- getCategories({ commit, dispatch, rootState }, restaurantId) {
246
+ getCategories({ commit, dispatch, rootState, state }, restaurantId) {
247
247
  let basketId = undefined;
248
248
  try {
249
249
  basketId = calculateBasketIdParameter(
@@ -264,7 +264,17 @@ const actions = {
264
264
  if (res.data.data.length) {
265
265
  categories = [...categories, ...res.data.data];
266
266
  commit('setCategories', categories);
267
- commit("setSelectedCategory", categories[0]);
267
+ if(categories.length){
268
+ if(!state.selectedCategory) {
269
+ commit("setSelectedCategory", categories[0]);
270
+ }else{
271
+ const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
272
+ if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
273
+ commit("setSelectedCategory", categories[0]);
274
+ }
275
+ }
276
+ }
277
+
268
278
  dispatch("getProducts", {
269
279
  category: categories[0],
270
280
  restaurantId: restaurantId,
@@ -275,7 +285,17 @@ const actions = {
275
285
  });
276
286
  } else {
277
287
  commit('setCategories', categories);
278
- commit("setSelectedCategory", categories[0]);
288
+ if(categories.length){
289
+ if(!state.selectedCategory) {
290
+ commit("setSelectedCategory", categories[0]);
291
+ }else{
292
+ const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
293
+ if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
294
+ commit("setSelectedCategory", categories[0]);
295
+ }
296
+ }
297
+ }
298
+
279
299
  dispatch("getProducts", {
280
300
  category: categories[0],
281
301
  restaurantId: restaurantId,