erp-city-vue-components 0.1.0 → 0.1.1
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/README.md +3 -3
- package/package.json +1 -1
- package/src/components/FavoritesSidebar.vue +13 -1
- package/src/state/productsState.js +36 -3
package/README.md
CHANGED
|
@@ -8,10 +8,10 @@ Designed to integrate with `erp-city` and `erp-city-client`:
|
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Install from npm:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install
|
|
14
|
+
npm install erp-city-vue-components
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Or add to your app `package.json`:
|
|
@@ -19,7 +19,7 @@ Or add to your app `package.json`:
|
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"erp-city-vue-components": "
|
|
22
|
+
"erp-city-vue-components": "^0.1.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
```
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed, onMounted } from 'vue';
|
|
2
|
+
import { computed, onMounted, watch } from 'vue';
|
|
3
3
|
import FavoriteProductCard from './FavoriteProductCard.vue';
|
|
4
4
|
import { favoritesState } from '../state/favoritesState.js';
|
|
5
5
|
import { productsState } from '../state/productsState.js';
|
|
@@ -18,6 +18,18 @@ onMounted(() => {
|
|
|
18
18
|
favoritesState.fetchFavorites();
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
+
|
|
22
|
+
watch(
|
|
23
|
+
() => favoritesState.ids.length,
|
|
24
|
+
(count) => {
|
|
25
|
+
if (!count) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
productsState.ensureLoaded();
|
|
30
|
+
},
|
|
31
|
+
{ immediate: true },
|
|
32
|
+
);
|
|
21
33
|
</script>
|
|
22
34
|
|
|
23
35
|
<template>
|
|
@@ -4,13 +4,46 @@ import { route } from 'ziggy-js';
|
|
|
4
4
|
|
|
5
5
|
export const productsState = reactive({
|
|
6
6
|
products: [],
|
|
7
|
+
loading: false,
|
|
8
|
+
error: null,
|
|
9
|
+
loaded: false,
|
|
7
10
|
|
|
8
11
|
getProduct(id) {
|
|
9
12
|
return this.products.find(product => product.id === id);
|
|
10
13
|
},
|
|
11
14
|
|
|
12
15
|
async loadProducts() {
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
+
this.loading = true;
|
|
17
|
+
this.error = null;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const { data } = await axios.get(route('products.index'));
|
|
21
|
+
this.products = Array.isArray(data) ? data : [];
|
|
22
|
+
this.loaded = true;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
this.error = error?.response?.data?.message || 'Nu am putut încărca produsele.';
|
|
25
|
+
throw error;
|
|
26
|
+
} finally {
|
|
27
|
+
this.loading = false;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async ensureLoaded() {
|
|
32
|
+
if (this.loaded || this.loading) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
await this.loadProducts();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
// Errors are stored on state; callers can check productsState.error.
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
reset() {
|
|
44
|
+
this.products = [];
|
|
45
|
+
this.loading = false;
|
|
46
|
+
this.error = null;
|
|
47
|
+
this.loaded = false;
|
|
48
|
+
},
|
|
16
49
|
});
|