npm-pkg-hook 1.0.2 → 1.0.5
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/.babelrc +13 -13
- package/.env +1 -0
- package/.eslintrc.js +132 -0
- package/.eslintrc.json +107 -107
- package/.github/pull_request_template.md +17 -17
- package/.github/workflows/pepeline.yaml +29 -29
- package/.vscode/extensions.json +6 -0
- package/.vscode/settings.json +12 -0
- package/README.md +1 -1
- package/jsconfig.json +27 -27
- package/next.config.js +128 -128
- package/package.json +8 -6
- package/script.txt +7 -0
- package/src/cookies/index.ts +3 -3
- package/src/hooks/index.js +47 -19
- package/src/hooks/updateExtProductFoodsOptional/index.js +38 -0
- package/src/hooks/useAcumulateDate/index.js +16 -16
- package/src/hooks/useAnimationText/index.jsx +31 -30
- package/src/hooks/useBanner/index.js +19 -0
- package/src/hooks/useCatWithProduct/index.js +42 -0
- package/src/hooks/useCatWithProduct/queries.js +172 -0
- package/src/hooks/useCategoryInStore/index.js +94 -0
- package/src/hooks/{useGetCategorieStore → useCategoryInStore}/queries.js +77 -77
- package/src/hooks/useCategoryStore/index.js +7 -7
- package/src/hooks/useCategoryStore/queries.js +16 -16
- package/src/hooks/useChartData/index.js +170 -0
- package/src/hooks/useCheckbox/index.js +114 -114
- package/src/hooks/useClients/index.js +13 -13
- package/src/hooks/useClients/queries.js +117 -117
- package/src/hooks/useConnection/index.js +23 -0
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +165 -0
- package/src/hooks/useCreateProduct/index.js +268 -0
- package/src/hooks/useDessert/index.js +141 -0
- package/src/hooks/useDrag/index.js +62 -57
- package/src/hooks/useEvent/index.js +33 -33
- package/src/hooks/useFetchJson/index.js +24 -24
- package/src/hooks/useFetchMoreInteractions/index.jsx +37 -34
- package/src/hooks/useFormTools/index.js +83 -70
- package/src/hooks/useFormatDate/index.js +34 -0
- package/src/hooks/useFullScreenMode/index.js +65 -65
- package/src/hooks/useHover/index.js +28 -28
- package/src/hooks/useImageOptimization/index.js +28 -0
- package/src/hooks/useImageWeight/index.js +52 -0
- package/src/hooks/useImagesStore/index.js +171 -0
- package/src/hooks/useImagesStore/queries.js +216 -0
- package/src/hooks/useInnerHtml/index.js +37 -37
- package/src/hooks/useIntersection/index.js +84 -31
- package/src/hooks/useKeypress/index.js +27 -27
- package/src/hooks/useLazyScript/index.js +72 -0
- package/src/hooks/useLocalSorage/index.js +35 -35
- package/src/hooks/useLocationNavigate/index.js +54 -54
- package/src/hooks/useMobile/index.js +37 -37
- package/src/hooks/useMutateHeight/index.js +37 -0
- package/src/hooks/useProductsFood/index.js +190 -0
- package/src/hooks/{useGetProductsFood → useProductsFood}/queriesStore.js +780 -765
- package/src/hooks/useProductsFood/usetagsProducts.js +57 -0
- package/src/hooks/useReactToPrint/index.js +1201 -0
- package/src/hooks/useReport/index.js +35 -0
- package/src/hooks/useReport/queries.js +122 -0
- package/src/hooks/useRestaurant/index.js +19 -19
- package/src/hooks/useRestaurant/queries.js +79 -69
- package/src/hooks/useSales/index.js +589 -489
- package/src/hooks/useSales/queries.js +290 -229
- package/src/hooks/useSales/useGetSale.js +12 -0
- package/src/hooks/useSales/useTotalSales.js +17 -0
- package/src/hooks/useSaveAvailableProduct/helpers/index.js +30 -0
- package/src/hooks/useSaveAvailableProduct/index.js +26 -0
- package/src/hooks/useSaveAvailableProduct/queries.js +10 -0
- package/src/hooks/useSchedule/index.jsx +23 -0
- package/src/hooks/useSetState/index.js +24 -24
- package/src/hooks/useStore/index.js +17 -17
- package/src/hooks/useStore/queries.js +135 -135
- package/src/hooks/useStoreCalendar/index.js +7 -0
- package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
- package/src/hooks/useUpdateCart/index.js +124 -124
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +37 -0
- package/src/hooks/useUser/index.js +7 -3
- package/src/hooks/useUser/queries.js +69 -0
- package/src/hooks/useWindowSize/index.js +37 -37
- package/src/index.jsx +2 -1
- package/src/mock/dessert/index.js +16 -0
- package/src/mock/index.js +2 -0
- package/src/utils/index.js +106 -54
- package/src/hooks/useGetCategorieStore/index.js +0 -21
- package/src/hooks/useGetProductsFood/index.js +0 -46
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client';
|
|
2
|
+
import {
|
|
3
|
+
useRef,
|
|
4
|
+
useState
|
|
5
|
+
} from 'react';
|
|
6
|
+
import {
|
|
7
|
+
CREATE_BANNER_STORE,
|
|
8
|
+
CREATE_LOGO,
|
|
9
|
+
DELETE_ONE_BANNER_STORE,
|
|
10
|
+
DELETE_ONE_LOGO_STORE,
|
|
11
|
+
GET_ONE_BANNER_STORE
|
|
12
|
+
} from '../useProductsFood/queriesStore';
|
|
13
|
+
import { GET_ONE_STORE } from '../useStore/queries';
|
|
14
|
+
|
|
15
|
+
export const useImageStore = (idStore) => {
|
|
16
|
+
// STATES
|
|
17
|
+
const fileInputRef = useRef(null)
|
|
18
|
+
const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({})
|
|
19
|
+
const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
|
|
20
|
+
const [{ alt, src }, setPreviewImg] = useState(initialState)
|
|
21
|
+
const fileInputRefLogo = useRef(null)
|
|
22
|
+
// HOOKS
|
|
23
|
+
const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
|
|
24
|
+
onCompleted: (data) => { return console.log({ message: data?.registerBanner?.message }) },
|
|
25
|
+
context: { clientName: 'admin-server' }
|
|
26
|
+
})
|
|
27
|
+
const [setALogoStore] = useMutation(CREATE_LOGO, {
|
|
28
|
+
onCompleted: (data) => { return console.log({ message: data?.setALogoStore?.message }) },
|
|
29
|
+
context: { clientName: 'admin-server' }
|
|
30
|
+
})
|
|
31
|
+
const [DeleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
|
|
32
|
+
onCompleted: (data) => { return console.log({ message: data?.DeleteOneBanner?.message }) },
|
|
33
|
+
context: { clientName: 'admin-server' }
|
|
34
|
+
})
|
|
35
|
+
const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
|
|
36
|
+
onCompleted: (data) => {
|
|
37
|
+
console.log({
|
|
38
|
+
message: data.deleteALogoStore.message
|
|
39
|
+
})
|
|
40
|
+
setPreviewImgLogo(initialState)
|
|
41
|
+
},
|
|
42
|
+
context: { clientName: 'admin-server' },
|
|
43
|
+
update(cache) {
|
|
44
|
+
cache.modify({
|
|
45
|
+
fields: {
|
|
46
|
+
getStore(dataOld = []) {
|
|
47
|
+
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
// HANDLESS
|
|
54
|
+
const handleDeleteLogo = () => {
|
|
55
|
+
return deleteALogoStore({
|
|
56
|
+
variables: {
|
|
57
|
+
Image: ImageName || null
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const handleUpdateBanner = event => {
|
|
63
|
+
try {
|
|
64
|
+
const { files } = event.target
|
|
65
|
+
setPreviewImg(
|
|
66
|
+
files.length
|
|
67
|
+
? {
|
|
68
|
+
src: URL.createObjectURL(files[0]),
|
|
69
|
+
alt: files[0].name
|
|
70
|
+
}
|
|
71
|
+
: initialState
|
|
72
|
+
)
|
|
73
|
+
registerBanner({
|
|
74
|
+
variables: {
|
|
75
|
+
input: {
|
|
76
|
+
bnImage: files[0],
|
|
77
|
+
idStore: idStore
|
|
78
|
+
}
|
|
79
|
+
}, update(cache) {
|
|
80
|
+
cache.modify({
|
|
81
|
+
fields: {
|
|
82
|
+
getOneBanners(dataOld = []) {
|
|
83
|
+
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}).catch(() => {
|
|
89
|
+
console.log({ message: 'No pudimos cargar la imagen', duration: 7000 })
|
|
90
|
+
setPreviewImg(initialState)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
} catch {
|
|
94
|
+
setPreviewImg(initialState)
|
|
95
|
+
console.log({ message: 'No pudimos cargar la imagen', duration: 7000 })
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const handleInputChangeLogo = event => {
|
|
99
|
+
const { files } = event.target
|
|
100
|
+
setPreviewImgLogo(
|
|
101
|
+
files.length
|
|
102
|
+
? {
|
|
103
|
+
srcLogo: URL.createObjectURL(files[0]),
|
|
104
|
+
altLogo: files[0].name
|
|
105
|
+
}
|
|
106
|
+
: initialState
|
|
107
|
+
)
|
|
108
|
+
setALogoStore({
|
|
109
|
+
variables: {
|
|
110
|
+
logo: files[0],
|
|
111
|
+
idStore: idStore
|
|
112
|
+
}, update(cache) {
|
|
113
|
+
cache.modify({
|
|
114
|
+
fields: {
|
|
115
|
+
getStore(dataOld = []) {
|
|
116
|
+
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
}).catch(() => {
|
|
122
|
+
console.log({ message: 'No pudimos cargar el banner', duration: 7000 })
|
|
123
|
+
setPreviewImgLogo(initialState)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
const HandleDeleteBanner = async () => {
|
|
127
|
+
setPreviewImg(initialState)
|
|
128
|
+
DeleteOneBanner({
|
|
129
|
+
variables: {
|
|
130
|
+
bnState: bnState,
|
|
131
|
+
bnImageFileName: bnImageFileName,
|
|
132
|
+
idStore,
|
|
133
|
+
bnId
|
|
134
|
+
}, update(cache) {
|
|
135
|
+
cache.modify({
|
|
136
|
+
fields: {
|
|
137
|
+
getOneBanners(dataOld = []) {
|
|
138
|
+
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}).then(() => {
|
|
144
|
+
setPreviewImg(initialState)
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
const onTargetClickLogo = e => {
|
|
148
|
+
e.preventDefault()
|
|
149
|
+
fileInputRefLogo.current.click()
|
|
150
|
+
}
|
|
151
|
+
const onTargetClick = e => {
|
|
152
|
+
e.preventDefault()
|
|
153
|
+
fileInputRef.current.click()
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
fileInputRefLogo,
|
|
157
|
+
src,
|
|
158
|
+
alt,
|
|
159
|
+
initialState,
|
|
160
|
+
srcLogo,
|
|
161
|
+
altLogo,
|
|
162
|
+
fileInputRef,
|
|
163
|
+
handleDeleteLogo,
|
|
164
|
+
onTargetClick,
|
|
165
|
+
onTargetClickLogo,
|
|
166
|
+
HandleDeleteBanner,
|
|
167
|
+
handleInputChangeLogo,
|
|
168
|
+
handleUpdateBanner
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const CREATE_SCHEDULE_STORE = gql`
|
|
4
|
+
mutation setStoreSchedule($input: IsStoreSchedule!){
|
|
5
|
+
setStoreSchedule(input: $input){
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
export const GET_SCHEDULE_STORE = gql`
|
|
12
|
+
query getStoreSchedules($schDay: Int, $idStore: ID) {
|
|
13
|
+
getStoreSchedules(schDay: $schDay, idStore: $idStore){
|
|
14
|
+
schId
|
|
15
|
+
idStore
|
|
16
|
+
schDay
|
|
17
|
+
schHoSta
|
|
18
|
+
schHoEnd
|
|
19
|
+
schState
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
export const GET_ONE_SCHEDULE_STORE = gql`
|
|
24
|
+
query getOneStoreSchedules($schDay: Int, $idStore: ID) {
|
|
25
|
+
getOneStoreSchedules(schDay: $schDay, idStore: $idStore){
|
|
26
|
+
schId
|
|
27
|
+
schDay
|
|
28
|
+
schHoSta
|
|
29
|
+
schHoEnd
|
|
30
|
+
schState
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`
|
|
34
|
+
export const GET_CAT_OF_PRODUCTS = gql`
|
|
35
|
+
query getAllCatOfProducts($idStore: ID) {
|
|
36
|
+
getAllCatOfProducts(idStore: $idStore) {
|
|
37
|
+
id
|
|
38
|
+
cpId
|
|
39
|
+
catName
|
|
40
|
+
catDescription
|
|
41
|
+
schState
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`
|
|
46
|
+
export const REGISTER_CAT_OF_PRODUCTS = gql`
|
|
47
|
+
mutation updatedProducts($input: InputCatProducts){
|
|
48
|
+
updatedProducts(input: $input){
|
|
49
|
+
success
|
|
50
|
+
message
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`
|
|
54
|
+
export const REGISTER_CONTRACT_STORE = gql`
|
|
55
|
+
mutation createOneContract($input: InputContractType) {
|
|
56
|
+
createOneContract(input: $input) {
|
|
57
|
+
success
|
|
58
|
+
message
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
export const GET_ALL_EMPLOYEE_STORE = gql`
|
|
63
|
+
query employees ($umId: ID, $cId: ID, $aId: ID){
|
|
64
|
+
employees(umId: $umId, cId: $cId, aId: $aId) {
|
|
65
|
+
eId
|
|
66
|
+
idStore
|
|
67
|
+
id
|
|
68
|
+
idEmployee
|
|
69
|
+
eSalary
|
|
70
|
+
typeContract
|
|
71
|
+
uEmail
|
|
72
|
+
termContract
|
|
73
|
+
eDatAdm
|
|
74
|
+
eState
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
export const GET_ALL_PRODUCT_STORE = gql`
|
|
79
|
+
query productFoodsAll($search: String, $min: Int, $max: Int, $gender: [String], $pState: Int, $desc: [String], $categories: [ID], $fromDate: DateTime, $toDate: DateTime ) {
|
|
80
|
+
productFoodsAll(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, pState: $pState categories: $categories, toDate: $toDate, fromDate: $fromDate) {
|
|
81
|
+
pId
|
|
82
|
+
sizeId #Talla
|
|
83
|
+
colorId #Color
|
|
84
|
+
cId #Country
|
|
85
|
+
dId #Department
|
|
86
|
+
ctId #Cuidad
|
|
87
|
+
fId #Características
|
|
88
|
+
pName
|
|
89
|
+
ProPrice
|
|
90
|
+
ProDescuento
|
|
91
|
+
free
|
|
92
|
+
ProUniDisponibles
|
|
93
|
+
ProDescription
|
|
94
|
+
ProProtegido
|
|
95
|
+
ProAssurance
|
|
96
|
+
ValueDelivery
|
|
97
|
+
ProStar
|
|
98
|
+
sTateLogistic
|
|
99
|
+
ProImage
|
|
100
|
+
ProWidth
|
|
101
|
+
ProHeight
|
|
102
|
+
ProLength
|
|
103
|
+
ProWeight
|
|
104
|
+
ProQuantity
|
|
105
|
+
ProOutstanding
|
|
106
|
+
pDatCre
|
|
107
|
+
pDatMod
|
|
108
|
+
ProDelivery
|
|
109
|
+
ProVoltaje
|
|
110
|
+
pState
|
|
111
|
+
feat {
|
|
112
|
+
fId
|
|
113
|
+
thpId
|
|
114
|
+
hpqrQuestion
|
|
115
|
+
}
|
|
116
|
+
area {
|
|
117
|
+
aId
|
|
118
|
+
aName
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
`
|
|
125
|
+
export const GET_ALL_RATING_START_STORE = gql`
|
|
126
|
+
query getAllRatingStar($idStore: ID){
|
|
127
|
+
getAllRatingStar(idStore: $idStore){
|
|
128
|
+
rSId
|
|
129
|
+
rScore
|
|
130
|
+
idStore
|
|
131
|
+
createAt
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`
|
|
135
|
+
export const GET_ALL_VISITOR_STORE = gql`
|
|
136
|
+
query getAllVisitorStore($idStore: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime) {
|
|
137
|
+
getAllVisitorStore(idStore: $idStore, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate) {
|
|
138
|
+
visitStoreId
|
|
139
|
+
id
|
|
140
|
+
idStore
|
|
141
|
+
createAt
|
|
142
|
+
updateAt
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
`
|
|
146
|
+
export const GET_MIN_PEDIDO = gql`
|
|
147
|
+
query getMinPrice($idStore: ID){
|
|
148
|
+
getMinPrice(idStore: $idStore)
|
|
149
|
+
}
|
|
150
|
+
`
|
|
151
|
+
|
|
152
|
+
export const GET_All_RATING_STORE = gql`
|
|
153
|
+
query getAllRating($idStore: ID){
|
|
154
|
+
getAllRating(idStore: $idStore){
|
|
155
|
+
idStore
|
|
156
|
+
rId
|
|
157
|
+
id
|
|
158
|
+
rAppearance
|
|
159
|
+
rTasty
|
|
160
|
+
rGoodTemperature
|
|
161
|
+
rGoodCondition
|
|
162
|
+
rState
|
|
163
|
+
createAt
|
|
164
|
+
updateAt
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
`
|
|
168
|
+
export const CREATE_LOGO = gql`
|
|
169
|
+
mutation setALogoStore($logo: Upload, $idStore: ID) {
|
|
170
|
+
setALogoStore(logo: $logo, idStore: $idStore) {
|
|
171
|
+
success
|
|
172
|
+
message
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`
|
|
176
|
+
export const CREATE_BANNER_STORE = gql`
|
|
177
|
+
mutation registerBanner($input: IBanner) {
|
|
178
|
+
registerBanner(input: $input) {
|
|
179
|
+
success
|
|
180
|
+
message
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
`
|
|
185
|
+
export const DELETE_ONE_LOGO_STORE = gql`
|
|
186
|
+
mutation deleteALogoStore($idStore: ID, $Image: String) {
|
|
187
|
+
deleteALogoStore(idStore: $idStore, Image: $Image) {
|
|
188
|
+
message
|
|
189
|
+
success
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
`
|
|
194
|
+
export const GET_ONE_BANNER_STORE = gql`
|
|
195
|
+
query getOneBanners($idStore: ID, $id: ID) {
|
|
196
|
+
getOneBanners(idStore: $idStore, id: $id) {
|
|
197
|
+
bnId
|
|
198
|
+
id
|
|
199
|
+
path
|
|
200
|
+
bnImageFileName
|
|
201
|
+
idStore
|
|
202
|
+
bnState
|
|
203
|
+
createAt
|
|
204
|
+
updateAt
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
`
|
|
208
|
+
export const DELETE_ONE_BANNER_STORE = gql`
|
|
209
|
+
mutation DeleteOneBanner($bnState: Int, $idStore: ID, $bnId: ID, $bnImage: String, $bnImageFileName: String) {
|
|
210
|
+
DeleteOneBanner(bnState: $bnState, idStore: $idStore, bnId: $bnId, bnImage: $bnImage, bnImageFileName: $bnImageFileName ) {
|
|
211
|
+
success
|
|
212
|
+
message
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
`
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { render } from 'react-dom'
|
|
3
|
-
import './styles.css'
|
|
4
|
-
|
|
5
|
-
const htmlText =
|
|
6
|
-
'<p style=\'display:inline;\'>Lorem ipsum</p> dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
|
|
7
|
-
|
|
8
|
-
function App() {
|
|
9
|
-
const [state, setState] = React.useState({
|
|
10
|
-
showOriginalHTML: false,
|
|
11
|
-
originalHTML: htmlText
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const handleShowText = React.useCallback(() => {
|
|
15
|
-
setState(prevState => {return {
|
|
16
|
-
...prevState,
|
|
17
|
-
showOriginalHTML: !prevState.showOriginalHTML
|
|
18
|
-
}})
|
|
19
|
-
}, [setState])
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<div className='container'>
|
|
23
|
-
<div
|
|
24
|
-
className='text'
|
|
25
|
-
dangerouslySetInnerHTML={{
|
|
26
|
-
__html: `${
|
|
27
|
-
state.originalHTML
|
|
28
|
-
}`
|
|
29
|
-
}}
|
|
30
|
-
/>
|
|
31
|
-
<button className='read-more' onClick={handleShowText}>
|
|
32
|
-
{!state.showOriginalHTML ? 'read more' : 'show less'}
|
|
33
|
-
</button>
|
|
34
|
-
</div>
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from 'react-dom'
|
|
3
|
+
import './styles.css'
|
|
4
|
+
|
|
5
|
+
const htmlText =
|
|
6
|
+
'<p style=\'display:inline;\'>Lorem ipsum</p> dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
|
|
7
|
+
|
|
8
|
+
function App() {
|
|
9
|
+
const [state, setState] = React.useState({
|
|
10
|
+
showOriginalHTML: false,
|
|
11
|
+
originalHTML: htmlText
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const handleShowText = React.useCallback(() => {
|
|
15
|
+
setState(prevState => {return {
|
|
16
|
+
...prevState,
|
|
17
|
+
showOriginalHTML: !prevState.showOriginalHTML
|
|
18
|
+
}})
|
|
19
|
+
}, [setState])
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className='container'>
|
|
23
|
+
<div
|
|
24
|
+
className='text'
|
|
25
|
+
dangerouslySetInnerHTML={{
|
|
26
|
+
__html: `${
|
|
27
|
+
state.originalHTML
|
|
28
|
+
}`
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
<button className='read-more' onClick={handleShowText}>
|
|
32
|
+
{!state.showOriginalHTML ? 'read more' : 'show less'}
|
|
33
|
+
</button>
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
38
|
render(<App />, document.getElementById('root'))
|
|
@@ -1,31 +1,84 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
export const useOnScreen = (threshold = 0.6) => {
|
|
4
|
-
const [isVisible, setIsVisible] = useState(false)
|
|
5
|
-
const [ref, setRef] = useState(null)
|
|
6
|
-
|
|
7
|
-
useEffect(
|
|
8
|
-
() => {
|
|
9
|
-
let observer
|
|
10
|
-
if (ref) {
|
|
11
|
-
observer = new IntersectionObserver(
|
|
12
|
-
([entry]) => {
|
|
13
|
-
setIsVisible(entry.isIntersecting)
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
// rootMargin,
|
|
17
|
-
threshold
|
|
18
|
-
}
|
|
19
|
-
)
|
|
20
|
-
observer.observe(ref)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return () => {
|
|
24
|
-
if (ref && observer) observer.unobserve(ref)
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
[ref]
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
return [setRef, isVisible]
|
|
31
|
-
}
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useOnScreen = (threshold = 0.6) => {
|
|
4
|
+
const [isVisible, setIsVisible] = useState(false)
|
|
5
|
+
const [ref, setRef] = useState(null)
|
|
6
|
+
|
|
7
|
+
useEffect(
|
|
8
|
+
() => {
|
|
9
|
+
let observer
|
|
10
|
+
if (ref) {
|
|
11
|
+
observer = new IntersectionObserver(
|
|
12
|
+
([entry]) => {
|
|
13
|
+
setIsVisible(entry.isIntersecting)
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
// rootMargin,
|
|
17
|
+
threshold
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
observer.observe(ref)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return () => {
|
|
24
|
+
if (ref && observer) observer.unobserve(ref)
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
[ref]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return [setRef, isVisible]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const defaultObserverOptions = {
|
|
34
|
+
root: null,
|
|
35
|
+
threshold: 0.1,
|
|
36
|
+
rootMargin: "0px"
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const useIntersectionObserver = ({
|
|
40
|
+
active = true,
|
|
41
|
+
disconnect,
|
|
42
|
+
el,
|
|
43
|
+
options = defaultObserverOptions,
|
|
44
|
+
onEnter = () => {},
|
|
45
|
+
out = () => {}
|
|
46
|
+
}) => {
|
|
47
|
+
const [onScreen, setOnScreen] = useState()
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
let observer
|
|
50
|
+
const refEl = el.current
|
|
51
|
+
if (IntersectionObserver && active && refEl) {
|
|
52
|
+
observer = new IntersectionObserver((entries) => {
|
|
53
|
+
entries.forEach((entry) => {
|
|
54
|
+
if (disconnect) {
|
|
55
|
+
if (entry.isIntersecting) {
|
|
56
|
+
onEnter()
|
|
57
|
+
setOnScreen(true)
|
|
58
|
+
} else {
|
|
59
|
+
out()
|
|
60
|
+
setOnScreen(false)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!disconnect) {
|
|
64
|
+
onEnter()
|
|
65
|
+
setOnScreen(true)
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}, options)
|
|
69
|
+
observer.observe(refEl)
|
|
70
|
+
}
|
|
71
|
+
return () => {
|
|
72
|
+
if (disconnect) {
|
|
73
|
+
// eslint-disable-next-line no-void
|
|
74
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect(refEl)
|
|
75
|
+
}
|
|
76
|
+
if (!disconnect) {
|
|
77
|
+
if (el && observer) observer.unobserve(refEl)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, [el, onEnter, active, options])
|
|
81
|
+
return {
|
|
82
|
+
onScreen
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
export const useKeyPress = (targetKey) => {
|
|
4
|
-
const [keyPressed, setKeyPressed] = useState(false)
|
|
5
|
-
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const downHandler = ({ key }) => {
|
|
8
|
-
if (key === targetKey) {
|
|
9
|
-
setKeyPressed(true)
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
const upHandler = ({ key }) => {
|
|
13
|
-
if (key === targetKey) {
|
|
14
|
-
setKeyPressed(false)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
window.addEventListener('keydown', downHandler)
|
|
19
|
-
window.addEventListener('keyup', upHandler)
|
|
20
|
-
|
|
21
|
-
return () => {
|
|
22
|
-
window.removeEventListener('keydown', downHandler)
|
|
23
|
-
window.removeEventListener('keyup', upHandler)
|
|
24
|
-
}
|
|
25
|
-
}, [targetKey])
|
|
26
|
-
|
|
27
|
-
return keyPressed
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useKeyPress = (targetKey) => {
|
|
4
|
+
const [keyPressed, setKeyPressed] = useState(false)
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const downHandler = ({ key }) => {
|
|
8
|
+
if (key === targetKey) {
|
|
9
|
+
setKeyPressed(true)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const upHandler = ({ key }) => {
|
|
13
|
+
if (key === targetKey) {
|
|
14
|
+
setKeyPressed(false)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
window.addEventListener('keydown', downHandler)
|
|
19
|
+
window.addEventListener('keyup', upHandler)
|
|
20
|
+
|
|
21
|
+
return () => {
|
|
22
|
+
window.removeEventListener('keydown', downHandler)
|
|
23
|
+
window.removeEventListener('keyup', upHandler)
|
|
24
|
+
}
|
|
25
|
+
}, [targetKey])
|
|
26
|
+
|
|
27
|
+
return keyPressed
|
|
28
28
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export const useLazyScript = (src, delay = null) => {
|
|
4
|
+
const [status, setStatus] = React.useState(src ? 'loading' : 'idle');
|
|
5
|
+
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
if (!src) {
|
|
8
|
+
setStatus('idle');
|
|
9
|
+
return 'idle';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let script = document.querySelector(`script[src='${src}']`);
|
|
13
|
+
let timeout = null;
|
|
14
|
+
|
|
15
|
+
if (!script) {
|
|
16
|
+
if (delay) {
|
|
17
|
+
timeout = setTimeout(() => {
|
|
18
|
+
injectScript();
|
|
19
|
+
// Add event listener after the script is added
|
|
20
|
+
script.addEventListener('load', setStateStatus);
|
|
21
|
+
script.addEventListener('error', setStateStatus);
|
|
22
|
+
}, delay);
|
|
23
|
+
} else {
|
|
24
|
+
injectScript();
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
setStatus(script.getAttribute('data-status'));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const setStateStatus = (event) => {
|
|
31
|
+
setStatus(event.type === 'load' ? 'ready' : 'error');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//code to inject script
|
|
35
|
+
function injectScript() {
|
|
36
|
+
script = document.createElement('script');
|
|
37
|
+
script.src = src;
|
|
38
|
+
script.async = true;
|
|
39
|
+
script.setAttribute('data-status', 'loading');
|
|
40
|
+
document.body.appendChild(script);
|
|
41
|
+
|
|
42
|
+
const setDataStatus = (event) => {
|
|
43
|
+
script.setAttribute(
|
|
44
|
+
'data-status',
|
|
45
|
+
event.type === 'load' ? 'ready' : 'error'
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
script.addEventListener('load', setDataStatus);
|
|
50
|
+
script.addEventListener('error', setDataStatus);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (script) {
|
|
54
|
+
//script will be be undefined available when its delayed hence check it before adding listener
|
|
55
|
+
script.addEventListener('load', setStateStatus);
|
|
56
|
+
script.addEventListener('error', setStateStatus);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
if (script) {
|
|
61
|
+
script.removeEventListener('load', setStateStatus);
|
|
62
|
+
script.removeEventListener('error', setStateStatus);
|
|
63
|
+
}
|
|
64
|
+
if (timeout) {
|
|
65
|
+
clearTimeout(timeout);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}, [src]);
|
|
69
|
+
|
|
70
|
+
return status;
|
|
71
|
+
};
|
|
72
|
+
|