@weavy/uikit-react 11.0.0

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 (223) hide show
  1. package/.github/workflows/publish.yml +16 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +110 -0
  4. package/changelog.md +50 -0
  5. package/dist/cjs/index.js +39 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/types/client/WeavyClient.d.ts +16 -0
  8. package/dist/cjs/types/components/Attachment.d.ts +13 -0
  9. package/dist/cjs/types/components/Avatar.d.ts +11 -0
  10. package/dist/cjs/types/components/Chat.d.ts +4 -0
  11. package/dist/cjs/types/components/Conversation.d.ts +4 -0
  12. package/dist/cjs/types/components/ConversationBadge.d.ts +3 -0
  13. package/dist/cjs/types/components/ConversationForm.d.ts +7 -0
  14. package/dist/cjs/types/components/ConversationList.d.ts +3 -0
  15. package/dist/cjs/types/components/ConversationListItem.d.ts +4 -0
  16. package/dist/cjs/types/components/File.d.ts +9 -0
  17. package/dist/cjs/types/components/FileBrowser.d.ts +6 -0
  18. package/dist/cjs/types/components/Image.d.ts +16 -0
  19. package/dist/cjs/types/components/Meeting.d.ts +8 -0
  20. package/dist/cjs/types/components/MeetingCard.d.ts +6 -0
  21. package/dist/cjs/types/components/Meetings.d.ts +6 -0
  22. package/dist/cjs/types/components/Message.d.ts +4 -0
  23. package/dist/cjs/types/components/Messages.d.ts +9 -0
  24. package/dist/cjs/types/components/Messenger.d.ts +4 -0
  25. package/dist/cjs/types/components/NewConversation.d.ts +3 -0
  26. package/dist/cjs/types/components/Presence.d.ts +7 -0
  27. package/dist/cjs/types/components/Reactions.d.ts +13 -0
  28. package/dist/cjs/types/components/SearchUsers.d.ts +7 -0
  29. package/dist/cjs/types/components/SeenBy.d.ts +9 -0
  30. package/dist/cjs/types/components/Typing.d.ts +8 -0
  31. package/dist/cjs/types/contexts/MessengerContext.d.ts +8 -0
  32. package/dist/cjs/types/contexts/PreviewContext.d.ts +7 -0
  33. package/dist/cjs/types/contexts/UserContext.d.ts +8 -0
  34. package/dist/cjs/types/contexts/WeavyContext.d.ts +10 -0
  35. package/dist/cjs/types/hooks/useBadge.d.ts +1 -0
  36. package/dist/cjs/types/hooks/useChat.d.ts +1 -0
  37. package/dist/cjs/types/hooks/useConversation.d.ts +1 -0
  38. package/dist/cjs/types/hooks/useConversations.d.ts +1 -0
  39. package/dist/cjs/types/hooks/useDebounce.d.ts +2 -0
  40. package/dist/cjs/types/hooks/useEvents.d.ts +6 -0
  41. package/dist/cjs/types/hooks/useFileUploader.d.ts +1 -0
  42. package/dist/cjs/types/hooks/useMembers.d.ts +1 -0
  43. package/dist/cjs/types/hooks/useMessages.d.ts +1 -0
  44. package/dist/cjs/types/hooks/useMutateChat.d.ts +4 -0
  45. package/dist/cjs/types/hooks/useMutateConversation.d.ts +3 -0
  46. package/dist/cjs/types/hooks/useMutateConversationName.d.ts +4 -0
  47. package/dist/cjs/types/hooks/useMutateDeleteReaction.d.ts +4 -0
  48. package/dist/cjs/types/hooks/useMutateExternalBlobs.d.ts +3 -0
  49. package/dist/cjs/types/hooks/useMutateMeeting.d.ts +3 -0
  50. package/dist/cjs/types/hooks/useMutateMembers.d.ts +4 -0
  51. package/dist/cjs/types/hooks/useMutateMessage.d.ts +9 -0
  52. package/dist/cjs/types/hooks/useMutatePinned.d.ts +4 -0
  53. package/dist/cjs/types/hooks/useMutateReaction.d.ts +4 -0
  54. package/dist/cjs/types/hooks/useMutateRead.d.ts +4 -0
  55. package/dist/cjs/types/hooks/useMutateRemoveMembers.d.ts +4 -0
  56. package/dist/cjs/types/hooks/useMutateTyping.d.ts +3 -0
  57. package/dist/cjs/types/hooks/usePresence.d.ts +1 -0
  58. package/dist/cjs/types/hooks/usePreview.d.ts +4 -0
  59. package/dist/cjs/types/hooks/useReactions.d.ts +3 -0
  60. package/dist/cjs/types/hooks/useSearchUsers.d.ts +1 -0
  61. package/dist/cjs/types/hooks/useThrottle.d.ts +2 -0
  62. package/dist/cjs/types/hooks/useUser.d.ts +1 -0
  63. package/dist/cjs/types/index.d.ts +15 -0
  64. package/dist/cjs/types/types/Chat.d.ts +3 -0
  65. package/dist/cjs/types/types/Conversation.d.ts +4 -0
  66. package/dist/cjs/types/types/ConversationListItem.d.ts +4 -0
  67. package/dist/cjs/types/types/Message.d.ts +15 -0
  68. package/dist/cjs/types/types/Messenger.d.ts +3 -0
  69. package/dist/cjs/types/types/types.d.ts +150 -0
  70. package/dist/cjs/types/ui/Button.d.ts +4 -0
  71. package/dist/cjs/types/ui/Dropdown.d.ts +19 -0
  72. package/dist/cjs/types/ui/Icon.d.ts +10 -0
  73. package/dist/cjs/types/ui/Overlay.d.ts +12 -0
  74. package/dist/cjs/types/utils/fileUtilities.d.ts +5 -0
  75. package/dist/cjs/types/utils/styles.d.ts +17 -0
  76. package/dist/esm/index.js +39 -0
  77. package/dist/esm/index.js.map +1 -0
  78. package/dist/esm/types/client/WeavyClient.d.ts +16 -0
  79. package/dist/esm/types/components/Attachment.d.ts +13 -0
  80. package/dist/esm/types/components/Avatar.d.ts +11 -0
  81. package/dist/esm/types/components/Chat.d.ts +4 -0
  82. package/dist/esm/types/components/Conversation.d.ts +4 -0
  83. package/dist/esm/types/components/ConversationBadge.d.ts +3 -0
  84. package/dist/esm/types/components/ConversationForm.d.ts +7 -0
  85. package/dist/esm/types/components/ConversationList.d.ts +3 -0
  86. package/dist/esm/types/components/ConversationListItem.d.ts +4 -0
  87. package/dist/esm/types/components/File.d.ts +9 -0
  88. package/dist/esm/types/components/FileBrowser.d.ts +6 -0
  89. package/dist/esm/types/components/Image.d.ts +16 -0
  90. package/dist/esm/types/components/Meeting.d.ts +8 -0
  91. package/dist/esm/types/components/MeetingCard.d.ts +6 -0
  92. package/dist/esm/types/components/Meetings.d.ts +6 -0
  93. package/dist/esm/types/components/Message.d.ts +4 -0
  94. package/dist/esm/types/components/Messages.d.ts +9 -0
  95. package/dist/esm/types/components/Messenger.d.ts +4 -0
  96. package/dist/esm/types/components/NewConversation.d.ts +3 -0
  97. package/dist/esm/types/components/Presence.d.ts +7 -0
  98. package/dist/esm/types/components/Reactions.d.ts +13 -0
  99. package/dist/esm/types/components/SearchUsers.d.ts +7 -0
  100. package/dist/esm/types/components/SeenBy.d.ts +9 -0
  101. package/dist/esm/types/components/Typing.d.ts +8 -0
  102. package/dist/esm/types/contexts/MessengerContext.d.ts +8 -0
  103. package/dist/esm/types/contexts/PreviewContext.d.ts +7 -0
  104. package/dist/esm/types/contexts/UserContext.d.ts +8 -0
  105. package/dist/esm/types/contexts/WeavyContext.d.ts +10 -0
  106. package/dist/esm/types/hooks/useBadge.d.ts +1 -0
  107. package/dist/esm/types/hooks/useChat.d.ts +1 -0
  108. package/dist/esm/types/hooks/useConversation.d.ts +1 -0
  109. package/dist/esm/types/hooks/useConversations.d.ts +1 -0
  110. package/dist/esm/types/hooks/useDebounce.d.ts +2 -0
  111. package/dist/esm/types/hooks/useEvents.d.ts +6 -0
  112. package/dist/esm/types/hooks/useFileUploader.d.ts +1 -0
  113. package/dist/esm/types/hooks/useMembers.d.ts +1 -0
  114. package/dist/esm/types/hooks/useMessages.d.ts +1 -0
  115. package/dist/esm/types/hooks/useMutateChat.d.ts +4 -0
  116. package/dist/esm/types/hooks/useMutateConversation.d.ts +3 -0
  117. package/dist/esm/types/hooks/useMutateConversationName.d.ts +4 -0
  118. package/dist/esm/types/hooks/useMutateDeleteReaction.d.ts +4 -0
  119. package/dist/esm/types/hooks/useMutateExternalBlobs.d.ts +3 -0
  120. package/dist/esm/types/hooks/useMutateMeeting.d.ts +3 -0
  121. package/dist/esm/types/hooks/useMutateMembers.d.ts +4 -0
  122. package/dist/esm/types/hooks/useMutateMessage.d.ts +9 -0
  123. package/dist/esm/types/hooks/useMutatePinned.d.ts +4 -0
  124. package/dist/esm/types/hooks/useMutateReaction.d.ts +4 -0
  125. package/dist/esm/types/hooks/useMutateRead.d.ts +4 -0
  126. package/dist/esm/types/hooks/useMutateRemoveMembers.d.ts +4 -0
  127. package/dist/esm/types/hooks/useMutateTyping.d.ts +3 -0
  128. package/dist/esm/types/hooks/usePresence.d.ts +1 -0
  129. package/dist/esm/types/hooks/usePreview.d.ts +4 -0
  130. package/dist/esm/types/hooks/useReactions.d.ts +3 -0
  131. package/dist/esm/types/hooks/useSearchUsers.d.ts +1 -0
  132. package/dist/esm/types/hooks/useThrottle.d.ts +2 -0
  133. package/dist/esm/types/hooks/useUser.d.ts +1 -0
  134. package/dist/esm/types/index.d.ts +15 -0
  135. package/dist/esm/types/types/Chat.d.ts +3 -0
  136. package/dist/esm/types/types/Conversation.d.ts +4 -0
  137. package/dist/esm/types/types/ConversationListItem.d.ts +4 -0
  138. package/dist/esm/types/types/Message.d.ts +15 -0
  139. package/dist/esm/types/types/Messenger.d.ts +3 -0
  140. package/dist/esm/types/types/types.d.ts +150 -0
  141. package/dist/esm/types/ui/Button.d.ts +4 -0
  142. package/dist/esm/types/ui/Dropdown.d.ts +19 -0
  143. package/dist/esm/types/ui/Icon.d.ts +10 -0
  144. package/dist/esm/types/ui/Overlay.d.ts +12 -0
  145. package/dist/esm/types/utils/fileUtilities.d.ts +5 -0
  146. package/dist/esm/types/utils/styles.d.ts +17 -0
  147. package/dist/index.d.ts +98 -0
  148. package/package.json +47 -0
  149. package/rollup.config.js +41 -0
  150. package/src/client/WeavyClient.ts +95 -0
  151. package/src/components/Attachment.tsx +33 -0
  152. package/src/components/Avatar.tsx +26 -0
  153. package/src/components/Chat.tsx +68 -0
  154. package/src/components/Conversation.tsx +220 -0
  155. package/src/components/ConversationBadge.tsx +44 -0
  156. package/src/components/ConversationForm.tsx +217 -0
  157. package/src/components/ConversationList.tsx +61 -0
  158. package/src/components/ConversationListItem.tsx +155 -0
  159. package/src/components/File.tsx +21 -0
  160. package/src/components/FileBrowser.tsx +86 -0
  161. package/src/components/Image.tsx +66 -0
  162. package/src/components/Meeting.tsx +21 -0
  163. package/src/components/MeetingCard.tsx +31 -0
  164. package/src/components/Meetings.tsx +58 -0
  165. package/src/components/Message.tsx +90 -0
  166. package/src/components/Messages.tsx +271 -0
  167. package/src/components/Messenger.tsx +34 -0
  168. package/src/components/NewConversation.tsx +50 -0
  169. package/src/components/Presence.tsx +15 -0
  170. package/src/components/Reactions.tsx +95 -0
  171. package/src/components/SearchUsers.tsx +90 -0
  172. package/src/components/SeenBy.tsx +26 -0
  173. package/src/components/Typing.tsx +131 -0
  174. package/src/contexts/MessengerContext.tsx +44 -0
  175. package/src/contexts/PreviewContext.tsx +105 -0
  176. package/src/contexts/UserContext.tsx +31 -0
  177. package/src/contexts/WeavyContext.tsx +66 -0
  178. package/src/hooks/useBadge.ts +32 -0
  179. package/src/hooks/useChat.ts +32 -0
  180. package/src/hooks/useConversation.ts +28 -0
  181. package/src/hooks/useConversations.ts +27 -0
  182. package/src/hooks/useDebounce.ts +22 -0
  183. package/src/hooks/useEvents.ts +43 -0
  184. package/src/hooks/useFileUploader.ts +35 -0
  185. package/src/hooks/useMembers.ts +27 -0
  186. package/src/hooks/useMessages.ts +42 -0
  187. package/src/hooks/useMessenger.ts +51 -0
  188. package/src/hooks/useMutateChat.ts +44 -0
  189. package/src/hooks/useMutateConversation.ts +40 -0
  190. package/src/hooks/useMutateConversationName.ts +41 -0
  191. package/src/hooks/useMutateDeleteReaction.ts +38 -0
  192. package/src/hooks/useMutateExternalBlobs.ts +39 -0
  193. package/src/hooks/useMutateMeeting.ts +39 -0
  194. package/src/hooks/useMutateMembers.ts +43 -0
  195. package/src/hooks/useMutateMessage.ts +116 -0
  196. package/src/hooks/useMutatePinned.ts +40 -0
  197. package/src/hooks/useMutateReaction.ts +38 -0
  198. package/src/hooks/useMutateRead.ts +40 -0
  199. package/src/hooks/useMutateRemoveMembers.ts +43 -0
  200. package/src/hooks/useMutateTyping.ts +34 -0
  201. package/src/hooks/usePresence.ts +32 -0
  202. package/src/hooks/usePreview.ts +21 -0
  203. package/src/hooks/useReactions.ts +53 -0
  204. package/src/hooks/useSearchUsers.ts +26 -0
  205. package/src/hooks/useThrottle.ts +13 -0
  206. package/src/hooks/useUser.ts +38 -0
  207. package/src/index.ts +33 -0
  208. package/src/types/Chat.ts +3 -0
  209. package/src/types/Conversation.ts +4 -0
  210. package/src/types/ConversationListItem.ts +4 -0
  211. package/src/types/Message.ts +16 -0
  212. package/src/types/Messenger.ts +3 -0
  213. package/src/types/emoji-toolkit.d.ts +1 -0
  214. package/src/types/types.ts +175 -0
  215. package/src/ui/Button.tsx +32 -0
  216. package/src/ui/Dropdown.tsx +58 -0
  217. package/src/ui/Icon.tsx +79 -0
  218. package/src/ui/Overlay.tsx +41 -0
  219. package/src/utils/fileUtilities.ts +230 -0
  220. package/src/utils/infiniteScroll.js +175 -0
  221. package/src/utils/scrollToBottom.js +75 -0
  222. package/src/utils/styles.ts +42 -0
  223. package/tsconfig.json +108 -0
@@ -0,0 +1,43 @@
1
+ import { useContext } from "react";
2
+ import { useMutation, useQueryClient } from "react-query";
3
+ import { MessengerContext } from "../contexts/MessengerContext";
4
+ import { WeavyContext } from "../contexts/WeavyContext";
5
+
6
+ /// DELETE to remove members from an app
7
+ export default function useMutateRemoveMembers() {
8
+
9
+ const { client } = useContext(WeavyContext);
10
+ const { setSelectedConversationId } = useContext(MessengerContext);
11
+ const queryClient = useQueryClient();
12
+
13
+ if (!client) {
14
+ throw new Error('useMutateRemoveMembers must be used within an WeavyProvider');
15
+ }
16
+
17
+
18
+ type MutateProps = {
19
+ id: number | null,
20
+ members: number[]
21
+ }
22
+
23
+ const mutateRemove = async ({ id, members }: MutateProps) => {
24
+
25
+ const response = await fetch(client.uri + "/api/apps/" + id + "/members/" + members.join(","), {
26
+ method: "DELETE",
27
+ body: JSON.stringify(members),
28
+ headers: {
29
+ "content-type": "application/json",
30
+ "Authorization": "Bearer " + await client.tokenFactory()
31
+ }
32
+ });
33
+
34
+ return response;
35
+ };
36
+
37
+ return useMutation(mutateRemove, {
38
+ onSuccess: () => {
39
+ queryClient.invalidateQueries("conversations");
40
+ setSelectedConversationId(null);
41
+ }
42
+ });
43
+ }
@@ -0,0 +1,34 @@
1
+ import { useContext } from "react";
2
+ import { useMutation } from "react-query";
3
+ import { WeavyContext } from "../contexts/WeavyContext";
4
+
5
+ /// PUT to add typing to a conversation
6
+ export default function useMutateTyping() {
7
+
8
+ const { client } = useContext(WeavyContext);
9
+
10
+ if (!client) {
11
+ throw new Error('useMutateTyping must be used within an WeavyProvider');
12
+ }
13
+
14
+
15
+ type MutateProps = {
16
+ id: number | null
17
+ }
18
+
19
+ const mutateTyping = async ({ id }: MutateProps) => {
20
+
21
+ const response = await fetch(client.uri + "/api/conversations/" + id + "/typing", {
22
+ method: "PUT",
23
+ body: JSON.stringify({}),
24
+ headers: {
25
+ "content-type": "application/json",
26
+ "Authorization": "Bearer " + await client.tokenFactory()
27
+ }
28
+ });
29
+
30
+ return response;
31
+ };
32
+
33
+ return useMutation(mutateTyping, { });
34
+ }
@@ -0,0 +1,32 @@
1
+ import { useContext, useEffect } from "react";
2
+ import { WeavyContext } from "../contexts/WeavyContext";
3
+ import { prefix as wy } from "../utils/styles";
4
+
5
+ export default function usePresence() {
6
+
7
+ const {client} = useContext(WeavyContext);
8
+
9
+ useEffect(() => {
10
+ client.subscribe("online", "online", handlePresenceChange)
11
+ }, []);
12
+
13
+ const handlePresenceChange = (data: any) => {
14
+
15
+ if (Array.isArray(data)) {
16
+ document.querySelectorAll(wy(".presence")).forEach(function (item) {
17
+ item.classList.remove(wy("presence-active"));
18
+ });
19
+
20
+ data.forEach(function (id) {
21
+ document.querySelectorAll("[data-presence-id='" + id + "']").forEach(function (item) {
22
+ item.classList.add(wy("presence-active"));
23
+ });
24
+ });
25
+ } else {
26
+ document.querySelectorAll("[data-presence-id='" + data + "']").forEach(function (item) {
27
+ item.classList.add(wy("presence-active"));
28
+ });
29
+ }
30
+ }
31
+
32
+ }
@@ -0,0 +1,21 @@
1
+ import { useContext, useEffect } from "react";
2
+ import { PreviewContext } from "../contexts/PreviewContext";
3
+
4
+
5
+ export default function usePreview(attachments: AttachmentType[]) {
6
+
7
+ const { openPreview, closePreview } = useContext(PreviewContext);
8
+
9
+ const open = (attachmentId: number) => {
10
+ openPreview(attachments, attachmentId);
11
+ }
12
+
13
+ const close = () => {
14
+ closePreview()
15
+ }
16
+
17
+ return {
18
+ open,
19
+ close
20
+ }
21
+ }
@@ -0,0 +1,53 @@
1
+ import { useCallback, useContext, useEffect, useLayoutEffect, useState } from "react";
2
+ import { UserContext } from "../contexts/UserContext";
3
+ import useEvents from "./useEvents";
4
+
5
+
6
+ export default function useReactions(id: number, reactions: ReactableType[]) {
7
+ const { on, off } = useEvents();
8
+ const { user } = useContext(UserContext);
9
+ const [reactionsList, setReactionsList] = useState<ReactableType[]>([]);
10
+
11
+ const groupReactions = useCallback((data: ReactableType[]) => {
12
+ var group = [...new Map<string, ReactableType>(data.map((item: ReactableType) => [item.content, item])).values()];
13
+
14
+ return group.map((item: ReactableType): ReactionGroup => {
15
+ return {
16
+ content: item.content,
17
+ count: data.filter((r) => r.content === item.content).length,
18
+ has_reacted: data.filter((r) => r.content === item.content && r.created_by_id === user.id).length > 0
19
+ }
20
+ });
21
+ }, [reactionsList]);
22
+
23
+ const handleRealtimeReactionInserted = useCallback((reaction: ReactionType) => {
24
+ if (reaction.parent.id === id) {
25
+ setReactionsList((oldList) => {
26
+ return [...oldList || [], { content: reaction.content, created_by_id: reaction.created_by.id }];
27
+ });
28
+ }
29
+ }, [id, reactionsList]);
30
+
31
+ const handleRealtimeReactionDeleted = useCallback((reaction: ReactionType) => {
32
+ if (reaction.parent.id === id) {
33
+ setReactionsList(oldList => oldList.filter(item => item.created_by_id !== reaction.created_by.id));
34
+ }
35
+ }, [id, reactionsList]);
36
+
37
+ useLayoutEffect(() => {
38
+ setReactionsList(reactions || []);
39
+ }, [reactions]);
40
+
41
+ useEffect(() => {
42
+
43
+ on('reaction-inserted', handleRealtimeReactionInserted);
44
+ on('reaction-deleted', handleRealtimeReactionDeleted);
45
+
46
+ return () => {
47
+ off('reaction-inserted', handleRealtimeReactionInserted);
48
+ off('reaction-deleted', handleRealtimeReactionDeleted);
49
+ }
50
+ }, [id]);
51
+
52
+ return { reactionsList: groupReactions(reactionsList) };
53
+ }
@@ -0,0 +1,26 @@
1
+ import { useContext } from "react";
2
+ import { useInfiniteQuery, useQuery } from "react-query";
3
+ import { WeavyContext } from "../contexts/WeavyContext";
4
+
5
+ /// GET users by search query
6
+ export default function useSearchUsers(text: string, options: any) {
7
+ const PAGE_SIZE = 10;
8
+ const { client } = useContext(WeavyContext);
9
+
10
+ if (!client) {
11
+ throw new Error('useSearchUsers must be used within an WeavyProvider');
12
+ }
13
+
14
+ const getUsers = async () => {
15
+ const response = await fetch(client.uri + "/api/users?q=" + text + "&skip=0&top=" + PAGE_SIZE, {
16
+ headers: {
17
+ "content-type": "application/json",
18
+ "Authorization": "Bearer " + await client.tokenFactory()
19
+ }
20
+ });
21
+ const data = await response.json();
22
+ return data;
23
+ };
24
+
25
+ return useQuery<MembersResult>('users', getUsers, options)
26
+ }
@@ -0,0 +1,13 @@
1
+ import throttle from "lodash.throttle"
2
+ import { useCallback, useEffect, useRef } from "react";
3
+
4
+ export default function useThrottle(cb: any, delay: number) {
5
+ const options = { leading: true, trailing: false }; // add custom lodash options
6
+ const cbRef = useRef(cb);
7
+ // use mutable ref to make useCallback/throttle not depend on `cb` dep
8
+ useEffect(() => { cbRef.current = cb; });
9
+ return useCallback(
10
+ throttle((...args) => cbRef.current(...args), delay, options),
11
+ [delay]
12
+ );
13
+ }
@@ -0,0 +1,38 @@
1
+ //import { useContext } from "react";
2
+ import { useQuery } from "react-query";
3
+ //import { WeavyContext } from "../contexts/WeavyContext";
4
+
5
+ /// GET current user
6
+ export default function useUser(client: any) {
7
+ //const { client } = useContext(WeavyContext);
8
+
9
+ if (!client) {
10
+ throw new Error('useUser must be used within an WeavyProvider');
11
+ }
12
+
13
+ const getUser = async () => {
14
+
15
+ try {
16
+ const response = await fetch(client.uri + "/api/user", {
17
+ headers: {
18
+ "content-type": "application/json",
19
+ "Authorization": "Bearer " + await client.tokenFactory()
20
+ }
21
+ });
22
+
23
+ if(response.ok){
24
+ return await response.json();
25
+ }
26
+
27
+ console.error("Could not load Weavy user data...")
28
+ return null;
29
+ } catch(err: any){
30
+ console.error(`Could not connect to the Weavy backend. Please make sure ${client.uri} is up and running!`)
31
+ }
32
+
33
+
34
+ };
35
+
36
+
37
+ return useQuery<UserType>("user", getUser);
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import WeavyClient from './client/WeavyClient';
2
+ import WeavyProvider from './contexts/WeavyContext';
3
+ import { WeavyContext } from './contexts/WeavyContext';
4
+ import MessengerProvider from './contexts/MessengerContext';
5
+ import { MessengerContext } from './contexts/MessengerContext';
6
+ import Messenger from './components/Messenger';
7
+ import ConversationBadge from './components/ConversationBadge';
8
+ import ConversationList from './components/ConversationList';
9
+ import Conversation from './components/Conversation';
10
+ import Chat from './components/Chat';
11
+ import Button from './ui/Button';
12
+ import Dropdown from './ui/Dropdown';
13
+ import Icon from './ui/Icon';
14
+ import Overlay from './ui/Overlay';
15
+ // import { useMessenger } from './hooks/useMessenger';
16
+
17
+ export {
18
+ WeavyClient,
19
+ WeavyContext,
20
+ WeavyProvider,
21
+ MessengerProvider,
22
+ MessengerContext,
23
+ Messenger,
24
+ ConversationList,
25
+ Conversation,
26
+ Chat,
27
+ ConversationBadge,
28
+ Button,
29
+ Dropdown,
30
+ Icon,
31
+ Overlay
32
+ //useMessenger
33
+ }
@@ -0,0 +1,3 @@
1
+ export interface ChatProps {
2
+ id: string
3
+ }
@@ -0,0 +1,4 @@
1
+ export interface ConversationProps {
2
+ id?: number | null,
3
+ showBackButton?: boolean
4
+ }
@@ -0,0 +1,4 @@
1
+ export interface ConversationListItemProps {
2
+ item: ConversationType,
3
+ refetchConversations: Function
4
+ }
@@ -0,0 +1,16 @@
1
+ export interface MessageProps {
2
+ id: number,
3
+ html: string,
4
+ temp?: boolean | false,
5
+ me: boolean,
6
+ avatar?: string,
7
+ name: string,
8
+ created_at: string,
9
+ attachments: AttachmentType[],
10
+ meeting: MeetingCardType,
11
+ parentId: number | null,
12
+ reactions: ReactableType[],
13
+ reactions_count?: number,
14
+ seenBy: MemberType[]
15
+ }
16
+
@@ -0,0 +1,3 @@
1
+ export interface Messenger {
2
+ options?: MessengerContextOptions
3
+ }
@@ -0,0 +1 @@
1
+ declare module 'emoji-toolkit';
@@ -0,0 +1,175 @@
1
+ type WeavyClientOptions = {
2
+ uri: string,
3
+ tokenFactory: (() => string | Promise<string>)
4
+ }
5
+
6
+ type WeavyContextProps = {
7
+ client: any,
8
+ options?: WeavyContextOptions
9
+ };
10
+
11
+ type WeavyContextOptions = {
12
+ zoomAuthenticationUrl?: string,
13
+ teamsAuthenticationUrl?: string,
14
+ enableCloudFiles?: boolean,
15
+ filebrowserUrl?: string
16
+ }
17
+
18
+ type MessengerContextProps = {
19
+ options?: MessengerContextOptions,
20
+ selectedConversationId: null | number,
21
+ setSelectedConversationId: Function
22
+ };
23
+
24
+ type UserContextProps = {
25
+ user: UserType
26
+ };
27
+
28
+
29
+ type MessengerContextOptions = {
30
+ reactions?: string[]
31
+ }
32
+
33
+ type PreviewContextProps = {
34
+ openPreview: Function,
35
+ closePreview: Function
36
+ }
37
+
38
+
39
+ type ProviderProps = {
40
+ children: React.ReactNode,
41
+ client: any
42
+ };
43
+
44
+ type InsertConversationProps = {
45
+ title: string,
46
+ text: string
47
+ }
48
+
49
+ type ConversationsResult = {
50
+ data: ConversationType[],
51
+ start: number,
52
+ end: number,
53
+ count: number
54
+ }
55
+
56
+
57
+ type MembersResult = {
58
+ data: MemberType[],
59
+ start: number,
60
+ end: number,
61
+ count: number
62
+ }
63
+
64
+ type MessagesResult = {
65
+ data: MessageType[],
66
+ start: number,
67
+ end: number,
68
+ count: number
69
+ }
70
+
71
+ type ConversationType = {
72
+ id: number,
73
+ display_name: string,
74
+ last_message: MessageType,
75
+ is_unread : boolean,
76
+ is_pinned: boolean,
77
+ type: string,
78
+ member_ids: number[],
79
+ avatar_url: string
80
+ }
81
+
82
+ type MemberType = {
83
+ id: number,
84
+ name: string,
85
+ display_name: string,
86
+ avatar_url: string,
87
+ delivered_at: string,
88
+ read_at: string,
89
+ presence: string
90
+ }
91
+
92
+ type MessageType = {
93
+ id: number,
94
+ html: string,
95
+ text: string,
96
+ app_id: number,
97
+ temp?: boolean,
98
+ created_at: string,
99
+ created_by: MemberType,
100
+ attachments: AttachmentType[],
101
+ attachment_ids: number[],
102
+ meeting: MeetingCardType,
103
+ meeting_id?: number,
104
+ reactions: ReactableType[],
105
+ }
106
+
107
+ type UserType = {
108
+ id: number,
109
+ username: string,
110
+ email: string,
111
+ name: string,
112
+ title: string,
113
+ avatar_url: string,
114
+ presence: string
115
+ }
116
+
117
+ type FileType = {
118
+ id: number,
119
+ name: string
120
+ }
121
+
122
+ type AttachmentType = {
123
+ id: number,
124
+ name: string,
125
+ kind: string,
126
+ media_type: string,
127
+ width: number,
128
+ height: number,
129
+ size: number,
130
+ provider: string,
131
+ download_url: string,
132
+ preview_url: string,
133
+ thumbnail_url: string,
134
+ external_url: string
135
+ }
136
+
137
+ type ReactionType = {
138
+ id: number,
139
+ parent: MessageType,
140
+ content: string,
141
+ created_by: MemberType,
142
+ count?: number
143
+ }
144
+
145
+ type ReactableType = {
146
+ content: string,
147
+ created_by_id: number
148
+ }
149
+
150
+ type ReactionGroup = {
151
+ content: string,
152
+ count: number,
153
+ has_reacted: boolean
154
+ }
155
+
156
+ type MeetingType = {
157
+ id: number,
158
+ provider: string
159
+ }
160
+
161
+ type MeetingCardType = {
162
+ id: number,
163
+ provider: string,
164
+ provider_id: string,
165
+ uuid: string,
166
+ join_url: string,
167
+ recording_url: string,
168
+ ended_at: string
169
+ }
170
+
171
+ type BadgeType = {
172
+ private: number,
173
+ rooms: number,
174
+ chat: number
175
+ }
@@ -0,0 +1,32 @@
1
+ import React, { Children } from "react";
2
+ import Icon from "./Icon";
3
+ import classNames from "classnames";
4
+ import { prefix as wy } from "../utils/styles";
5
+
6
+ type Props = {
7
+ active?: boolean,
8
+ type?: "button" | "submit" | "reset",
9
+ onClick?: (e: any) => void,
10
+ className?: string,
11
+ children: React.ReactNode,
12
+ props?: React.ButtonHTMLAttributes<HTMLButtonElement>
13
+ }
14
+
15
+ const Button: any = ({ active = false, type = "button", onClick, className = "", children, ...props }: Props) => {
16
+ let singleChild: any = Children.count(children) === 1 && Children.toArray(children).pop();
17
+
18
+ let buttonClassNames = classNames(
19
+ wy('button'),
20
+ className,
21
+ {
22
+ [wy('active')]: active,
23
+ [wy('button-icon')]: singleChild?.type === Icon.UI
24
+ }
25
+ );
26
+
27
+ return <button type={type} className={buttonClassNames} onClick={onClick} { ...props }>{children}</button>
28
+ }
29
+
30
+ // Export as replacable UI component
31
+ const UIButton = { UI: Button };
32
+ export default UIButton;
@@ -0,0 +1,58 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import classNames from 'classnames';
3
+ import Icon from "./Icon";
4
+ import Button from "./Button";
5
+ import { prefix as wy } from "../utils/styles";
6
+
7
+ type DropdownProps = {
8
+ directionX?: "left" | "right";
9
+ directionY?: "up" | "down";
10
+ children: React.ReactNode,
11
+ className?: string,
12
+ props?: React.HTMLAttributes<HTMLSpanElement>
13
+ }
14
+
15
+ const Dropdown = ({ directionX = "right", directionY = "down", children, className = "", ...props }: DropdownProps) => {
16
+ const [visible, setVisible] = useState<boolean>(false);
17
+
18
+ useEffect(() => {
19
+ if (visible) {
20
+ document.addEventListener("click", () => { setVisible(false) });
21
+ } else {
22
+ document.removeEventListener("click", () => { setVisible(false) });
23
+ }
24
+
25
+ }, [visible]);
26
+
27
+ const handleMenuClick = (e: any) => {
28
+ e.stopPropagation();
29
+ setVisible(!visible);
30
+ }
31
+
32
+ return (
33
+ <span className={classNames(wy("dropdown"), { [wy("dropup")]: directionY === "up" }, className)} {...props}>
34
+ <Button.UI onClick={(e: any) => handleMenuClick(e)} className={wy(classNames({ "active": visible }))}>
35
+ <Icon.UI name="dots-vertical" />
36
+ </Button.UI>
37
+
38
+ <div className={wy(classNames("dropdown-menu", { "dropdown-menu-end": directionX === "left" }))} hidden={!visible}>
39
+ {children}
40
+ </div>
41
+ </span>
42
+
43
+ )
44
+
45
+ }
46
+ type ItemProps = {
47
+ children: React.ReactNode,
48
+ className?: string,
49
+ onClick?: (e: any) => void,
50
+ props?: React.HTMLAttributes<HTMLDivElement>
51
+ }
52
+ const DropdownItem = ({ children, className = "", onClick, ...props }: ItemProps) => {
53
+ return <div className={classNames(wy("dropdown-item"), className)} onClick={onClick} {...props}>{children}</div>
54
+ }
55
+
56
+ // Export as replacable UI component
57
+ const UIDropdown = { UI: Dropdown, Item: DropdownItem };
58
+ export default UIDropdown;