shelflife-react-hooks 1.0.17 → 1.0.19
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 +33 -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 +33 -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 +40 -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,32 @@ 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
|
+
config.setItems((previous) => previous.filter((i) => i.id !== itemId));
|
|
1534
|
+
});
|
|
1511
1535
|
var createShoppingItemRequest = async (config, storageId, dto) => runWithRequestState(config, async () => {
|
|
1512
1536
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1513
1537
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist`, {
|
|
@@ -1575,6 +1599,9 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1575
1599
|
const fetchItems = (0, import_react9.useCallback)(async (storageId) => {
|
|
1576
1600
|
return fetchShoppingListRequest(apiConfig, storageId);
|
|
1577
1601
|
}, [apiConfig]);
|
|
1602
|
+
const createStorageItemsWithShoppingListItem = (0, import_react9.useCallback)(async (storageId, itemId) => {
|
|
1603
|
+
return createStorageItemsWithShoppingListItemRequest(apiConfig, storageId, itemId);
|
|
1604
|
+
}, [apiConfig]);
|
|
1578
1605
|
const createItem = (0, import_react9.useCallback)(async (storageId, dto) => {
|
|
1579
1606
|
return createShoppingItemRequest(apiConfig, storageId, dto);
|
|
1580
1607
|
}, [apiConfig]);
|
|
@@ -1584,7 +1611,10 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1584
1611
|
const deleteItem = (0, import_react9.useCallback)(async (storageId, itemId) => {
|
|
1585
1612
|
return deleteShoppingItemRequest(apiConfig, storageId, itemId);
|
|
1586
1613
|
}, [apiConfig]);
|
|
1587
|
-
const
|
|
1614
|
+
const fetchAggregated = (0, import_react9.useCallback)(async () => {
|
|
1615
|
+
return fetchAggregatedShoppingListRequest(apiConfig);
|
|
1616
|
+
}, [apiConfig]);
|
|
1617
|
+
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
1618
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ShoppingListContext.Provider, { value, children });
|
|
1589
1619
|
};
|
|
1590
1620
|
var useShoppingList = () => {
|
|
@@ -1592,48 +1622,6 @@ var useShoppingList = () => {
|
|
|
1592
1622
|
if (!context) throw new Error("useShoppingList must be used within a ShoppingListProvider");
|
|
1593
1623
|
return context;
|
|
1594
1624
|
};
|
|
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
1625
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1638
1626
|
0 && (module.exports = {
|
|
1639
1627
|
AuthProvider,
|
|
@@ -1644,7 +1632,6 @@ var useToPurchase = () => {
|
|
|
1644
1632
|
StorageItemProvider,
|
|
1645
1633
|
StorageMemberProvider,
|
|
1646
1634
|
StorageProvider,
|
|
1647
|
-
ToPurchaseProvider,
|
|
1648
1635
|
UserProvider,
|
|
1649
1636
|
buildAuthHeaders,
|
|
1650
1637
|
normalizeBaseUrl,
|
|
@@ -1658,7 +1645,6 @@ var useToPurchase = () => {
|
|
|
1658
1645
|
useStorageItems,
|
|
1659
1646
|
useStorageMembers,
|
|
1660
1647
|
useStorages,
|
|
1661
|
-
useToPurchase,
|
|
1662
1648
|
useUsers
|
|
1663
1649
|
});
|
|
1664
1650
|
//# sourceMappingURL=index.cjs.js.map
|