@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.
- package/.github/workflows/publish.yml +16 -0
- package/LICENSE.md +21 -0
- package/README.md +110 -0
- package/changelog.md +50 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/client/WeavyClient.d.ts +16 -0
- package/dist/cjs/types/components/Attachment.d.ts +13 -0
- package/dist/cjs/types/components/Avatar.d.ts +11 -0
- package/dist/cjs/types/components/Chat.d.ts +4 -0
- package/dist/cjs/types/components/Conversation.d.ts +4 -0
- package/dist/cjs/types/components/ConversationBadge.d.ts +3 -0
- package/dist/cjs/types/components/ConversationForm.d.ts +7 -0
- package/dist/cjs/types/components/ConversationList.d.ts +3 -0
- package/dist/cjs/types/components/ConversationListItem.d.ts +4 -0
- package/dist/cjs/types/components/File.d.ts +9 -0
- package/dist/cjs/types/components/FileBrowser.d.ts +6 -0
- package/dist/cjs/types/components/Image.d.ts +16 -0
- package/dist/cjs/types/components/Meeting.d.ts +8 -0
- package/dist/cjs/types/components/MeetingCard.d.ts +6 -0
- package/dist/cjs/types/components/Meetings.d.ts +6 -0
- package/dist/cjs/types/components/Message.d.ts +4 -0
- package/dist/cjs/types/components/Messages.d.ts +9 -0
- package/dist/cjs/types/components/Messenger.d.ts +4 -0
- package/dist/cjs/types/components/NewConversation.d.ts +3 -0
- package/dist/cjs/types/components/Presence.d.ts +7 -0
- package/dist/cjs/types/components/Reactions.d.ts +13 -0
- package/dist/cjs/types/components/SearchUsers.d.ts +7 -0
- package/dist/cjs/types/components/SeenBy.d.ts +9 -0
- package/dist/cjs/types/components/Typing.d.ts +8 -0
- package/dist/cjs/types/contexts/MessengerContext.d.ts +8 -0
- package/dist/cjs/types/contexts/PreviewContext.d.ts +7 -0
- package/dist/cjs/types/contexts/UserContext.d.ts +8 -0
- package/dist/cjs/types/contexts/WeavyContext.d.ts +10 -0
- package/dist/cjs/types/hooks/useBadge.d.ts +1 -0
- package/dist/cjs/types/hooks/useChat.d.ts +1 -0
- package/dist/cjs/types/hooks/useConversation.d.ts +1 -0
- package/dist/cjs/types/hooks/useConversations.d.ts +1 -0
- package/dist/cjs/types/hooks/useDebounce.d.ts +2 -0
- package/dist/cjs/types/hooks/useEvents.d.ts +6 -0
- package/dist/cjs/types/hooks/useFileUploader.d.ts +1 -0
- package/dist/cjs/types/hooks/useMembers.d.ts +1 -0
- package/dist/cjs/types/hooks/useMessages.d.ts +1 -0
- package/dist/cjs/types/hooks/useMutateChat.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateConversation.d.ts +3 -0
- package/dist/cjs/types/hooks/useMutateConversationName.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateDeleteReaction.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateExternalBlobs.d.ts +3 -0
- package/dist/cjs/types/hooks/useMutateMeeting.d.ts +3 -0
- package/dist/cjs/types/hooks/useMutateMembers.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateMessage.d.ts +9 -0
- package/dist/cjs/types/hooks/useMutatePinned.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateReaction.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateRead.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateRemoveMembers.d.ts +4 -0
- package/dist/cjs/types/hooks/useMutateTyping.d.ts +3 -0
- package/dist/cjs/types/hooks/usePresence.d.ts +1 -0
- package/dist/cjs/types/hooks/usePreview.d.ts +4 -0
- package/dist/cjs/types/hooks/useReactions.d.ts +3 -0
- package/dist/cjs/types/hooks/useSearchUsers.d.ts +1 -0
- package/dist/cjs/types/hooks/useThrottle.d.ts +2 -0
- package/dist/cjs/types/hooks/useUser.d.ts +1 -0
- package/dist/cjs/types/index.d.ts +15 -0
- package/dist/cjs/types/types/Chat.d.ts +3 -0
- package/dist/cjs/types/types/Conversation.d.ts +4 -0
- package/dist/cjs/types/types/ConversationListItem.d.ts +4 -0
- package/dist/cjs/types/types/Message.d.ts +15 -0
- package/dist/cjs/types/types/Messenger.d.ts +3 -0
- package/dist/cjs/types/types/types.d.ts +150 -0
- package/dist/cjs/types/ui/Button.d.ts +4 -0
- package/dist/cjs/types/ui/Dropdown.d.ts +19 -0
- package/dist/cjs/types/ui/Icon.d.ts +10 -0
- package/dist/cjs/types/ui/Overlay.d.ts +12 -0
- package/dist/cjs/types/utils/fileUtilities.d.ts +5 -0
- package/dist/cjs/types/utils/styles.d.ts +17 -0
- package/dist/esm/index.js +39 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/client/WeavyClient.d.ts +16 -0
- package/dist/esm/types/components/Attachment.d.ts +13 -0
- package/dist/esm/types/components/Avatar.d.ts +11 -0
- package/dist/esm/types/components/Chat.d.ts +4 -0
- package/dist/esm/types/components/Conversation.d.ts +4 -0
- package/dist/esm/types/components/ConversationBadge.d.ts +3 -0
- package/dist/esm/types/components/ConversationForm.d.ts +7 -0
- package/dist/esm/types/components/ConversationList.d.ts +3 -0
- package/dist/esm/types/components/ConversationListItem.d.ts +4 -0
- package/dist/esm/types/components/File.d.ts +9 -0
- package/dist/esm/types/components/FileBrowser.d.ts +6 -0
- package/dist/esm/types/components/Image.d.ts +16 -0
- package/dist/esm/types/components/Meeting.d.ts +8 -0
- package/dist/esm/types/components/MeetingCard.d.ts +6 -0
- package/dist/esm/types/components/Meetings.d.ts +6 -0
- package/dist/esm/types/components/Message.d.ts +4 -0
- package/dist/esm/types/components/Messages.d.ts +9 -0
- package/dist/esm/types/components/Messenger.d.ts +4 -0
- package/dist/esm/types/components/NewConversation.d.ts +3 -0
- package/dist/esm/types/components/Presence.d.ts +7 -0
- package/dist/esm/types/components/Reactions.d.ts +13 -0
- package/dist/esm/types/components/SearchUsers.d.ts +7 -0
- package/dist/esm/types/components/SeenBy.d.ts +9 -0
- package/dist/esm/types/components/Typing.d.ts +8 -0
- package/dist/esm/types/contexts/MessengerContext.d.ts +8 -0
- package/dist/esm/types/contexts/PreviewContext.d.ts +7 -0
- package/dist/esm/types/contexts/UserContext.d.ts +8 -0
- package/dist/esm/types/contexts/WeavyContext.d.ts +10 -0
- package/dist/esm/types/hooks/useBadge.d.ts +1 -0
- package/dist/esm/types/hooks/useChat.d.ts +1 -0
- package/dist/esm/types/hooks/useConversation.d.ts +1 -0
- package/dist/esm/types/hooks/useConversations.d.ts +1 -0
- package/dist/esm/types/hooks/useDebounce.d.ts +2 -0
- package/dist/esm/types/hooks/useEvents.d.ts +6 -0
- package/dist/esm/types/hooks/useFileUploader.d.ts +1 -0
- package/dist/esm/types/hooks/useMembers.d.ts +1 -0
- package/dist/esm/types/hooks/useMessages.d.ts +1 -0
- package/dist/esm/types/hooks/useMutateChat.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateConversation.d.ts +3 -0
- package/dist/esm/types/hooks/useMutateConversationName.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateDeleteReaction.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateExternalBlobs.d.ts +3 -0
- package/dist/esm/types/hooks/useMutateMeeting.d.ts +3 -0
- package/dist/esm/types/hooks/useMutateMembers.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateMessage.d.ts +9 -0
- package/dist/esm/types/hooks/useMutatePinned.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateReaction.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateRead.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateRemoveMembers.d.ts +4 -0
- package/dist/esm/types/hooks/useMutateTyping.d.ts +3 -0
- package/dist/esm/types/hooks/usePresence.d.ts +1 -0
- package/dist/esm/types/hooks/usePreview.d.ts +4 -0
- package/dist/esm/types/hooks/useReactions.d.ts +3 -0
- package/dist/esm/types/hooks/useSearchUsers.d.ts +1 -0
- package/dist/esm/types/hooks/useThrottle.d.ts +2 -0
- package/dist/esm/types/hooks/useUser.d.ts +1 -0
- package/dist/esm/types/index.d.ts +15 -0
- package/dist/esm/types/types/Chat.d.ts +3 -0
- package/dist/esm/types/types/Conversation.d.ts +4 -0
- package/dist/esm/types/types/ConversationListItem.d.ts +4 -0
- package/dist/esm/types/types/Message.d.ts +15 -0
- package/dist/esm/types/types/Messenger.d.ts +3 -0
- package/dist/esm/types/types/types.d.ts +150 -0
- package/dist/esm/types/ui/Button.d.ts +4 -0
- package/dist/esm/types/ui/Dropdown.d.ts +19 -0
- package/dist/esm/types/ui/Icon.d.ts +10 -0
- package/dist/esm/types/ui/Overlay.d.ts +12 -0
- package/dist/esm/types/utils/fileUtilities.d.ts +5 -0
- package/dist/esm/types/utils/styles.d.ts +17 -0
- package/dist/index.d.ts +98 -0
- package/package.json +47 -0
- package/rollup.config.js +41 -0
- package/src/client/WeavyClient.ts +95 -0
- package/src/components/Attachment.tsx +33 -0
- package/src/components/Avatar.tsx +26 -0
- package/src/components/Chat.tsx +68 -0
- package/src/components/Conversation.tsx +220 -0
- package/src/components/ConversationBadge.tsx +44 -0
- package/src/components/ConversationForm.tsx +217 -0
- package/src/components/ConversationList.tsx +61 -0
- package/src/components/ConversationListItem.tsx +155 -0
- package/src/components/File.tsx +21 -0
- package/src/components/FileBrowser.tsx +86 -0
- package/src/components/Image.tsx +66 -0
- package/src/components/Meeting.tsx +21 -0
- package/src/components/MeetingCard.tsx +31 -0
- package/src/components/Meetings.tsx +58 -0
- package/src/components/Message.tsx +90 -0
- package/src/components/Messages.tsx +271 -0
- package/src/components/Messenger.tsx +34 -0
- package/src/components/NewConversation.tsx +50 -0
- package/src/components/Presence.tsx +15 -0
- package/src/components/Reactions.tsx +95 -0
- package/src/components/SearchUsers.tsx +90 -0
- package/src/components/SeenBy.tsx +26 -0
- package/src/components/Typing.tsx +131 -0
- package/src/contexts/MessengerContext.tsx +44 -0
- package/src/contexts/PreviewContext.tsx +105 -0
- package/src/contexts/UserContext.tsx +31 -0
- package/src/contexts/WeavyContext.tsx +66 -0
- package/src/hooks/useBadge.ts +32 -0
- package/src/hooks/useChat.ts +32 -0
- package/src/hooks/useConversation.ts +28 -0
- package/src/hooks/useConversations.ts +27 -0
- package/src/hooks/useDebounce.ts +22 -0
- package/src/hooks/useEvents.ts +43 -0
- package/src/hooks/useFileUploader.ts +35 -0
- package/src/hooks/useMembers.ts +27 -0
- package/src/hooks/useMessages.ts +42 -0
- package/src/hooks/useMessenger.ts +51 -0
- package/src/hooks/useMutateChat.ts +44 -0
- package/src/hooks/useMutateConversation.ts +40 -0
- package/src/hooks/useMutateConversationName.ts +41 -0
- package/src/hooks/useMutateDeleteReaction.ts +38 -0
- package/src/hooks/useMutateExternalBlobs.ts +39 -0
- package/src/hooks/useMutateMeeting.ts +39 -0
- package/src/hooks/useMutateMembers.ts +43 -0
- package/src/hooks/useMutateMessage.ts +116 -0
- package/src/hooks/useMutatePinned.ts +40 -0
- package/src/hooks/useMutateReaction.ts +38 -0
- package/src/hooks/useMutateRead.ts +40 -0
- package/src/hooks/useMutateRemoveMembers.ts +43 -0
- package/src/hooks/useMutateTyping.ts +34 -0
- package/src/hooks/usePresence.ts +32 -0
- package/src/hooks/usePreview.ts +21 -0
- package/src/hooks/useReactions.ts +53 -0
- package/src/hooks/useSearchUsers.ts +26 -0
- package/src/hooks/useThrottle.ts +13 -0
- package/src/hooks/useUser.ts +38 -0
- package/src/index.ts +33 -0
- package/src/types/Chat.ts +3 -0
- package/src/types/Conversation.ts +4 -0
- package/src/types/ConversationListItem.ts +4 -0
- package/src/types/Message.ts +16 -0
- package/src/types/Messenger.ts +3 -0
- package/src/types/emoji-toolkit.d.ts +1 -0
- package/src/types/types.ts +175 -0
- package/src/ui/Button.tsx +32 -0
- package/src/ui/Dropdown.tsx +58 -0
- package/src/ui/Icon.tsx +79 -0
- package/src/ui/Overlay.tsx +41 -0
- package/src/utils/fileUtilities.ts +230 -0
- package/src/utils/infiniteScroll.js +175 -0
- package/src/utils/scrollToBottom.js +75 -0
- package/src/utils/styles.ts +42 -0
- 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,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 @@
|
|
|
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;
|