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.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;
|
|
@@ -389,6 +385,8 @@ type ShoppingListContextValue = {
|
|
|
389
385
|
isLoading: boolean;
|
|
390
386
|
isError: boolean;
|
|
391
387
|
error: Error | null;
|
|
388
|
+
createStorageItemsWithShoppingListItem: (storageId: number, itemId: number) => Promise<void>;
|
|
389
|
+
fetchAggregated: () => Promise<ShoppingListItem[]>;
|
|
392
390
|
fetchItems: (storageId: number) => Promise<ShoppingListItem[]>;
|
|
393
391
|
createItem: (storageId: number, dto: CreateShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
394
392
|
editItem: (storageId: number, itemId: number, dto: EditShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
@@ -401,18 +399,4 @@ type ShoppingListProviderProps = {
|
|
|
401
399
|
declare const ShoppingListProvider: ({ baseUrl, children }: ShoppingListProviderProps) => react_jsx_runtime.JSX.Element;
|
|
402
400
|
declare const useShoppingList: () => ShoppingListContextValue;
|
|
403
401
|
|
|
404
|
-
type
|
|
405
|
-
items: ToPurchaseItem[];
|
|
406
|
-
isLoading: boolean;
|
|
407
|
-
isError: boolean;
|
|
408
|
-
error: Error | null;
|
|
409
|
-
fetchAggregated: () => Promise<ToPurchaseItem[]>;
|
|
410
|
-
};
|
|
411
|
-
type ToPurchaseProviderProps = {
|
|
412
|
-
baseUrl: string;
|
|
413
|
-
children: React.ReactNode;
|
|
414
|
-
};
|
|
415
|
-
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
416
|
-
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
417
|
-
|
|
418
|
-
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;
|
|
@@ -389,6 +385,8 @@ type ShoppingListContextValue = {
|
|
|
389
385
|
isLoading: boolean;
|
|
390
386
|
isError: boolean;
|
|
391
387
|
error: Error | null;
|
|
388
|
+
createStorageItemsWithShoppingListItem: (storageId: number, itemId: number) => Promise<void>;
|
|
389
|
+
fetchAggregated: () => Promise<ShoppingListItem[]>;
|
|
392
390
|
fetchItems: (storageId: number) => Promise<ShoppingListItem[]>;
|
|
393
391
|
createItem: (storageId: number, dto: CreateShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
394
392
|
editItem: (storageId: number, itemId: number, dto: EditShoppingItemRequest) => Promise<ShoppingListItem>;
|
|
@@ -401,18 +399,4 @@ type ShoppingListProviderProps = {
|
|
|
401
399
|
declare const ShoppingListProvider: ({ baseUrl, children }: ShoppingListProviderProps) => react_jsx_runtime.JSX.Element;
|
|
402
400
|
declare const useShoppingList: () => ShoppingListContextValue;
|
|
403
401
|
|
|
404
|
-
type
|
|
405
|
-
items: ToPurchaseItem[];
|
|
406
|
-
isLoading: boolean;
|
|
407
|
-
isError: boolean;
|
|
408
|
-
error: Error | null;
|
|
409
|
-
fetchAggregated: () => Promise<ToPurchaseItem[]>;
|
|
410
|
-
};
|
|
411
|
-
type ToPurchaseProviderProps = {
|
|
412
|
-
baseUrl: string;
|
|
413
|
-
children: React.ReactNode;
|
|
414
|
-
};
|
|
415
|
-
declare const ToPurchaseProvider: ({ baseUrl, children }: ToPurchaseProviderProps) => react_jsx_runtime.JSX.Element;
|
|
416
|
-
declare const useToPurchase: () => ToPurchaseContextValue;
|
|
417
|
-
|
|
418
|
-
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
|
@@ -1508,6 +1508,32 @@ var fetchShoppingListRequest = async (config, storageId) => runWithRequestState(
|
|
|
1508
1508
|
}
|
|
1509
1509
|
return [];
|
|
1510
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
|
+
config.setItems((previous) => previous.filter((i) => i.id !== itemId));
|
|
1536
|
+
});
|
|
1511
1537
|
var createShoppingItemRequest = async (config, storageId, dto) => runWithRequestState(config, async () => {
|
|
1512
1538
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
1513
1539
|
const response = await fetch(`${normalizedBaseUrl}/api/storages/${storageId}/shoppinglist`, {
|
|
@@ -1575,6 +1601,9 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1575
1601
|
const fetchItems = useCallback9(async (storageId) => {
|
|
1576
1602
|
return fetchShoppingListRequest(apiConfig, storageId);
|
|
1577
1603
|
}, [apiConfig]);
|
|
1604
|
+
const createStorageItemsWithShoppingListItem = useCallback9(async (storageId, itemId) => {
|
|
1605
|
+
return createStorageItemsWithShoppingListItemRequest(apiConfig, storageId, itemId);
|
|
1606
|
+
}, [apiConfig]);
|
|
1578
1607
|
const createItem = useCallback9(async (storageId, dto) => {
|
|
1579
1608
|
return createShoppingItemRequest(apiConfig, storageId, dto);
|
|
1580
1609
|
}, [apiConfig]);
|
|
@@ -1584,7 +1613,10 @@ var ShoppingListProvider = ({ baseUrl, children }) => {
|
|
|
1584
1613
|
const deleteItem = useCallback9(async (storageId, itemId) => {
|
|
1585
1614
|
return deleteShoppingItemRequest(apiConfig, storageId, itemId);
|
|
1586
1615
|
}, [apiConfig]);
|
|
1587
|
-
const
|
|
1616
|
+
const fetchAggregated = useCallback9(async () => {
|
|
1617
|
+
return fetchAggregatedShoppingListRequest(apiConfig);
|
|
1618
|
+
}, [apiConfig]);
|
|
1619
|
+
const value = useMemo9(() => ({ items, isLoading, isError, error, fetchItems, createItem, editItem, deleteItem, createStorageItemsWithShoppingListItem, fetchAggregated }), [items, isLoading, isError, error, fetchItems, createItem, editItem, deleteItem, createStorageItemsWithShoppingListItem, fetchAggregated]);
|
|
1588
1620
|
return /* @__PURE__ */ jsx9(ShoppingListContext.Provider, { value, children });
|
|
1589
1621
|
};
|
|
1590
1622
|
var useShoppingList = () => {
|
|
@@ -1592,48 +1624,6 @@ var useShoppingList = () => {
|
|
|
1592
1624
|
if (!context) throw new Error("useShoppingList must be used within a ShoppingListProvider");
|
|
1593
1625
|
return context;
|
|
1594
1626
|
};
|
|
1595
|
-
|
|
1596
|
-
// src/context/ToPurchaseContext.tsx
|
|
1597
|
-
import { createContext as createContext10, useCallback as useCallback10, useContext as useContext10, useMemo as useMemo10, useState as useState10 } from "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
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1618
|
-
var ToPurchaseContext = createContext10(void 0);
|
|
1619
|
-
var ToPurchaseProvider = ({ baseUrl, children }) => {
|
|
1620
|
-
const { token } = useAuth();
|
|
1621
|
-
const [items, setItems] = useState10([]);
|
|
1622
|
-
const [isLoading, setIsLoading] = useState10(false);
|
|
1623
|
-
const [isError, setIsError] = useState10(false);
|
|
1624
|
-
const [error, setError] = useState10(null);
|
|
1625
|
-
const apiConfig = { baseUrl, token, setToPurchase: setItems, setIsLoading, setIsError, setError };
|
|
1626
|
-
const fetchAggregated = useCallback10(async () => {
|
|
1627
|
-
return fetchAggregatedShoppingRequest(apiConfig);
|
|
1628
|
-
}, [apiConfig]);
|
|
1629
|
-
const value = useMemo10(() => ({ items, isLoading, isError, error, fetchAggregated }), [items, isLoading, isError, error, fetchAggregated]);
|
|
1630
|
-
return /* @__PURE__ */ jsx10(ToPurchaseContext.Provider, { value, children });
|
|
1631
|
-
};
|
|
1632
|
-
var useToPurchase = () => {
|
|
1633
|
-
const context = useContext10(ToPurchaseContext);
|
|
1634
|
-
if (!context) throw new Error("useToPurchase must be used within a ToPurchaseProvider");
|
|
1635
|
-
return context;
|
|
1636
|
-
};
|
|
1637
1627
|
export {
|
|
1638
1628
|
AuthProvider,
|
|
1639
1629
|
InviteProvider,
|
|
@@ -1643,7 +1633,6 @@ export {
|
|
|
1643
1633
|
StorageItemProvider,
|
|
1644
1634
|
StorageMemberProvider,
|
|
1645
1635
|
StorageProvider,
|
|
1646
|
-
ToPurchaseProvider,
|
|
1647
1636
|
UserProvider,
|
|
1648
1637
|
buildAuthHeaders,
|
|
1649
1638
|
normalizeBaseUrl,
|
|
@@ -1657,7 +1646,6 @@ export {
|
|
|
1657
1646
|
useStorageItems,
|
|
1658
1647
|
useStorageMembers,
|
|
1659
1648
|
useStorages,
|
|
1660
|
-
useToPurchase,
|
|
1661
1649
|
useUsers
|
|
1662
1650
|
};
|
|
1663
1651
|
//# sourceMappingURL=index.esm.js.map
|