@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,35 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// POST to upload a a file
|
|
6
|
+
export default function useFileUploader(callback: Function) {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
|
|
10
|
+
return useMutation(
|
|
11
|
+
async ({ request }: any) => {
|
|
12
|
+
|
|
13
|
+
const formData = new FormData();
|
|
14
|
+
formData.append('blob', request.file);
|
|
15
|
+
|
|
16
|
+
var response = await fetch(client.uri + "/api/blobs", {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
body: formData,
|
|
19
|
+
headers: {
|
|
20
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
var uploaded = await response.json();
|
|
25
|
+
callback(uploaded);
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
onError: (e: any) => {
|
|
29
|
+
|
|
30
|
+
},
|
|
31
|
+
onSuccess: (data: any, variables: any) => {
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useQuery } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// GET all members in an app
|
|
6
|
+
export default function useMembers(id: number | null, options: any) {
|
|
7
|
+
const { client } = useContext(WeavyContext);
|
|
8
|
+
|
|
9
|
+
if (!client) {
|
|
10
|
+
throw new Error('useMembers must be used within an WeavyProvider');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getConversationMembers = async () => {
|
|
14
|
+
|
|
15
|
+
const response = await fetch(client.uri + "/api/apps/" + id + "/members", {
|
|
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
|
+
|
|
26
|
+
return useQuery<MembersResult>(["members", id], getConversationMembers, options);
|
|
27
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useInfiniteQuery, useQuery } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// GET all messages in an app
|
|
6
|
+
export default function useMessages(id: number | null, options: any) {
|
|
7
|
+
const PAGE_SIZE = 25;
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
|
|
10
|
+
if (!client) {
|
|
11
|
+
throw new Error('useMessages must be used within an WeavyProvider');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const getMessages = async (opt: any) => {
|
|
15
|
+
let skip = opt.pageParam || 0;
|
|
16
|
+
|
|
17
|
+
const response = await fetch(client.uri + "/api/apps/" + id + "/messages?orderby=createdat+desc&skip=" + skip + "&top=" + PAGE_SIZE, {
|
|
18
|
+
headers: {
|
|
19
|
+
"content-type": "application/json",
|
|
20
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
let result = await response.json();
|
|
24
|
+
result.data = result.data?.reverse() || [];
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var opts = {
|
|
28
|
+
...options,
|
|
29
|
+
getNextPageParam: (lastPage:any, pages:any) => {
|
|
30
|
+
if (lastPage?.end < lastPage?.count) {
|
|
31
|
+
return pages.length * PAGE_SIZE;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
select: (data: any) => ({
|
|
35
|
+
// reverse scroll
|
|
36
|
+
pages: [...data.pages].reverse(),
|
|
37
|
+
pageParams: [...data.pageParams].reverse(),
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return useInfiniteQuery<MessagesResult>(['messages', id], getMessages, opts)
|
|
42
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// import { useContext, useEffect, useState } from "react";
|
|
2
|
+
// import { WeavyContext } from "../contexts/WeavyContext";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// export const useMessenger = (id: number) => {
|
|
6
|
+
// //const { client, state, dispatch } = useContext<WeavyContextProps>(WeavyContext);
|
|
7
|
+
// const [loading, setLoading] = useState<boolean>(true);
|
|
8
|
+
|
|
9
|
+
// // if (!client) {
|
|
10
|
+
// // throw new Error('useMessenger must be used within an WeavyProvider');
|
|
11
|
+
// // }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// useEffect(() => {
|
|
15
|
+
// let mocked = [
|
|
16
|
+
// { id: 11, title: "Chat 1", text: "Quisque cursus, metus vitae pharetra" },
|
|
17
|
+
// { id: 22, title: "Chat 2", text: "Quisque cursus, metus vitae pharetra" }
|
|
18
|
+
// ];
|
|
19
|
+
|
|
20
|
+
// setTimeout(() => {
|
|
21
|
+
// init(mocked);
|
|
22
|
+
// setLoading(false);
|
|
23
|
+
// }, 2000);
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// }, [])
|
|
27
|
+
|
|
28
|
+
// const init = (data: Conversation[]) => {
|
|
29
|
+
// //dispatch({ app: "messenger", type: "init", payload: data })
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
// const insert = ({ title, text }: InsertConversationProps) => {
|
|
33
|
+
|
|
34
|
+
// //dispatch({ app: "messenger", type: "insert", payload: { id: Math.random(), title, text } })
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
// const select = (id: number) => {
|
|
38
|
+
// //dispatch({ app: "messenger", type: "select", payload: id })
|
|
39
|
+
// }
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// return {
|
|
43
|
+
// //data: state.messenger.conversations,
|
|
44
|
+
// //selected: state.messenger.selected,
|
|
45
|
+
// loading,
|
|
46
|
+
// init,
|
|
47
|
+
// select,
|
|
48
|
+
// insert
|
|
49
|
+
// };
|
|
50
|
+
|
|
51
|
+
// }
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// POST to create a new conversation
|
|
6
|
+
export default function useMutateChat() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateChat must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
identifier: string,
|
|
18
|
+
members: number[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// create new conversation
|
|
22
|
+
const mutateChat = async ({ identifier, members }: MutateProps) => {
|
|
23
|
+
|
|
24
|
+
const response = await fetch(client.uri + "/api/apps/", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
identifier: identifier,
|
|
28
|
+
members: members
|
|
29
|
+
}),
|
|
30
|
+
headers: {
|
|
31
|
+
"content-type": "application/json",
|
|
32
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return response.json();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return useMutation(mutateChat, {
|
|
40
|
+
onSuccess: () => {
|
|
41
|
+
//queryClient.invalidateQueries("conversations");
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// POST to create a new conversation
|
|
6
|
+
export default function useMutateConversation() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateConversation must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
members: number[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// create new conversation
|
|
21
|
+
const mutateConversation = async ({ members }: MutateProps) => {
|
|
22
|
+
|
|
23
|
+
const response = await fetch(client.uri + "/api/conversations/", {
|
|
24
|
+
method: "POST",
|
|
25
|
+
body: JSON.stringify({ members: members }),
|
|
26
|
+
headers: {
|
|
27
|
+
"content-type": "application/json",
|
|
28
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return response.json();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return useMutation(mutateConversation, {
|
|
36
|
+
onSuccess: () => {
|
|
37
|
+
queryClient.invalidateQueries("conversations");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// PUT to update an app name
|
|
6
|
+
export default function useMutateConversationName() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateConversationName must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
name: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const mutateConversationName = async ({ id, name }: MutateProps) => {
|
|
22
|
+
|
|
23
|
+
const response = await fetch(client.uri + "/api/apps/" + id, {
|
|
24
|
+
method: "PATCH",
|
|
25
|
+
body: JSON.stringify({ name: name }),
|
|
26
|
+
headers: {
|
|
27
|
+
"content-type": "application/json",
|
|
28
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return response.json();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return useMutation(mutateConversationName, {
|
|
36
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
37
|
+
queryClient.invalidateQueries("conversations");
|
|
38
|
+
queryClient.invalidateQueries(["conversation", variables.id]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation } from "react-query";
|
|
3
|
+
import { UserContext } from "../contexts/UserContext";
|
|
4
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
5
|
+
|
|
6
|
+
/// DELETE to remove a reaction from a message
|
|
7
|
+
export default function useMutateDeleteReaction() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const { user } = useContext(UserContext);
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutateDeleteReaction must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type MutateProps = {
|
|
18
|
+
id: number | null,
|
|
19
|
+
reaction: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const mutateDeleteReaction = async ({ id, reaction }: MutateProps) => {
|
|
23
|
+
|
|
24
|
+
// remove the existing reaction
|
|
25
|
+
const response = await fetch(client.uri + "/api/messages/" + id + "/reactions/", {
|
|
26
|
+
method: "DELETE",
|
|
27
|
+
headers: {
|
|
28
|
+
"content-type": "application/json",
|
|
29
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return useMutation(mutateDeleteReaction);
|
|
38
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// POST to upload an external blob
|
|
6
|
+
export default function useMutateExternalBlobs() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateExternalBlobs must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
blobs: []
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const mutateExternalBlobs = async ({ blobs }: MutateProps) => {
|
|
21
|
+
|
|
22
|
+
const response = await fetch(client.uri + "/api/blobs/external", {
|
|
23
|
+
method: "POST",
|
|
24
|
+
body: JSON.stringify(blobs),
|
|
25
|
+
headers: {
|
|
26
|
+
"content-type": "application/json",
|
|
27
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return response.json();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return useMutation(mutateExternalBlobs, {
|
|
35
|
+
onSuccess: (variables: any) => {
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// POST to create a new meeting
|
|
6
|
+
export default function useMutateMeeting() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateMeeting must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
provider: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const mutateMeeting = async ({ provider }: MutateProps) => {
|
|
21
|
+
|
|
22
|
+
const response = await fetch(client.uri + "/api/meetings", {
|
|
23
|
+
method: "POST",
|
|
24
|
+
body: JSON.stringify({provider: provider}),
|
|
25
|
+
headers: {
|
|
26
|
+
"content-type": "application/json",
|
|
27
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return response.json();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return useMutation(mutateMeeting, {
|
|
35
|
+
onSuccess: (variables: any) => {
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// PUT to update members in an app
|
|
6
|
+
export default function useMutateMembers() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateMembers must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
members: number[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// add members to conversation
|
|
22
|
+
const mutateMembers = async ({ id, members }: MutateProps) => {
|
|
23
|
+
|
|
24
|
+
const response = await fetch(client.uri + "/api/apps/" + id + "/members/", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: JSON.stringify(members),
|
|
27
|
+
headers: {
|
|
28
|
+
"content-type": "application/json",
|
|
29
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return response;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return useMutation(mutateMembers, {
|
|
37
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
38
|
+
queryClient.invalidateQueries("conversations");
|
|
39
|
+
queryClient.invalidateQueries(["conversation", variables.id]);
|
|
40
|
+
queryClient.invalidateQueries(["members", variables.id]);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// PSOT to add a new message to an app
|
|
6
|
+
export default function useMutateMessage() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateMessage must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
text: string,
|
|
19
|
+
userId: number,
|
|
20
|
+
attachments: [],
|
|
21
|
+
meetings: MeetingType[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const mutateMessage = async ({ id, text, userId, attachments, meetings }: MutateProps) => {
|
|
25
|
+
const response = await fetch(client.uri + "/api/apps/" + id + "/messages", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
text: text,
|
|
29
|
+
blobs: attachments.map((a: FileType) => { return a.id }),
|
|
30
|
+
meeting_id: meetings.length > 0 ? meetings[0].id : null
|
|
31
|
+
}),
|
|
32
|
+
headers: {
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return response.json();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return useMutation(mutateMessage, {
|
|
42
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
43
|
+
|
|
44
|
+
const previousData = queryClient.getQueryData<any>(['messages', variables.id]);
|
|
45
|
+
if (previousData && previousData.pages) {
|
|
46
|
+
// update cache
|
|
47
|
+
const newPagesArray = previousData.pages.map((page: any, i: number) => {
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// remove temp message
|
|
52
|
+
if (i === 0) {
|
|
53
|
+
page.data = [
|
|
54
|
+
...page.data.filter((message: MessageType) => message.id !== context.tempId),
|
|
55
|
+
data
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return page;
|
|
61
|
+
|
|
62
|
+
}) ?? [];
|
|
63
|
+
|
|
64
|
+
queryClient.setQueryData(["messages", variables.id], (data: any) => ({
|
|
65
|
+
pages: newPagesArray,
|
|
66
|
+
pageParams: data.pageParams,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// refetch conversations list
|
|
71
|
+
queryClient.invalidateQueries("conversations");
|
|
72
|
+
|
|
73
|
+
},
|
|
74
|
+
onMutate: async (variables: any) => {
|
|
75
|
+
await queryClient.cancelQueries(['messages', variables.id]);
|
|
76
|
+
|
|
77
|
+
const previousData = queryClient.getQueryData<any>(['messages', variables.id]);
|
|
78
|
+
const tempId = Math.random();
|
|
79
|
+
|
|
80
|
+
if (previousData && previousData.pages.length > 0) {
|
|
81
|
+
|
|
82
|
+
var lastPage = previousData.pages[0]; // in reverse order
|
|
83
|
+
|
|
84
|
+
// add temp message
|
|
85
|
+
var data = lastPage.data || [];
|
|
86
|
+
let pageMessages = [...data, {
|
|
87
|
+
id: tempId,
|
|
88
|
+
text: variables.text,
|
|
89
|
+
display_name: "",
|
|
90
|
+
temp: true,
|
|
91
|
+
parent_id: null,
|
|
92
|
+
created_by: { id: variables.userId },
|
|
93
|
+
created_at: new Date().toUTCString(),
|
|
94
|
+
attachments: [],
|
|
95
|
+
reactions: [],
|
|
96
|
+
reactions_count: 0
|
|
97
|
+
}];
|
|
98
|
+
lastPage.data = pageMessages;
|
|
99
|
+
|
|
100
|
+
// update cache
|
|
101
|
+
queryClient.setQueryData(["messages", variables.id], (data: any) => {
|
|
102
|
+
let updatedPages = [lastPage];
|
|
103
|
+
if (data?.pages.length > 1) {
|
|
104
|
+
updatedPages = [lastPage, ...data?.pages.slice(1)];
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
pages: updatedPages,
|
|
108
|
+
pageParams: data?.pageParams,
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return { tempId }
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// PUT or DELETE to update pinned state on a conversation
|
|
6
|
+
export default function useMutatePinned() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutatePinned must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
pin: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const mutatePinned = async ({ id, pin }: MutateProps) => {
|
|
22
|
+
|
|
23
|
+
const response = await fetch(client.uri + "/api/conversations/" + id + "/pin", {
|
|
24
|
+
method: + !pin ? "DELETE": "PUT",
|
|
25
|
+
body: "",
|
|
26
|
+
headers: {
|
|
27
|
+
"content-type": "application/json",
|
|
28
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return response.json();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return useMutation(mutatePinned, {
|
|
36
|
+
onSuccess: () => {
|
|
37
|
+
queryClient.invalidateQueries("conversations");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation } from "react-query";
|
|
3
|
+
import { UserContext } from "../contexts/UserContext";
|
|
4
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
5
|
+
|
|
6
|
+
/// POST to add a reaction to a message
|
|
7
|
+
export default function useMutateReaction() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const { user } = useContext(UserContext);
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutateReaction must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type MutateProps = {
|
|
18
|
+
id: number | null,
|
|
19
|
+
reaction: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const mutateReaction = async ({id, reaction }: MutateProps) => {
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const response = await fetch(client.uri + "/api/messages/" + id + "/reactions/", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify({ content: reaction}),
|
|
28
|
+
headers: {
|
|
29
|
+
"content-type": "application/json",
|
|
30
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return useMutation(mutateReaction);
|
|
38
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// PUT or DELETE to update read state on a conversation
|
|
6
|
+
export default function useMutateRead() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateUnread must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
read: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const mutateRead = async ({ id, read }: MutateProps) => {
|
|
22
|
+
|
|
23
|
+
const response = await fetch(client.uri + "/api/conversations/" + id + "/read", {
|
|
24
|
+
method: !read ? "DELETE": "PUT",
|
|
25
|
+
body: "",
|
|
26
|
+
headers: {
|
|
27
|
+
"content-type": "application/json",
|
|
28
|
+
"Authorization": "Bearer " + await client.tokenFactory()
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return response.json();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return useMutation(mutateRead, {
|
|
36
|
+
onSuccess: () => {
|
|
37
|
+
queryClient.invalidateQueries("conversations");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|