shelflife-react-hooks 1.0.16 → 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 +93 -48
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +7 -20
- package/dist/index.d.ts +7 -20
- package/dist/index.esm.js +93 -46
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/context/ShoppingListContext.tsx +14 -2
- package/src/context/StorageItemContext.tsx +22 -1
- package/src/context/api/shoppingListApi.ts +38 -1
- package/src/context/api/storageItemApi.ts +63 -0
- 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);
|
|
@@ -1148,6 +1146,36 @@ var fetchAboutToExpireRequest = async (config, storageId) => runWithRequestState
|
|
|
1148
1146
|
}
|
|
1149
1147
|
return [];
|
|
1150
1148
|
});
|
|
1149
|
+
var fetchAggregatedExpiredRequest = async (config) => runWithRequestState(config, async () => {
|
|
1150
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1151
|
+
const response = await fetch(`${normalizedBaseUrl}/api/expired`, {
|
|
1152
|
+
headers: buildAuthHeaders(config.token)
|
|
1153
|
+
});
|
|
1154
|
+
if (!response.ok) {
|
|
1155
|
+
throw new Error("Failed to fetch expired items");
|
|
1156
|
+
}
|
|
1157
|
+
const payload = await readJson(response);
|
|
1158
|
+
if (payload) {
|
|
1159
|
+
config.setExpiredItems(payload);
|
|
1160
|
+
return payload;
|
|
1161
|
+
}
|
|
1162
|
+
return [];
|
|
1163
|
+
});
|
|
1164
|
+
var fetchAggregatedAboutToExpireRequest = async (config) => runWithRequestState(config, async () => {
|
|
1165
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1166
|
+
const response = await fetch(`${normalizedBaseUrl}/api/abouttoexpire`, {
|
|
1167
|
+
headers: buildAuthHeaders(config.token)
|
|
1168
|
+
});
|
|
1169
|
+
if (!response.ok) {
|
|
1170
|
+
throw new Error("Failed to fetch items about to expire");
|
|
1171
|
+
}
|
|
1172
|
+
const payload = await readJson(response);
|
|
1173
|
+
if (payload) {
|
|
1174
|
+
config.setAboutToExpireItems(payload);
|
|
1175
|
+
return payload;
|
|
1176
|
+
}
|
|
1177
|
+
return [];
|
|
1178
|
+
});
|
|
1151
1179
|
var fetchRunningLowRequest = async (config, storageId) => runWithRequestState(config, async () => {
|
|
1152
1180
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1153
1181
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/runninglow`, {
|
|
@@ -1163,6 +1191,21 @@ var fetchRunningLowRequest = async (config, storageId) => runWithRequestState(co
|
|
|
1163
1191
|
}
|
|
1164
1192
|
return [];
|
|
1165
1193
|
});
|
|
1194
|
+
var fetchAggregatedRunningLowRequest = async (config) => runWithRequestState(config, async () => {
|
|
1195
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1196
|
+
const response = await fetch(`${normalizedBaseUrl}/api/runninglow`, {
|
|
1197
|
+
headers: buildAuthHeaders(config.token)
|
|
1198
|
+
});
|
|
1199
|
+
if (!response.ok) {
|
|
1200
|
+
throw new Error("Failed to fetch running low items");
|
|
1201
|
+
}
|
|
1202
|
+
const payload = await readJson(response);
|
|
1203
|
+
if (payload) {
|
|
1204
|
+
config.setRunningLow(payload);
|
|
1205
|
+
return payload;
|
|
1206
|
+
}
|
|
1207
|
+
return [];
|
|
1208
|
+
});
|
|
1166
1209
|
|
|
1167
1210
|
// src/context/StorageItemContext.tsx
|
|
1168
1211
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
@@ -1204,14 +1247,26 @@ var StorageItemProvider = ({ baseUrl, children }) => {
|
|
|
1204
1247
|
(storageId) => fetchExpiredRequest(apiConfig, storageId),
|
|
1205
1248
|
[apiConfig]
|
|
1206
1249
|
);
|
|
1250
|
+
const fetchExpiredAggregated = (0, import_react6.useCallback)(
|
|
1251
|
+
() => fetchAggregatedExpiredRequest(apiConfig),
|
|
1252
|
+
[apiConfig]
|
|
1253
|
+
);
|
|
1207
1254
|
const fetchAboutToExpire = (0, import_react6.useCallback)(
|
|
1208
1255
|
(storageId) => fetchAboutToExpireRequest(apiConfig, storageId),
|
|
1209
1256
|
[apiConfig]
|
|
1210
1257
|
);
|
|
1258
|
+
const fetchAboutToExpireAggregated = (0, import_react6.useCallback)(
|
|
1259
|
+
() => fetchAggregatedAboutToExpireRequest(apiConfig),
|
|
1260
|
+
[apiConfig]
|
|
1261
|
+
);
|
|
1211
1262
|
const fetchRunningLow = (0, import_react6.useCallback)(
|
|
1212
1263
|
(storageId) => fetchRunningLowRequest(apiConfig, storageId),
|
|
1213
1264
|
[apiConfig]
|
|
1214
1265
|
);
|
|
1266
|
+
const fetchRunningLowAggregated = (0, import_react6.useCallback)(
|
|
1267
|
+
() => fetchAggregatedRunningLowRequest(apiConfig),
|
|
1268
|
+
[apiConfig]
|
|
1269
|
+
);
|
|
1215
1270
|
const value = (0, import_react6.useMemo)(() => ({
|
|
1216
1271
|
items,
|
|
1217
1272
|
expiredItems,
|
|
@@ -1225,8 +1280,11 @@ var StorageItemProvider = ({ baseUrl, children }) => {
|
|
|
1225
1280
|
editItem,
|
|
1226
1281
|
deleteItem,
|
|
1227
1282
|
fetchExpired,
|
|
1283
|
+
fetchExpiredAggregated,
|
|
1228
1284
|
fetchAboutToExpire,
|
|
1229
|
-
|
|
1285
|
+
fetchAboutToExpireAggregated,
|
|
1286
|
+
fetchRunningLow,
|
|
1287
|
+
fetchRunningLowAggregated
|
|
1230
1288
|
}), [
|
|
1231
1289
|
aboutToExpireItems,
|
|
1232
1290
|
addItem,
|
|
@@ -1448,6 +1506,31 @@ var fetchShoppingListRequest = async (config, storageId) => runWithRequestState(
|
|
|
1448
1506
|
}
|
|
1449
1507
|
return [];
|
|
1450
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
|
+
});
|
|
1451
1534
|
var createShoppingItemRequest = async (config, storageId, dto) => runWithRequestState(config, async () => {
|
|
1452
1535
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1453
1536
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist`, {
|
|
@@ -1515,6 +1598,9 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1515
1598
|
const fetchItems = (0, import_react9.useCallback)(async (storageId) => {
|
|
1516
1599
|
return fetchShoppingListRequest(apiConfig, storageId);
|
|
1517
1600
|
}, [apiConfig]);
|
|
1601
|
+
const createStorageItemsWithShoppingListItem = (0, import_react9.useCallback)(async (storageId, itemId) => {
|
|
1602
|
+
return createStorageItemsWithShoppingListItemRequest(apiConfig, storageId, itemId);
|
|
1603
|
+
}, [apiConfig]);
|
|
1518
1604
|
const createItem = (0, import_react9.useCallback)(async (storageId, dto) => {
|
|
1519
1605
|
return createShoppingItemRequest(apiConfig, storageId, dto);
|
|
1520
1606
|
}, [apiConfig]);
|
|
@@ -1524,7 +1610,10 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1524
1610
|
const deleteItem = (0, import_react9.useCallback)(async (storageId, itemId) => {
|
|
1525
1611
|
return deleteShoppingItemRequest(apiConfig, storageId, itemId);
|
|
1526
1612
|
}, [apiConfig]);
|
|
1527
|
-
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]);
|
|
1528
1617
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ShoppingListContext.Provider, { value, children });
|
|
1529
1618
|
};
|
|
1530
1619
|
var useShoppingList = () => {
|
|
@@ -1532,48 +1621,6 @@ var useShoppingList = () => {
|
|
|
1532
1621
|
if (!context) throw new Error("useShoppingList must be used within a ShoppingListProvider");
|
|
1533
1622
|
return context;
|
|
1534
1623
|
};
|
|
1535
|
-
|
|
1536
|
-
// src/context/ToPurchaseContext.tsx
|
|
1537
|
-
var import_react10 = require("react");
|
|
1538
|
-
|
|
1539
|
-
// src/context/api/toPurchaseApi.ts
|
|
1540
|
-
var fetchAggregatedShoppingRequest = async (config) => runWithRequestState(config, async () => {
|
|
1541
|
-
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1542
|
-
const response = await fetch(`${normalizedBaseUrl}/api/tobuy/shopping`, {
|
|
1543
|
-
headers: buildAuthHeaders(config.token)
|
|
1544
|
-
});
|
|
1545
|
-
if (!response.ok) {
|
|
1546
|
-
throw new Error("Failed to fetch aggregated shopping list");
|
|
1547
|
-
}
|
|
1548
|
-
const payload = await readJson(response);
|
|
1549
|
-
if (payload) {
|
|
1550
|
-
config.setToPurchase(payload);
|
|
1551
|
-
return payload;
|
|
1552
|
-
}
|
|
1553
|
-
return [];
|
|
1554
|
-
});
|
|
1555
|
-
|
|
1556
|
-
// src/context/ToPurchaseContext.tsx
|
|
1557
|
-
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1558
|
-
var ToPurchaseContext = (0, import_react10.createContext)(void 0);
|
|
1559
|
-
var ToPurchaseProvider = ({ baseUrl, children }) => {
|
|
1560
|
-
const { token } = useAuth();
|
|
1561
|
-
const [items, setItems] = (0, import_react10.useState)([]);
|
|
1562
|
-
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
1563
|
-
const [isError, setIsError] = (0, import_react10.useState)(false);
|
|
1564
|
-
const [error, setError] = (0, import_react10.useState)(null);
|
|
1565
|
-
const apiConfig = { baseUrl, token, setToPurchase: setItems, setIsLoading, setIsError, setError };
|
|
1566
|
-
const fetchAggregated = (0, import_react10.useCallback)(async () => {
|
|
1567
|
-
return fetchAggregatedShoppingRequest(apiConfig);
|
|
1568
|
-
}, [apiConfig]);
|
|
1569
|
-
const value = (0, import_react10.useMemo)(() => ({ items, isLoading, isError, error, fetchAggregated }), [items, isLoading, isError, error, fetchAggregated]);
|
|
1570
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ToPurchaseContext.Provider, { value, children });
|
|
1571
|
-
};
|
|
1572
|
-
var useToPurchase = () => {
|
|
1573
|
-
const context = (0, import_react10.useContext)(ToPurchaseContext);
|
|
1574
|
-
if (!context) throw new Error("useToPurchase must be used within a ToPurchaseProvider");
|
|
1575
|
-
return context;
|
|
1576
|
-
};
|
|
1577
1624
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1578
1625
|
0 && (module.exports = {
|
|
1579
1626
|
AuthProvider,
|
|
@@ -1584,7 +1631,6 @@ var useToPurchase = () => {
|
|
|
1584
1631
|
StorageItemProvider,
|
|
1585
1632
|
StorageMemberProvider,
|
|
1586
1633
|
StorageProvider,
|
|
1587
|
-
ToPurchaseProvider,
|
|
1588
1634
|
UserProvider,
|
|
1589
1635
|
buildAuthHeaders,
|
|
1590
1636
|
normalizeBaseUrl,
|
|
@@ -1598,7 +1644,6 @@ var useToPurchase = () => {
|
|
|
1598
1644
|
useStorageItems,
|
|
1599
1645
|
useStorageMembers,
|
|
1600
1646
|
useStorages,
|
|
1601
|
-
useToPurchase,
|
|
1602
1647
|
useUsers
|
|
1603
1648
|
});
|
|
1604
1649
|
//# sourceMappingURL=index.cjs.js.map
|