shelflife-react-hooks 1.0.17 → 1.0.18
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 +32 -47
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +4 -20
- package/dist/index.d.ts +4 -20
- package/dist/index.esm.js +32 -45
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/context/ShoppingListContext.tsx +14 -2
- package/src/context/api/shoppingListApi.ts +38 -1
- package/src/index.ts +1 -2
- package/src/type/models.ts +2 -7
- package/src/context/ToPurchaseContext.tsx +0 -43
- package/src/context/api/toPurchaseApi.ts +0 -30
package/dist/index.cjs.js
CHANGED
|
@@ -28,7 +28,6 @@ __export(index_exports, {
|
|
|
28
28
|
StorageItemProvider: () => StorageItemProvider,
|
|
29
29
|
StorageMemberProvider: () => StorageMemberProvider,
|
|
30
30
|
StorageProvider: () => StorageProvider,
|
|
31
|
-
ToPurchaseProvider: () => ToPurchaseProvider,
|
|
32
31
|
UserProvider: () => UserProvider,
|
|
33
32
|
buildAuthHeaders: () => buildAuthHeaders,
|
|
34
33
|
normalizeBaseUrl: () => normalizeBaseUrl,
|
|
@@ -42,7 +41,6 @@ __export(index_exports, {
|
|
|
42
41
|
useStorageItems: () => useStorageItems,
|
|
43
42
|
useStorageMembers: () => useStorageMembers,
|
|
44
43
|
useStorages: () => useStorages,
|
|
45
|
-
useToPurchase: () => useToPurchase,
|
|
46
44
|
useUsers: () => useUsers
|
|
47
45
|
});
|
|
48
46
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1508,6 +1506,31 @@ var fetchShoppingListRequest = async (config, storageId) => runWithRequestState(
|
|
|
1508
1506
|
}
|
|
1509
1507
|
return [];
|
|
1510
1508
|
});
|
|
1509
|
+
var fetchAggregatedShoppingListRequest = async (config) => runWithRequestState(config, async () => {
|
|
1510
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1511
|
+
const response = await fetch(`${normalizedBaseUrl}/api/shoppinglist`, {
|
|
1512
|
+
headers: buildAuthHeaders(config.token)
|
|
1513
|
+
});
|
|
1514
|
+
if (!response.ok) {
|
|
1515
|
+
throw new Error("Failed to fetch aggregated shopping list");
|
|
1516
|
+
}
|
|
1517
|
+
const payload = await readJson(response);
|
|
1518
|
+
if (payload) {
|
|
1519
|
+
config.setItems(payload);
|
|
1520
|
+
return payload;
|
|
1521
|
+
}
|
|
1522
|
+
return [];
|
|
1523
|
+
});
|
|
1524
|
+
var createStorageItemsWithShoppingListItemRequest = async (config, storageId, itemId) => runWithRequestState(config, async () => {
|
|
1525
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1526
|
+
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist/${itemId}`, {
|
|
1527
|
+
method: "POST",
|
|
1528
|
+
headers: buildAuthHeaders(config.token)
|
|
1529
|
+
});
|
|
1530
|
+
if (!response.ok) {
|
|
1531
|
+
throw new Error("Failed to add items");
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1511
1534
|
var createShoppingItemRequest = async (config, storageId, dto) => runWithRequestState(config, async () => {
|
|
1512
1535
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1513
1536
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist`, {
|
|
@@ -1575,6 +1598,9 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1575
1598
|
const fetchItems = (0, import_react9.useCallback)(async (storageId) => {
|
|
1576
1599
|
return fetchShoppingListRequest(apiConfig, storageId);
|
|
1577
1600
|
}, [apiConfig]);
|
|
1601
|
+
const createStorageItemsWithShoppingListItem = (0, import_react9.useCallback)(async (storageId, itemId) => {
|
|
1602
|
+
return createStorageItemsWithShoppingListItemRequest(apiConfig, storageId, itemId);
|
|
1603
|
+
}, [apiConfig]);
|
|
1578
1604
|
const createItem = (0, import_react9.useCallback)(async (storageId, dto) => {
|
|
1579
1605
|
return createShoppingItemRequest(apiConfig, storageId, dto);
|
|
1580
1606
|
}, [apiConfig]);
|
|
@@ -1584,7 +1610,10 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1584
1610
|
const deleteItem = (0, import_react9.useCallback)(async (storageId, itemId) => {
|
|
1585
1611
|
return deleteShoppingItemRequest(apiConfig, storageId, itemId);
|
|
1586
1612
|
}, [apiConfig]);
|
|
1587
|
-
const
|
|
1613
|
+
const fetchAggregated = (0, import_react9.useCallback)(async () => {
|
|
1614
|
+
return fetchAggregatedShoppingListRequest(apiConfig);
|
|
1615
|
+
}, [apiConfig]);
|
|
1616
|
+
const value = (0, import_react9.useMemo)(() => ({ items, isLoading, isError, error, fetchItems, createItem, editItem, deleteItem, createStorageItemsWithShoppingListItem, fetchAggregated }), [items, isLoading, isError, error, fetchItems, createItem, editItem, deleteItem, createStorageItemsWithShoppingListItem, fetchAggregated]);
|
|
1588
1617
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ShoppingListContext.Provider, { value, children });
|
|
1589
1618
|
};
|
|
1590
1619
|
var useShoppingList = () => {
|
|
@@ -1592,48 +1621,6 @@ var useShoppingList = () => {
|
|
|
1592
1621
|
if (!context) throw new Error("useShoppingList must be used within a ShoppingListProvider");
|
|
1593
1622
|
return context;
|
|
1594
1623
|
};
|
|
1595
|
-
|
|
1596
|
-
// src/context/ToPurchaseContext.tsx
|
|
1597
|
-
var import_react10 = require("react");
|
|
1598
|
-
|
|
1599
|
-
// src/context/api/toPurchaseApi.ts
|
|
1600
|
-
var fetchAggregatedShoppingRequest = async (config) => runWithRequestState(config, async () => {
|
|
1601
|
-
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1602
|
-
const response = await fetch(`${normalizedBaseUrl}/api/shoppinglist`, {
|
|
1603
|
-
headers: buildAuthHeaders(config.token)
|
|
1604
|
-
});
|
|
1605
|
-
if (!response.ok) {
|
|
1606
|
-
throw new Error("Failed to fetch aggregated shopping list");
|
|
1607
|
-
}
|
|
1608
|
-
const payload = await readJson(response);
|
|
1609
|
-
if (payload) {
|
|
1610
|
-
config.setToPurchase(payload);
|
|
1611
|
-
return payload;
|
|
1612
|
-
}
|
|
1613
|
-
return [];
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
// src/context/ToPurchaseContext.tsx
|
|
1617
|
-
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1618
|
-
var ToPurchaseContext = (0, import_react10.createContext)(void 0);
|
|
1619
|
-
var ToPurchaseProvider = ({ baseUrl, children }) => {
|
|
1620
|
-
const { token } = useAuth();
|
|
1621
|
-
const [items, setItems] = (0, import_react10.useState)([]);
|
|
1622
|
-
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
1623
|
-
const [isError, setIsError] = (0, import_react10.useState)(false);
|
|
1624
|
-
const [error, setError] = (0, import_react10.useState)(null);
|
|
1625
|
-
const apiConfig = { baseUrl, token, setToPurchase: setItems, setIsLoading, setIsError, setError };
|
|
1626
|
-
const fetchAggregated = (0, import_react10.useCallback)(async () => {
|
|
1627
|
-
return fetchAggregatedShoppingRequest(apiConfig);
|
|
1628
|
-
}, [apiConfig]);
|
|
1629
|
-
const value = (0, import_react10.useMemo)(() => ({ items, isLoading, isError, error, fetchAggregated }), [items, isLoading, isError, error, fetchAggregated]);
|
|
1630
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ToPurchaseContext.Provider, { value, children });
|
|
1631
|
-
};
|
|
1632
|
-
var useToPurchase = () => {
|
|
1633
|
-
const context = (0, import_react10.useContext)(ToPurchaseContext);
|
|
1634
|
-
if (!context) throw new Error("useToPurchase must be used within a ToPurchaseProvider");
|
|
1635
|
-
return context;
|
|
1636
|
-
};
|
|
1637
1624
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1638
1625
|
0 && (module.exports = {
|
|
1639
1626
|
AuthProvider,
|
|
@@ -1644,7 +1631,6 @@ var useToPurchase = () => {
|
|
|
1644
1631
|
StorageItemProvider,
|
|
1645
1632
|
StorageMemberProvider,
|
|
1646
1633
|
StorageProvider,
|
|
1647
|
-
ToPurchaseProvider,
|
|
1648
1634
|
UserProvider,
|
|
1649
1635
|
buildAuthHeaders,
|
|
1650
1636
|
normalizeBaseUrl,
|
|
@@ -1658,7 +1644,6 @@ var useToPurchase = () => {
|
|
|
1658
1644
|
useStorageItems,
|
|
1659
1645
|
useStorageMembers,
|
|
1660
1646
|
useStorages,
|
|
1661
|
-
useToPurchase,
|
|
1662
1647
|
useUsers
|
|
1663
1648
|
});
|
|
1664
1649
|
//# sourceMappingURL=index.cjs.js.map
|