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.d.cts
CHANGED
|
@@ -33,6 +33,7 @@ type Product = {
|
|
|
33
33
|
};
|
|
34
34
|
type StorageItem = {
|
|
35
35
|
id: number;
|
|
36
|
+
storage: Storage;
|
|
36
37
|
product: Product;
|
|
37
38
|
expiresAt: string;
|
|
38
39
|
createdAt: string;
|
|
@@ -61,11 +62,6 @@ type ShoppingListItem = {
|
|
|
61
62
|
product: Product;
|
|
62
63
|
amountToBuy: number;
|
|
63
64
|
};
|
|
64
|
-
type ToPurchaseItem = {
|
|
65
|
-
productId: number;
|
|
66
|
-
productName: string;
|
|
67
|
-
amountToBuy: number;
|
|
68
|
-
};
|
|
69
65
|
|
|
70
66
|
type LoginRequest = {
|
|
71
67
|
email: string;
|
|
@@ -335,8 +331,11 @@ type StorageItemContextValue = {
|
|
|
335
331
|
editItem: (storageId: number, itemId: number, dto: EditItemRequest) => Promise<StorageItem>;
|
|
336
332
|
deleteItem: (storageId: number, itemId: number) => Promise<void>;
|
|
337
333
|
fetchExpired: (storageId: number) => Promise<StorageItem[]>;
|
|
334
|
+
fetchExpiredAggregated: () => Promise<StorageItem[]>;
|
|
338
335
|
fetchAboutToExpire: (storageId: number) => Promise<StorageItem[]>;
|
|
336
|
+
fetchAboutToExpireAggregated: () => Promise<StorageItem[]>;
|
|
339
337
|
fetchRunningLow: (storageId: number) => Promise<RunningLowNotification[]>;
|
|
338
|
+
fetchRunningLowAggregated: () => Promise<RunningLowNotification[]>;
|
|
340
339
|
};
|
|
341
340
|
type StorageItemProviderProps = {
|
|
342
341
|
baseUrl: string;
|
|
@@ -386,6 +385,8 @@ type ShoppingListContextValue = {
|
|
|
386
385
|
isLoading: boolean;
|
|
387
386
|
isError: boolean;
|
|
388
387
|
error: Error | null;
|
|
388
|
+
createStorageItemsWithShoppingListItem: (storageId: number, itemId: number) => Promise<void>;
|
|
389
|
+
fetchAggregated: () => Promise<ShoppingListItem[]>;
|
|
389
390
|
fetchItems: (storageId: number) => Promise<ShoppingListItem[]>;
|
|
390
391
|
createItem: (storageId: number, dto: CreateShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
391
392
|
editItem: (storageId: number, itemId: number, dto: EditShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
@@ -398,18 +399,4 @@ type ShoppingListProviderProps = {
|
|
|
398
399
|
declare const ShoppingListProvider: ({ baseUrl, children }: ShoppingListProviderProps) => react_jsx_runtime.JSX.Element;
|
|
399
400
|
declare const useShoppingList: () => ShoppingListContextValue;
|
|
400
401
|
|
|
401
|
-
type
|
|
402
|
-
items: ToPurchaseItem[];
|
|
403
|
-
isLoading: boolean;
|
|
404
|
-
isError: boolean;
|
|
405
|
-
error: Error | null;
|
|
406
|
-
fetchAggregated: () => Promise<ToPurchaseItem[]>;
|
|
407
|
-
};
|
|
408
|
-
type ToPurchaseProviderProps = {
|
|
409
|
-
baseUrl: string;
|
|
410
|
-
children: React.ReactNode;
|
|
411
|
-
};
|
|
412
|
-
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
413
|
-
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
414
|
-
|
|
415
|
-
export { type AddItemError, type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateShoppingItemError, type CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemError, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemError, type EditShoppingItemRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberError, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type PaginatedResponse, type Product, type ProductCreateError, ProductProvider, type RunningLowNotification, RunningLowProvider, type RunningLowSetting, type ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type ToPurchaseItem, ToPurchaseProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useToPurchase, useUsers };
|
|
402
|
+
export { type AddItemError, type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateShoppingItemError, type CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemError, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemError, type EditShoppingItemRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberError, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type PaginatedResponse, type Product, type ProductCreateError, ProductProvider, type RunningLowNotification, RunningLowProvider, type RunningLowSetting, type ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useUsers };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ type Product = {
|
|
|
33
33
|
};
|
|
34
34
|
type StorageItem = {
|
|
35
35
|
id: number;
|
|
36
|
+
storage: Storage;
|
|
36
37
|
product: Product;
|
|
37
38
|
expiresAt: string;
|
|
38
39
|
createdAt: string;
|
|
@@ -61,11 +62,6 @@ type ShoppingListItem = {
|
|
|
61
62
|
product: Product;
|
|
62
63
|
amountToBuy: number;
|
|
63
64
|
};
|
|
64
|
-
type ToPurchaseItem = {
|
|
65
|
-
productId: number;
|
|
66
|
-
productName: string;
|
|
67
|
-
amountToBuy: number;
|
|
68
|
-
};
|
|
69
65
|
|
|
70
66
|
type LoginRequest = {
|
|
71
67
|
email: string;
|
|
@@ -335,8 +331,11 @@ type StorageItemContextValue = {
|
|
|
335
331
|
editItem: (storageId: number, itemId: number, dto: EditItemRequest) => Promise<StorageItem>;
|
|
336
332
|
deleteItem: (storageId: number, itemId: number) => Promise<void>;
|
|
337
333
|
fetchExpired: (storageId: number) => Promise<StorageItem[]>;
|
|
334
|
+
fetchExpiredAggregated: () => Promise<StorageItem[]>;
|
|
338
335
|
fetchAboutToExpire: (storageId: number) => Promise<StorageItem[]>;
|
|
336
|
+
fetchAboutToExpireAggregated: () => Promise<StorageItem[]>;
|
|
339
337
|
fetchRunningLow: (storageId: number) => Promise<RunningLowNotification[]>;
|
|
338
|
+
fetchRunningLowAggregated: () => Promise<RunningLowNotification[]>;
|
|
340
339
|
};
|
|
341
340
|
type StorageItemProviderProps = {
|
|
342
341
|
baseUrl: string;
|
|
@@ -386,6 +385,8 @@ type ShoppingListContextValue = {
|
|
|
386
385
|
isLoading: boolean;
|
|
387
386
|
isError: boolean;
|
|
388
387
|
error: Error | null;
|
|
388
|
+
createStorageItemsWithShoppingListItem: (storageId: number, itemId: number) => Promise<void>;
|
|
389
|
+
fetchAggregated: () => Promise<ShoppingListItem[]>;
|
|
389
390
|
fetchItems: (storageId: number) => Promise<ShoppingListItem[]>;
|
|
390
391
|
createItem: (storageId: number, dto: CreateShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
391
392
|
editItem: (storageId: number, itemId: number, dto: EditShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
@@ -398,18 +399,4 @@ type ShoppingListProviderProps = {
|
|
|
398
399
|
declare const ShoppingListProvider: ({ baseUrl, children }: ShoppingListProviderProps) => react_jsx_runtime.JSX.Element;
|
|
399
400
|
declare const useShoppingList: () => ShoppingListContextValue;
|
|
400
401
|
|
|
401
|
-
type
|
|
402
|
-
items: ToPurchaseItem[];
|
|
403
|
-
isLoading: boolean;
|
|
404
|
-
isError: boolean;
|
|
405
|
-
error: Error | null;
|
|
406
|
-
fetchAggregated: () => Promise<ToPurchaseItem[]>;
|
|
407
|
-
};
|
|
408
|
-
type ToPurchaseProviderProps = {
|
|
409
|
-
baseUrl: string;
|
|
410
|
-
children: React.ReactNode;
|
|
411
|
-
};
|
|
412
|
-
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
413
|
-
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
414
|
-
|
|
415
|
-
export { type AddItemError, type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateShoppingItemError, type CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemError, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemError, type EditShoppingItemRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberError, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type PaginatedResponse, type Product, type ProductCreateError, ProductProvider, type RunningLowNotification, RunningLowProvider, type RunningLowSetting, type ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type ToPurchaseItem, ToPurchaseProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useToPurchase, useUsers };
|
|
402
|
+
export { type AddItemError, type AddItemRequest, type AuthContextValue, AuthProvider, type BaseErrorResponse, type ChangePasswordErrorResponse, type ChangePasswordRequest, type ChangePasswordResponse, type ChangeStorageNameRequest, type ChangeUserDataRequest, type CreateProductRequest, type CreateRunningLowSettingError, type CreateSettingRequest, type CreateShoppingItemError, type CreateShoppingItemRequest, type CreateStorageError, type CreateStorageRequest, type EditItemError, type EditItemRequest, type EditRunningLowSettingError, type EditSettingRequest, type EditShoppingItemError, type EditShoppingItemRequest, type EmptyResponse, type ErrorResponse, type FieldErrorMap, type GetMeResponse, type ImageResponse, type InviteMemberError, type InviteMemberRequest, InviteProvider, type LoginErrorResponse, type LoginRequest, type LoginResponse, type LoginSuccessResponse, type LogoutErrorResponse, type LogoutResponse, type PaginatedResponse, type Product, type ProductCreateError, ProductProvider, type RunningLowNotification, RunningLowProvider, type RunningLowSetting, type ShoppingListItem, ShoppingListProvider, type SignupError, type SignupRequest, type SignupResponse, type Storage, type StorageItem, StorageItemProvider, type StorageMember, StorageMemberProvider, StorageProvider, type TokenStorage, type UpdateProductRequest, type UpdateUserError, type User, UserProvider, buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson, useAuth, useInvites, useProducts, useRunningLow, useShoppingList, useStorageItems, useStorageMembers, useStorages, useUsers };
|
package/dist/index.esm.js
CHANGED
|
@@ -1136,6 +1136,36 @@ var fetchAboutToExpireRequest = async (config, storageId) => runWithRequestState
|
|
|
1136
1136
|
}
|
|
1137
1137
|
return [];
|
|
1138
1138
|
});
|
|
1139
|
+
var fetchAggregatedExpiredRequest = async (config) => runWithRequestState(config, async () => {
|
|
1140
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1141
|
+
const response = await fetch(`${normalizedBaseUrl}/api/expired`, {
|
|
1142
|
+
headers: buildAuthHeaders(config.token)
|
|
1143
|
+
});
|
|
1144
|
+
if (!response.ok) {
|
|
1145
|
+
throw new Error("Failed to fetch expired items");
|
|
1146
|
+
}
|
|
1147
|
+
const payload = await readJson(response);
|
|
1148
|
+
if (payload) {
|
|
1149
|
+
config.setExpiredItems(payload);
|
|
1150
|
+
return payload;
|
|
1151
|
+
}
|
|
1152
|
+
return [];
|
|
1153
|
+
});
|
|
1154
|
+
var fetchAggregatedAboutToExpireRequest = async (config) => runWithRequestState(config, async () => {
|
|
1155
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1156
|
+
const response = await fetch(`${normalizedBaseUrl}/api/abouttoexpire`, {
|
|
1157
|
+
headers: buildAuthHeaders(config.token)
|
|
1158
|
+
});
|
|
1159
|
+
if (!response.ok) {
|
|
1160
|
+
throw new Error("Failed to fetch items about to expire");
|
|
1161
|
+
}
|
|
1162
|
+
const payload = await readJson(response);
|
|
1163
|
+
if (payload) {
|
|
1164
|
+
config.setAboutToExpireItems(payload);
|
|
1165
|
+
return payload;
|
|
1166
|
+
}
|
|
1167
|
+
return [];
|
|
1168
|
+
});
|
|
1139
1169
|
var fetchRunningLowRequest = async (config, storageId) => runWithRequestState(config, async () => {
|
|
1140
1170
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1141
1171
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/runninglow`, {
|
|
@@ -1151,6 +1181,21 @@ var fetchRunningLowRequest = async (config, storageId) => runWithRequestState(co
|
|
|
1151
1181
|
}
|
|
1152
1182
|
return [];
|
|
1153
1183
|
});
|
|
1184
|
+
var fetchAggregatedRunningLowRequest = async (config) => runWithRequestState(config, async () => {
|
|
1185
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1186
|
+
const response = await fetch(`${normalizedBaseUrl}/api/runninglow`, {
|
|
1187
|
+
headers: buildAuthHeaders(config.token)
|
|
1188
|
+
});
|
|
1189
|
+
if (!response.ok) {
|
|
1190
|
+
throw new Error("Failed to fetch running low items");
|
|
1191
|
+
}
|
|
1192
|
+
const payload = await readJson(response);
|
|
1193
|
+
if (payload) {
|
|
1194
|
+
config.setRunningLow(payload);
|
|
1195
|
+
return payload;
|
|
1196
|
+
}
|
|
1197
|
+
return [];
|
|
1198
|
+
});
|
|
1154
1199
|
|
|
1155
1200
|
// src/context/StorageItemContext.tsx
|
|
1156
1201
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
@@ -1192,14 +1237,26 @@ var StorageItemProvider = ({ baseUrl, children }) => {
|
|
|
1192
1237
|
(storageId) => fetchExpiredRequest(apiConfig, storageId),
|
|
1193
1238
|
[apiConfig]
|
|
1194
1239
|
);
|
|
1240
|
+
const fetchExpiredAggregated = useCallback6(
|
|
1241
|
+
() => fetchAggregatedExpiredRequest(apiConfig),
|
|
1242
|
+
[apiConfig]
|
|
1243
|
+
);
|
|
1195
1244
|
const fetchAboutToExpire = useCallback6(
|
|
1196
1245
|
(storageId) => fetchAboutToExpireRequest(apiConfig, storageId),
|
|
1197
1246
|
[apiConfig]
|
|
1198
1247
|
);
|
|
1248
|
+
const fetchAboutToExpireAggregated = useCallback6(
|
|
1249
|
+
() => fetchAggregatedAboutToExpireRequest(apiConfig),
|
|
1250
|
+
[apiConfig]
|
|
1251
|
+
);
|
|
1199
1252
|
const fetchRunningLow = useCallback6(
|
|
1200
1253
|
(storageId) => fetchRunningLowRequest(apiConfig, storageId),
|
|
1201
1254
|
[apiConfig]
|
|
1202
1255
|
);
|
|
1256
|
+
const fetchRunningLowAggregated = useCallback6(
|
|
1257
|
+
() => fetchAggregatedRunningLowRequest(apiConfig),
|
|
1258
|
+
[apiConfig]
|
|
1259
|
+
);
|
|
1203
1260
|
const value = useMemo6(() => ({
|
|
1204
1261
|
items,
|
|
1205
1262
|
expiredItems,
|
|
@@ -1213,8 +1270,11 @@ var StorageItemProvider = ({ baseUrl, children }) => {
|
|
|
1213
1270
|
editItem,
|
|
1214
1271
|
deleteItem,
|
|
1215
1272
|
fetchExpired,
|
|
1273
|
+
fetchExpiredAggregated,
|
|
1216
1274
|
fetchAboutToExpire,
|
|
1217
|
-
|
|
1275
|
+
fetchAboutToExpireAggregated,
|
|
1276
|
+
fetchRunningLow,
|
|
1277
|
+
fetchRunningLowAggregated
|
|
1218
1278
|
}), [
|
|
1219
1279
|
aboutToExpireItems,
|
|
1220
1280
|
addItem,
|
|
@@ -1448,6 +1508,31 @@ var fetchShoppingListRequest = async (config, storageId) => runWithRequestState(
|
|
|
1448
1508
|
}
|
|
1449
1509
|
return [];
|
|
1450
1510
|
});
|
|
1511
|
+
var fetchAggregatedShoppingListRequest = async (config) => runWithRequestState(config, async () => {
|
|
1512
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1513
|
+
const response = await fetch(`${normalizedBaseUrl}/api/shoppinglist`, {
|
|
1514
|
+
headers: buildAuthHeaders(config.token)
|
|
1515
|
+
});
|
|
1516
|
+
if (!response.ok) {
|
|
1517
|
+
throw new Error("Failed to fetch aggregated shopping list");
|
|
1518
|
+
}
|
|
1519
|
+
const payload = await readJson(response);
|
|
1520
|
+
if (payload) {
|
|
1521
|
+
config.setItems(payload);
|
|
1522
|
+
return payload;
|
|
1523
|
+
}
|
|
1524
|
+
return [];
|
|
1525
|
+
});
|
|
1526
|
+
var createStorageItemsWithShoppingListItemRequest = async (config, storageId, itemId) => runWithRequestState(config, async () => {
|
|
1527
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1528
|
+
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist/${itemId}`, {
|
|
1529
|
+
method: "POST",
|
|
1530
|
+
headers: buildAuthHeaders(config.token)
|
|
1531
|
+
});
|
|
1532
|
+
if (!response.ok) {
|
|
1533
|
+
throw new Error("Failed to add items");
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1451
1536
|
var createShoppingItemRequest = async (config, storageId, dto) => runWithRequestState(config, async () => {
|
|
1452
1537
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1453
1538
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist`, {
|
|
@@ -1515,6 +1600,9 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1515
1600
|
const fetchItems = useCallback9(async (storageId) => {
|
|
1516
1601
|
return fetchShoppingListRequest(apiConfig, storageId);
|
|
1517
1602
|
}, [apiConfig]);
|
|
1603
|
+
const createStorageItemsWithShoppingListItem = useCallback9(async (storageId, itemId) => {
|
|
1604
|
+
return createStorageItemsWithShoppingListItemRequest(apiConfig, storageId, itemId);
|
|
1605
|
+
}, [apiConfig]);
|
|
1518
1606
|
const createItem = useCallback9(async (storageId, dto) => {
|
|
1519
1607
|
return createShoppingItemRequest(apiConfig, storageId, dto);
|
|
1520
1608
|
}, [apiConfig]);
|
|
@@ -1524,7 +1612,10 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1524
1612
|
const deleteItem = useCallback9(async (storageId, itemId) => {
|
|
1525
1613
|
return deleteShoppingItemRequest(apiConfig, storageId, itemId);
|
|
1526
1614
|
}, [apiConfig]);
|
|
1527
|
-
const
|
|
1615
|
+
const fetchAggregated = useCallback9(async () => {
|
|
1616
|
+
return fetchAggregatedShoppingListRequest(apiConfig);
|
|
1617
|
+
}, [apiConfig]);
|
|
1618
|
+
const value = useMemo9(() => ({ items, isLoading, isError, error, fetchItems, createItem, editItem, deleteItem, createStorageItemsWithShoppingListItem, fetchAggregated }), [items, isLoading, isError, error, fetchItems, createItem, editItem, deleteItem, createStorageItemsWithShoppingListItem, fetchAggregated]);
|
|
1528
1619
|
return /* @__PURE__ */ jsx9(ShoppingListContext.Provider, { value, children });
|
|
1529
1620
|
};
|
|
1530
1621
|
var useShoppingList = () => {
|
|
@@ -1532,48 +1623,6 @@ var useShoppingList = () => {
|
|
|
1532
1623
|
if (!context) throw new Error("useShoppingList must be used within a ShoppingListProvider");
|
|
1533
1624
|
return context;
|
|
1534
1625
|
};
|
|
1535
|
-
|
|
1536
|
-
// src/context/ToPurchaseContext.tsx
|
|
1537
|
-
import { createContext as createContext10, useCallback as useCallback10, useContext as useContext10, useMemo as useMemo10, useState as useState10 } from "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
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1558
|
-
var ToPurchaseContext = createContext10(void 0);
|
|
1559
|
-
var ToPurchaseProvider = ({ baseUrl, children }) => {
|
|
1560
|
-
const { token } = useAuth();
|
|
1561
|
-
const [items, setItems] = useState10([]);
|
|
1562
|
-
const [isLoading, setIsLoading] = useState10(false);
|
|
1563
|
-
const [isError, setIsError] = useState10(false);
|
|
1564
|
-
const [error, setError] = useState10(null);
|
|
1565
|
-
const apiConfig = { baseUrl, token, setToPurchase: setItems, setIsLoading, setIsError, setError };
|
|
1566
|
-
const fetchAggregated = useCallback10(async () => {
|
|
1567
|
-
return fetchAggregatedShoppingRequest(apiConfig);
|
|
1568
|
-
}, [apiConfig]);
|
|
1569
|
-
const value = useMemo10(() => ({ items, isLoading, isError, error, fetchAggregated }), [items, isLoading, isError, error, fetchAggregated]);
|
|
1570
|
-
return /* @__PURE__ */ jsx10(ToPurchaseContext.Provider, { value, children });
|
|
1571
|
-
};
|
|
1572
|
-
var useToPurchase = () => {
|
|
1573
|
-
const context = useContext10(ToPurchaseContext);
|
|
1574
|
-
if (!context) throw new Error("useToPurchase must be used within a ToPurchaseProvider");
|
|
1575
|
-
return context;
|
|
1576
|
-
};
|
|
1577
1626
|
export {
|
|
1578
1627
|
AuthProvider,
|
|
1579
1628
|
InviteProvider,
|
|
@@ -1583,7 +1632,6 @@ export {
|
|
|
1583
1632
|
StorageItemProvider,
|
|
1584
1633
|
StorageMemberProvider,
|
|
1585
1634
|
StorageProvider,
|
|
1586
|
-
ToPurchaseProvider,
|
|
1587
1635
|
UserProvider,
|
|
1588
1636
|
buildAuthHeaders,
|
|
1589
1637
|
normalizeBaseUrl,
|
|
@@ -1597,7 +1645,6 @@ export {
|
|
|
1597
1645
|
useStorageItems,
|
|
1598
1646
|
useStorageMembers,
|
|
1599
1647
|
useStorages,
|
|
1600
|
-
useToPurchase,
|
|
1601
1648
|
useUsers
|
|
1602
1649
|
};
|
|
1603
1650
|
//# sourceMappingURL=index.esm.js.map
|