npm-pkg-hook 1.5.5 → 1.5.6
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/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -9,7 +9,9 @@ export * from './statusOpenStores'
|
|
|
9
9
|
export * from './useCategoriesProduct'
|
|
10
10
|
export * from './useLogout'
|
|
11
11
|
export * from './useStatusOpenStore'
|
|
12
|
+
export * from './useChatRoomSubscription'
|
|
12
13
|
export * from './useScheduleData'
|
|
14
|
+
export * from './useGetMessagesToRoom'
|
|
13
15
|
export * from './useOrders'
|
|
14
16
|
export * from './usePushNotifications'
|
|
15
17
|
export * from './useLocationManager'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSubscription, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const NEW_CHAT_ROOM_MESSAGE_SUBSCRIPTION = gql`
|
|
4
|
+
subscription NewChatRoomMessage($codeRoom: String!) {
|
|
5
|
+
newChatRoomMessage(codeRoom: $codeRoom) {
|
|
6
|
+
uuid
|
|
7
|
+
content
|
|
8
|
+
aDatCre
|
|
9
|
+
from
|
|
10
|
+
to
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
export const chatRoomSubscription = (codeRoom, onMessageReceived) => {
|
|
16
|
+
const subscription = useSubscription(NEW_CHAT_ROOM_MESSAGE_SUBSCRIPTION, {
|
|
17
|
+
variables: { codeRoom },
|
|
18
|
+
onSubscriptionData: ({ client, subscriptionData }) => {
|
|
19
|
+
if (subscriptionData.data && subscriptionData.data.newChatRoomMessage) {
|
|
20
|
+
// Llama a la función proporcionada cuando se recibe un nuevo mensaje
|
|
21
|
+
onMessageReceived(subscriptionData.data.newChatRoomMessage)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Puedes ajustar lo que devuelve el hook según tus necesidades
|
|
27
|
+
return subscription
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
// Define la consulta GraphQL
|
|
4
|
+
const GET_MESSAGES = gql`
|
|
5
|
+
query getMessages($codeRoom: String!, $id: String!) {
|
|
6
|
+
getMessages(codeRoom: $codeRoom, id: $id) {
|
|
7
|
+
uuid
|
|
8
|
+
content
|
|
9
|
+
from
|
|
10
|
+
to
|
|
11
|
+
aDatCre
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
export const useGetMessagesToRoom = (codeRoom, id) => {
|
|
17
|
+
const { loading, error, data } = useQuery(GET_MESSAGES, {
|
|
18
|
+
context: { clientName: 'web-socket-chat' },
|
|
19
|
+
variables: { codeRoom, id }
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return [data?.getMessages ?? [], { loading, error }]
|
|
23
|
+
}
|
package/src/utils/index.js
CHANGED
|
@@ -166,3 +166,10 @@ export const convertBase64 = file => {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
export const validationImg = file => { return (/\.(jpg|png|gif|jpeg)$/i).test(file.name) }
|
|
169
|
+
|
|
170
|
+
export const SERVICES = Object.freeze({
|
|
171
|
+
WEB_SOCKET_CHAT: 'web-socket-chat',
|
|
172
|
+
ADMIN_SERVER: 'admin-server',
|
|
173
|
+
ADMIN_STORE: 'admin-store',
|
|
174
|
+
MAIN: 'main'
|
|
175
|
+
})
|