npm-pkg-hook 1.1.5 → 1.1.8

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.
Files changed (140) hide show
  1. package/.eslintrc.js +19 -113
  2. package/.eslintrc.json +127 -108
  3. package/next.config.js +2 -5
  4. package/package.json +27 -24
  5. package/src/config/client/errors.js +14 -14
  6. package/src/config/client/index.js +1 -1
  7. package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
  8. package/src/hooks/getCategoriesWithProduct/index.js +62 -0
  9. package/src/hooks/getSession/index.js +18 -18
  10. package/src/hooks/index.js +13 -9
  11. package/src/hooks/useAcumulateDate/index.js +1 -1
  12. package/src/hooks/useAnimationFrame/index.js +45 -45
  13. package/src/hooks/useAsideCart/helpers/index.js +22 -0
  14. package/src/hooks/useAsideCart/index.js +156 -0
  15. package/src/hooks/useAsideCart/queries.js +10 -0
  16. package/src/hooks/useBanner/index.js +11 -11
  17. package/src/hooks/useCart/index.js +2 -0
  18. package/src/hooks/useCart/queries.js +164 -0
  19. package/src/hooks/useCart/useCart/helpers/index.js +75 -0
  20. package/src/hooks/useCart/useCart/index.js +411 -0
  21. package/src/hooks/useCart/useGetCart/index.js +31 -0
  22. package/src/hooks/useCatWithProduct/index.js +15 -15
  23. package/src/hooks/useCatWithProduct/queries.js +1 -1
  24. package/src/hooks/useCatWithProductClient/index.js +48 -0
  25. package/src/hooks/useCatWithProductClient/queries.js +55 -0
  26. package/src/hooks/useCategoriesProduct/index.js +12 -12
  27. package/src/hooks/useCategoriesProduct/queries.js +16 -16
  28. package/src/hooks/useCategoryInStore/index.js +39 -36
  29. package/src/hooks/useCategoryInStore/queries.js +78 -78
  30. package/src/hooks/useCategoryStore/index.js +2 -2
  31. package/src/hooks/useChartData/index.js +159 -156
  32. package/src/hooks/useChartData/useChartData/index.js +199 -197
  33. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
  34. package/src/hooks/useCheckbox/index.js +115 -115
  35. package/src/hooks/useClients/index.js +12 -14
  36. package/src/hooks/useClients/queries.js +1 -1
  37. package/src/hooks/useConnection/index.js +20 -21
  38. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
  39. package/src/hooks/useCreateProduct/index.js +22 -19
  40. package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
  41. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
  42. package/src/hooks/useDessert/helpers/index.js +51 -51
  43. package/src/hooks/useDessert/index.js +56 -65
  44. package/src/hooks/useDevices/index.js +35 -36
  45. package/src/hooks/useDevices/queries.js +19 -19
  46. package/src/hooks/useDropzone/index.js +94 -79
  47. package/src/hooks/useDynamicAuth/index.js +13 -13
  48. package/src/hooks/useDynamicAuth/queries.js +24 -24
  49. package/src/hooks/useEmployee/queries.js +1 -1
  50. package/src/hooks/useEvent/index.js +33 -33
  51. package/src/hooks/useFavoriteStores/index.js +19 -0
  52. package/src/hooks/useFavoriteStores/queries.js +47 -0
  53. package/src/hooks/useFetchJson/index.js +25 -25
  54. package/src/hooks/useFingerprintjs/index.js +172 -176
  55. package/src/hooks/useFormTools/index.js +12 -11
  56. package/src/hooks/useFormatDate/index.js +20 -21
  57. package/src/hooks/useFormatNumberPhone/index.js +9 -9
  58. package/src/hooks/useFullScreenMode/index.js +65 -65
  59. package/src/hooks/useGenerateNumberArray/index.js +17 -17
  60. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
  61. package/src/hooks/useGetFoodRecomended/index.js +33 -0
  62. package/src/hooks/useGetFoodRecomended/queries.js +47 -0
  63. package/src/hooks/useGetMinPrice/index.js +8 -0
  64. package/src/hooks/useGetMinPrice/queries.js +7 -0
  65. package/src/hooks/useGetOneStoreRating/index.js +40 -0
  66. package/src/hooks/useGetOneStoreRating/queries.js +18 -0
  67. package/src/hooks/useGoogleLogin/index.js +160 -161
  68. package/src/hooks/useHover/index.js +29 -29
  69. package/src/hooks/useImageOptimization/index.js +15 -15
  70. package/src/hooks/useImageWeight/index.js +18 -19
  71. package/src/hooks/useImagesStore/index.js +139 -140
  72. package/src/hooks/useImagesStore/queries.js +19 -18
  73. package/src/hooks/useInnerHtml/index.js +39 -38
  74. package/src/hooks/useIntersection/index.js +4 -4
  75. package/src/hooks/useKeypress/index.js +28 -28
  76. package/src/hooks/useLazyScript/index.js +35 -36
  77. package/src/hooks/useLocalSorage/index.js +2 -2
  78. package/src/hooks/useLogout/index.js +23 -23
  79. package/src/hooks/useManageQueryParams/index.js +36 -37
  80. package/src/hooks/useMobile/index.js +39 -38
  81. package/src/hooks/useMutateHeight/index.js +15 -16
  82. package/src/hooks/useOrderClient/index.js +5 -0
  83. package/src/hooks/useOrders/index.js +10 -16
  84. package/src/hooks/useOrders/queries.js +1 -1
  85. package/src/hooks/useProductsFood/index.js +32 -32
  86. package/src/hooks/useProductsFood/queriesStore.js +49 -48
  87. package/src/hooks/useProductsFood/useEditProduct.js +2 -4
  88. package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
  89. package/src/hooks/useProviders/index.js +3 -3
  90. package/src/hooks/useProviders/queries.js +31 -31
  91. package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
  92. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
  93. package/src/hooks/useProvidersStore/index.js +24 -24
  94. package/src/hooks/useProvidersStore/queries.js +31 -31
  95. package/src/hooks/useRatingArrayData/index.js +54 -0
  96. package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
  97. package/src/hooks/useReactToPrint/index.js +1120 -1098
  98. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
  99. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
  100. package/src/hooks/useReport/index.js +9 -9
  101. package/src/hooks/useReport/queries.js +1 -1
  102. package/src/hooks/useRestaurant/index.js +19 -19
  103. package/src/hooks/useRestaurant/queries.js +80 -80
  104. package/src/hooks/useSales/index.js +476 -451
  105. package/src/hooks/useSales/queries.js +14 -15
  106. package/src/hooks/useSales/useGetAllSales/index.js +25 -25
  107. package/src/hooks/useSales/useTotalSales.js +18 -18
  108. package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
  109. package/src/hooks/useSaveAvailableProduct/index.js +16 -16
  110. package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
  111. package/src/hooks/useSchedule/index.js +33 -36
  112. package/src/hooks/useSchedule/index.jsx +22 -22
  113. package/src/hooks/useSchedule/queries.js +34 -35
  114. package/src/hooks/useScheduleData/index.js +123 -171
  115. package/src/hooks/useScroll/index.js +56 -57
  116. package/src/hooks/useScrollRotate/index.js +16 -14
  117. package/src/hooks/useSetSession/index.js +16 -16
  118. package/src/hooks/useSetState/index.js +3 -3
  119. package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
  120. package/src/hooks/useStatusOpenStore/index.js +172 -173
  121. package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
  122. package/src/hooks/useStatusOrdersClient/index.js +17 -0
  123. package/src/hooks/useStatusOrdersClient/queries.js +80 -0
  124. package/src/hooks/useStore/index.js +40 -25
  125. package/src/hooks/useStore/queries.js +162 -136
  126. package/src/hooks/useStoreCalendar/index.js +5 -7
  127. package/src/hooks/useStoreContacts/index.js +16 -16
  128. package/src/hooks/useStoreContacts/queries.js +1 -1
  129. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  130. package/src/hooks/useUpdateCart/index.js +34 -28
  131. package/src/hooks/useUpdateExistingOrders/index.js +35 -35
  132. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
  133. package/src/hooks/useUser/index.js +1 -1
  134. package/src/hooks/useUser/queries.js +1 -1
  135. package/src/hooks/useWindowSize/index.js +38 -38
  136. package/src/mock/dessert/index.js +16 -16
  137. package/src/mock/index.js +1 -2
  138. package/src/utils/index.js +42 -45
  139. package/src/hooks/useRatingData/index.js +0 -53
  140. package/src/hooks/useSalesClient/index.js +0 -1
@@ -0,0 +1,14 @@
1
+ import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useProductsFood/queriesStore'
2
+ import { useLazyQuery } from '@apollo/client'
3
+
4
+ export const useGetExtProductFoodsSubOptionalAll = ({ setDataOptional = () => { } } = {}) => {
5
+ const [ExtProductFoodsSubOptionalAll] = useLazyQuery(
6
+ GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
7
+ {
8
+ onError: () => {
9
+ setDataOptional([])
10
+ }
11
+ }
12
+ )
13
+ return [ExtProductFoodsSubOptionalAll]
14
+ }
@@ -0,0 +1,33 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_PRODUCT_STORE_RECOMENDED } from './queries'
3
+
4
+ export const useGetFoodRecomended = ({
5
+ name = ''
6
+ }) => {
7
+ console.log({ name })
8
+ const {
9
+ data,
10
+ called,
11
+ fetchMore,
12
+ loading,
13
+ error
14
+ } = useQuery(GET_ALL_PRODUCT_STORE_RECOMENDED, {
15
+ fetchPolicy: 'cache-and-network',
16
+ skip: !name,
17
+ notifyOnNetworkStatusChange: true,
18
+ nextFetchPolicy: 'cache-first',
19
+ refetchWritePolicy: 'merge',
20
+ variables:
21
+ {
22
+ max: 6,
23
+ search: name
24
+ }
25
+ })
26
+
27
+ return [data?.productFoodsAllRecommended, {
28
+ called,
29
+ fetchMore,
30
+ loading,
31
+ error
32
+ }]
33
+ }
@@ -0,0 +1,47 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ALL_PRODUCT_STORE_RECOMENDED = gql`
4
+ query productFoodsAllRecommended($search: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
5
+ productFoodsAllRecommended(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
6
+ pId
7
+ sizeId #Talla
8
+ colorId #Color
9
+ cId #Country
10
+ dId #Department
11
+ ctId #Cuidad
12
+ fId #Características
13
+ pName
14
+ ProPrice
15
+ ProDescuento
16
+ ProUniDisponibles
17
+ ProDescription
18
+ ProProtegido
19
+ ProAssurance
20
+ ProStar
21
+ sTateLogistic
22
+ ProImage
23
+ ProWidth
24
+ ProHeight
25
+ ProLength
26
+ ProWeight
27
+ ProQuantity
28
+ ProOutstanding
29
+ pDatCre
30
+ pDatMod
31
+ ProDelivery
32
+ ProVoltaje
33
+ pState
34
+ feat {
35
+ fId
36
+ thpId
37
+ hpqrQuestion
38
+ }
39
+ area {
40
+ aId
41
+ aName
42
+ }
43
+
44
+ }
45
+ }
46
+
47
+ `
@@ -0,0 +1,8 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_MIN_PEDIDO } from './queries'
3
+
4
+ export const useGetMinPrice = () => {
5
+ const { data, loading, error } = useQuery(GET_MIN_PEDIDO)
6
+
7
+ return [data, { loading, error }]
8
+ }
@@ -0,0 +1,7 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_MIN_PEDIDO = gql`
4
+ query getMinPrice($idStore: ID){
5
+ getMinPrice(idStore: $idStore)
6
+ }
7
+ `
@@ -0,0 +1,40 @@
1
+ import { useState } from 'react'
2
+ import { useLazyQuery } from '@apollo/client'
3
+ import { GET_ONE_RATING_STORE } from './queries'
4
+
5
+ export const useGetOneStoreRating = () => {
6
+ const [ratings, setRatings] = useState({
7
+ rGoodTemperature: 0,
8
+ rGoodCondition: 0,
9
+ rTasty: 0,
10
+ appearance: 0
11
+ })
12
+
13
+ const [getOneRating] = useLazyQuery(GET_ONE_RATING_STORE, {
14
+ onCompleted: res => {
15
+ if (res) {
16
+ setRatings((prevState) => {
17
+ const {
18
+ rGoodTemperature,
19
+ rGoodCondition,
20
+ rTasty,
21
+ rAppearance
22
+ } = res.getOneRating || {}
23
+ return {
24
+ ...prevState,
25
+ rGoodTemperature: rGoodTemperature || 0,
26
+ rGoodCondition: rGoodCondition || 0,
27
+ rTasty: rTasty || 0,
28
+ appearance: rAppearance || 0
29
+ }
30
+ })
31
+ }
32
+ }
33
+ })
34
+
35
+ return {
36
+ ratings,
37
+ setRatings,
38
+ getOneRating
39
+ }
40
+ }
@@ -0,0 +1,18 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ONE_RATING_STORE = gql`
4
+ query getOneRating($idStore: ID){
5
+ getOneRating(idStore: $idStore){
6
+ idStore
7
+ rId
8
+ id
9
+ rAppearance
10
+ rTasty
11
+ rGoodTemperature
12
+ rGoodCondition
13
+ rState
14
+ createAt
15
+ updateAt
16
+ }
17
+ }
18
+ `
@@ -1,161 +1,160 @@
1
- import { useState, useEffect } from 'react'
2
- import loadScript from './loadScript'
3
- import removeScript from './removeScript'
4
-
5
- export const useGoogleLogin = ({
6
- onSuccess = () => {},
7
- onAutoLoadFinished = () => {},
8
- onFailure = () => {},
9
- onRequest = () => {},
10
- onScriptLoadFailure,
11
- clientId,
12
- cookiePolicy,
13
- loginHint,
14
- hostedDomain,
15
- autoLoad,
16
- isSignedIn,
17
- fetchBasicProfile,
18
- redirectUri,
19
- discoveryDocs,
20
- uxMode,
21
- scope,
22
- accessType,
23
- responseType,
24
- jsSrc = 'https://apis.google.com/js/api.js',
25
- prompt
26
- }) => {
27
- const [loaded, setLoaded] = useState(false)
28
-
29
- function handleSigninSuccess(res) {
30
- /*
31
- offer renamed response keys to names that match use
32
- */
33
- const basicProfile = res.getBasicProfile()
34
- const authResponse = res.getAuthResponse(true)
35
- res.googleId = basicProfile.getId()
36
- res.tokenObj = authResponse
37
- res.tokenId = authResponse.id_token
38
- res.accessToken = authResponse.access_token
39
- res.profileObj = {
40
- googleId: basicProfile.getId(),
41
- imageUrl: basicProfile.getImageUrl(),
42
- email: basicProfile.getEmail(),
43
- name: basicProfile.getName(),
44
- givenName: basicProfile.getGivenName(),
45
- familyName: basicProfile.getFamilyName()
46
- }
47
- onSuccess(res)
48
- }
49
-
50
- function signIn(e) {
51
- if (e) {
52
- e.preventDefault() // to prevent submit if used within form
53
- }
54
- if (loaded) {
55
- const GoogleAuth = window.gapi.auth2.getAuthInstance()
56
- const options = {
57
- prompt
58
- }
59
- onRequest()
60
- if (responseType === 'code') {
61
- GoogleAuth.grantOfflineAccess(options).then(
62
- res => onSuccess(res),
63
- err => onFailure(err)
64
- )
65
- } else {
66
- GoogleAuth.signIn(options).then(
67
- res => handleSigninSuccess(res),
68
- err => onFailure(err)
69
- )
70
- }
71
- }
72
- }
73
-
74
- useEffect(() => {
75
- let unmounted = false
76
- const onLoadFailure = onScriptLoadFailure || onFailure
77
- loadScript(
78
- document,
79
- 'script',
80
- 'google-login',
81
- jsSrc,
82
- () => {
83
- const params = {
84
- client_id: clientId,
85
- cookie_policy: cookiePolicy,
86
- login_hint: loginHint,
87
- hosted_domain: hostedDomain,
88
- fetch_basic_profile: fetchBasicProfile,
89
- discoveryDocs,
90
- ux_mode: uxMode,
91
- redirect_uri: redirectUri,
92
- scope,
93
- access_type: accessType
94
- }
95
-
96
- if (responseType === 'code') {
97
- params.access_type = 'offline'
98
- }
99
-
100
- window.gapi.load('auth2', () => {
101
- const GoogleAuth = window.gapi.auth2.getAuthInstance()
102
- if (!GoogleAuth) {
103
- window.gapi.auth2.init(params).then(
104
- res => {
105
- if (!unmounted) {
106
- setLoaded(true)
107
- const signedIn = isSignedIn && res.isSignedIn.get()
108
- onAutoLoadFinished(signedIn)
109
- if (signedIn) {
110
- handleSigninSuccess(res.currentUser.get())
111
- }
112
- }
113
- },
114
- err => {
115
- setLoaded(true)
116
- onAutoLoadFinished(false)
117
- onLoadFailure(err)
118
- }
119
- )
120
- } else {
121
- GoogleAuth.then(
122
- () => {
123
- if (unmounted) {
124
- return
125
- }
126
- if (isSignedIn && GoogleAuth.isSignedIn.get()) {
127
- setLoaded(true)
128
- onAutoLoadFinished(true)
129
- handleSigninSuccess(GoogleAuth.currentUser.get())
130
- } else {
131
- setLoaded(true)
132
- onAutoLoadFinished(false)
133
- }
134
- },
135
- err => {
136
- onFailure(err)
137
- }
138
- )
139
- }
140
- })
141
- },
142
- err => {
143
- onLoadFailure(err)
144
- }
145
- )
146
-
147
- return () => {
148
- unmounted = true
149
- removeScript(document, 'google-login')
150
- }
151
- }, [])
152
-
153
- useEffect(() => {
154
- if (autoLoad) {
155
- signIn()
156
- }
157
- }, [loaded])
158
-
159
- return { signIn, loaded }
160
- }
161
-
1
+ import { useState, useEffect } from 'react'
2
+ import loadScript from './loadScript'
3
+ import removeScript from './removeScript'
4
+
5
+ export const useGoogleLogin = ({
6
+ onSuccess = () => {},
7
+ onAutoLoadFinished = () => {},
8
+ onFailure = () => {},
9
+ onRequest = () => {},
10
+ onScriptLoadFailure,
11
+ clientId,
12
+ cookiePolicy,
13
+ loginHint,
14
+ hostedDomain,
15
+ autoLoad,
16
+ isSignedIn,
17
+ fetchBasicProfile,
18
+ redirectUri,
19
+ discoveryDocs,
20
+ uxMode,
21
+ scope,
22
+ accessType,
23
+ responseType,
24
+ jsSrc = 'https://apis.google.com/js/api.js',
25
+ prompt
26
+ }) => {
27
+ const [loaded, setLoaded] = useState(false)
28
+
29
+ function handleSigninSuccess (res) {
30
+ /*
31
+ offer renamed response keys to names that match use
32
+ */
33
+ const basicProfile = res.getBasicProfile()
34
+ const authResponse = res.getAuthResponse(true)
35
+ res.googleId = basicProfile.getId()
36
+ res.tokenObj = authResponse
37
+ res.tokenId = authResponse.id_token
38
+ res.accessToken = authResponse.access_token
39
+ res.profileObj = {
40
+ googleId: basicProfile.getId(),
41
+ imageUrl: basicProfile.getImageUrl(),
42
+ email: basicProfile.getEmail(),
43
+ name: basicProfile.getName(),
44
+ givenName: basicProfile.getGivenName(),
45
+ familyName: basicProfile.getFamilyName()
46
+ }
47
+ onSuccess(res)
48
+ }
49
+
50
+ function signIn (e) {
51
+ if (e) {
52
+ e.preventDefault() // to prevent submit if used within form
53
+ }
54
+ if (loaded) {
55
+ const GoogleAuth = window.gapi.auth2.getAuthInstance()
56
+ const options = {
57
+ prompt
58
+ }
59
+ onRequest()
60
+ if (responseType === 'code') {
61
+ GoogleAuth.grantOfflineAccess(options).then(
62
+ res => onSuccess(res),
63
+ err => onFailure(err)
64
+ )
65
+ } else {
66
+ GoogleAuth.signIn(options).then(
67
+ res => handleSigninSuccess(res),
68
+ err => onFailure(err)
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ useEffect(() => {
75
+ let unmounted = false
76
+ const onLoadFailure = onScriptLoadFailure || onFailure
77
+ loadScript(
78
+ document,
79
+ 'script',
80
+ 'google-login',
81
+ jsSrc,
82
+ () => {
83
+ const params = {
84
+ client_id: clientId,
85
+ cookie_policy: cookiePolicy,
86
+ login_hint: loginHint,
87
+ hosted_domain: hostedDomain,
88
+ fetch_basic_profile: fetchBasicProfile,
89
+ discoveryDocs,
90
+ ux_mode: uxMode,
91
+ redirect_uri: redirectUri,
92
+ scope,
93
+ access_type: accessType
94
+ }
95
+
96
+ if (responseType === 'code') {
97
+ params.access_type = 'offline'
98
+ }
99
+
100
+ window.gapi.load('auth2', () => {
101
+ const GoogleAuth = window.gapi.auth2.getAuthInstance()
102
+ if (!GoogleAuth) {
103
+ window.gapi.auth2.init(params).then(
104
+ res => {
105
+ if (!unmounted) {
106
+ setLoaded(true)
107
+ const signedIn = isSignedIn && res.isSignedIn.get()
108
+ onAutoLoadFinished(signedIn)
109
+ if (signedIn) {
110
+ handleSigninSuccess(res.currentUser.get())
111
+ }
112
+ }
113
+ },
114
+ err => {
115
+ setLoaded(true)
116
+ onAutoLoadFinished(false)
117
+ onLoadFailure(err)
118
+ }
119
+ )
120
+ } else {
121
+ GoogleAuth.then(
122
+ () => {
123
+ if (unmounted) {
124
+ return
125
+ }
126
+ if (isSignedIn && GoogleAuth.isSignedIn.get()) {
127
+ setLoaded(true)
128
+ onAutoLoadFinished(true)
129
+ handleSigninSuccess(GoogleAuth.currentUser.get())
130
+ } else {
131
+ setLoaded(true)
132
+ onAutoLoadFinished(false)
133
+ }
134
+ },
135
+ err => {
136
+ onFailure(err)
137
+ }
138
+ )
139
+ }
140
+ })
141
+ },
142
+ err => {
143
+ onLoadFailure(err)
144
+ }
145
+ )
146
+
147
+ return () => {
148
+ unmounted = true
149
+ removeScript(document, 'google-login')
150
+ }
151
+ }, [])
152
+
153
+ useEffect(() => {
154
+ if (autoLoad) {
155
+ signIn()
156
+ }
157
+ }, [loaded])
158
+
159
+ return { signIn, loaded }
160
+ }
@@ -1,29 +1,29 @@
1
- import { useRef, useState, useEffect } from 'react'
2
-
3
- export function useHover() {
4
- const [value, setValue] = useState(false)
5
-
6
- const ref = useRef(null)
7
-
8
- const handleMouseOver = () => {return setValue(true)}
9
- const handleMouseOut = () => {return setValue(false)}
10
-
11
- useEffect(
12
- () => {
13
- const node = ref.current
14
- if (node) {
15
- node.addEventListener('mouseover', handleMouseOver)
16
- node.addEventListener('mouseout', handleMouseOut)
17
-
18
- return () => {
19
- node.removeEventListener('mouseover', handleMouseOver)
20
- node.removeEventListener('mouseout', handleMouseOut)
21
- }
22
- }
23
- return {}
24
- },
25
- [] // Recall only if ref changes
26
- )
27
-
28
- return [ref, value]
29
- }
1
+ import { useRef, useState, useEffect } from 'react'
2
+
3
+ export function useHover () {
4
+ const [value, setValue] = useState(false)
5
+
6
+ const ref = useRef(null)
7
+
8
+ const handleMouseOver = () => { return setValue(true) }
9
+ const handleMouseOut = () => { return setValue(false) }
10
+
11
+ useEffect(
12
+ () => {
13
+ const node = ref.current
14
+ if (node) {
15
+ node.addEventListener('mouseover', handleMouseOver)
16
+ node.addEventListener('mouseout', handleMouseOut)
17
+
18
+ return () => {
19
+ node.removeEventListener('mouseover', handleMouseOver)
20
+ node.removeEventListener('mouseout', handleMouseOut)
21
+ }
22
+ }
23
+ return {}
24
+ },
25
+ [] // Recall only if ref changes
26
+ )
27
+
28
+ return [ref, value]
29
+ }
@@ -1,28 +1,28 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useState } from 'react'
2
2
  // use it
3
3
  // const imageUrl = 'https://example.com/image.jpg';
4
4
  // const optimizedUrl = useImageOptimization(imageUrl);
5
5
 
6
- export function useImageOptimization(imageUrl) {
7
- const [optimizedUrl, setOptimizedUrl] = useState(null);
6
+ export function useImageOptimization (imageUrl) {
7
+ const [optimizedUrl, setOptimizedUrl] = useState(null)
8
8
 
9
9
  useEffect(() => {
10
- const image = new Image();
11
- image.src = imageUrl;
10
+ const image = new Image()
11
+ image.src = imageUrl
12
12
 
13
13
  image.onload = () => {
14
- const canvas = document.createElement('canvas');
15
- const ctx = canvas.getContext('2d');
14
+ const canvas = document.createElement('canvas')
15
+ const ctx = canvas.getContext('2d')
16
16
 
17
- canvas.width = image.width;
18
- canvas.height = image.height;
17
+ canvas.width = image.width
18
+ canvas.height = image.height
19
19
 
20
- ctx.drawImage(image, 0, 0, image.width, image.height);
20
+ ctx.drawImage(image, 0, 0, image.width, image.height)
21
21
 
22
- const optimizedUrl = canvas.toDataURL('image/jpeg', 0.8);
23
- setOptimizedUrl(optimizedUrl);
24
- };
25
- }, [imageUrl]);
22
+ const optimizedUrl = canvas.toDataURL('image/jpeg', 0.8)
23
+ setOptimizedUrl(optimizedUrl)
24
+ }
25
+ }, [imageUrl])
26
26
 
27
- return optimizedUrl;
27
+ return optimizedUrl
28
28
  }
@@ -1,33 +1,33 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useState } from 'react'
2
2
 
3
- export function useImageWeight(imageUrl) {
4
- const [weight, setWeight] = useState(null);
3
+ export function useImageWeight (imageUrl) {
4
+ const [weight, setWeight] = useState(null)
5
5
 
6
6
  useEffect(() => {
7
- const image = new Image();
8
- image.src = imageUrl;
7
+ const image = new Image()
8
+ image.src = imageUrl
9
9
 
10
10
  image.onload = () => {
11
- const xhr = new XMLHttpRequest();
12
- xhr.open('HEAD', imageUrl, true);
11
+ const xhr = new XMLHttpRequest()
12
+ xhr.open('HEAD', imageUrl, true)
13
13
  xhr.onreadystatechange = () => {
14
14
  if (xhr.readyState === 4 && xhr.status === 200) {
15
- const contentLength = xhr.getResponseHeader('Content-Length');
16
- setWeight(contentLength);
15
+ const contentLength = xhr.getResponseHeader('Content-Length')
16
+ setWeight(contentLength)
17
17
  }
18
- };
19
- xhr.send();
20
- };
21
- }, [imageUrl]);
18
+ }
19
+ xhr.send()
20
+ }
21
+ }, [imageUrl])
22
22
 
23
- return weight;
23
+ return weight
24
24
  }
25
25
 
26
- // I use
26
+ // I use
27
27
  // function MyComponent() {
28
28
  // const imageUrl = 'https://example.com/image.jpg';
29
29
  // const weight = useImageWeight(imageUrl);
30
-
30
+
31
31
  // return (
32
32
  // <div>
33
33
  // <img src={imageUrl} alt="My Image" />
@@ -35,13 +35,13 @@ export function useImageWeight(imageUrl) {
35
35
  // </div>
36
36
  // );
37
37
  // }
38
-
38
+
39
39
  // const weightInMB = weight / (1024 * 1024);
40
40
 
41
41
  // function MyComponent() {
42
42
  // const imageUrl = 'https://example.com/image.jpg';
43
43
  // const weight = useImageWeight(imageUrl);
44
-
44
+
45
45
  // return (
46
46
  // <div>
47
47
  // <img src={imageUrl} alt="My Image" />
@@ -49,4 +49,3 @@ export function useImageWeight(imageUrl) {
49
49
  // </div>
50
50
  // );
51
51
  // }
52
-