shelflife-react-hooks 1.0.18 → 1.0.20
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/dist/index.cjs.js +23 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +23 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +36 -36
- package/src/context/AuthContext.tsx +161 -161
- package/src/context/InviteContext.tsx +74 -74
- package/src/context/ProductContext.tsx +131 -121
- package/src/context/RunningLowContext.tsx +100 -100
- package/src/context/ShoppingListContext.tsx +76 -76
- package/src/context/StorageContext.tsx +105 -105
- package/src/context/StorageItemContext.tsx +157 -157
- package/src/context/StorageMemberContext.tsx +84 -84
- package/src/context/UserContext.tsx +109 -109
- package/src/context/__tests__/contexts.test.tsx +370 -370
- package/src/context/api/authApi.ts +155 -155
- package/src/context/api/inviteApi.ts +65 -65
- package/src/context/api/productApi.ts +223 -201
- package/src/context/api/requestState.ts +24 -24
- package/src/context/api/runningLowApi.ts +141 -141
- package/src/context/api/shoppingListApi.ts +161 -159
- package/src/context/api/storageApi.ts +166 -166
- package/src/context/api/storageItemApi.ts +260 -260
- package/src/context/api/storageMemberApi.ts +84 -84
- package/src/context/api/userApi.ts +161 -161
- package/src/context/http.ts +22 -22
- package/src/index.ts +21 -21
- package/src/type/PaginatedResponse.ts +8 -8
- package/src/type/auth.ts +79 -79
- package/src/type/base.ts +21 -21
- package/src/type/item.ts +12 -12
- package/src/type/member.ts +6 -6
- package/src/type/models.ts +56 -56
- package/src/type/product.ts +11 -11
- package/src/type/requests.ts +60 -60
- package/src/type/runninglow.ts +13 -13
- package/src/type/shoppingList.ts +13 -13
- package/src/type/storage.ts +7 -7
- package/src/type/user.ts +11 -11
- package/tsconfig.json +46 -46
- package/tsup.config.ts +10 -10
- package/vitest.config.ts +8 -8
package/dist/index.cjs.js
CHANGED
|
@@ -534,6 +534,21 @@ var fetchProductRequest = async (config, id) => runWithRequestState(config, asyn
|
|
|
534
534
|
config.setProducts((previous) => updateById2(previous, payload));
|
|
535
535
|
return payload;
|
|
536
536
|
});
|
|
537
|
+
var fetchCategoriesRequest = async (config) => runWithRequestState(config, async () => {
|
|
538
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
539
|
+
const response = await fetch(`${normalizedBaseUrl}/api/products/categories`, {
|
|
540
|
+
headers: buildAuthHeaders(config.token)
|
|
541
|
+
});
|
|
542
|
+
if (!response.ok) {
|
|
543
|
+
throw new Error("Failed to fetch categories");
|
|
544
|
+
}
|
|
545
|
+
const payload = await readJson(response);
|
|
546
|
+
if (!payload) {
|
|
547
|
+
throw new Error("Category response missing data");
|
|
548
|
+
}
|
|
549
|
+
config.setCategories(payload);
|
|
550
|
+
return payload;
|
|
551
|
+
});
|
|
537
552
|
var createProductRequest = async (config, dto) => runWithRequestState(config, async () => {
|
|
538
553
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
539
554
|
const response = await fetch(`${normalizedBaseUrl}/api/products`, {
|
|
@@ -623,6 +638,7 @@ var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
|
623
638
|
var ProductContext = (0, import_react3.createContext)(void 0);
|
|
624
639
|
var ProductProvider = ({ baseUrl, children }) => {
|
|
625
640
|
const { token } = useAuth();
|
|
641
|
+
const [categories, setCategories] = (0, import_react3.useState)([]);
|
|
626
642
|
const [products, setProducts] = (0, import_react3.useState)([]);
|
|
627
643
|
const [product, setProduct] = (0, import_react3.useState)(null);
|
|
628
644
|
const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
|
|
@@ -631,6 +647,7 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
631
647
|
const apiConfig = (0, import_react3.useMemo)(() => ({
|
|
632
648
|
baseUrl,
|
|
633
649
|
token,
|
|
650
|
+
setCategories,
|
|
634
651
|
setProducts,
|
|
635
652
|
setProduct,
|
|
636
653
|
setIsLoading,
|
|
@@ -641,6 +658,7 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
641
658
|
(search = "", size = 0, page = 0) => fetchProductsRequest(apiConfig, search, size, page),
|
|
642
659
|
[apiConfig]
|
|
643
660
|
);
|
|
661
|
+
const fetchCategories = (0, import_react3.useCallback)(() => fetchCategoriesRequest(apiConfig), [apiConfig]);
|
|
644
662
|
const fetchProduct = (0, import_react3.useCallback)((id) => fetchProductRequest(apiConfig, id), [apiConfig]);
|
|
645
663
|
const createProduct = (0, import_react3.useCallback)(
|
|
646
664
|
(dto) => createProductRequest(apiConfig, dto),
|
|
@@ -662,6 +680,8 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
662
680
|
isLoading,
|
|
663
681
|
isError,
|
|
664
682
|
error,
|
|
683
|
+
categories,
|
|
684
|
+
fetchCategories,
|
|
665
685
|
fetchProducts,
|
|
666
686
|
fetchProduct,
|
|
667
687
|
createProduct,
|
|
@@ -675,11 +695,13 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
675
695
|
error,
|
|
676
696
|
fetchProduct,
|
|
677
697
|
fetchProducts,
|
|
698
|
+
fetchCategories,
|
|
678
699
|
getProductIcon,
|
|
679
700
|
isError,
|
|
680
701
|
isLoading,
|
|
681
702
|
product,
|
|
682
703
|
products,
|
|
704
|
+
categories,
|
|
683
705
|
updateProduct,
|
|
684
706
|
uploadProductIcon
|
|
685
707
|
]);
|
|
@@ -1530,6 +1552,7 @@ var createStorageItemsWithShoppingListItemRequest = async (config, storageId, it
|
|
|
1530
1552
|
if (!response.ok) {
|
|
1531
1553
|
throw new Error("Failed to add items");
|
|
1532
1554
|
}
|
|
1555
|
+
config.setItems((previous) => previous.filter((i) => i.id !== itemId));
|
|
1533
1556
|
});
|
|
1534
1557
|
var createShoppingItemRequest = async (config, storageId, dto) => runWithRequestState(config, async () => {
|
|
1535
1558
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|