@weavy/uikit-react 12.1.0 → 13.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/changelog.md +36 -0
- package/dist/cjs/index.js +28 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/client/WeavyClient.d.ts +8 -1
- package/dist/cjs/types/components/Attachment.d.ts +2 -1
- package/dist/cjs/types/components/Chat.d.ts +1 -1
- package/dist/cjs/types/components/PdfViewer.d.ts +3 -1
- package/dist/cjs/types/components/Preview.d.ts +8 -10
- package/dist/cjs/types/contexts/PreviewContext.d.ts +2 -1
- package/dist/cjs/types/contexts/WeavyContext.d.ts +2 -3
- package/dist/cjs/types/types/Chat.d.ts +1 -1
- package/dist/cjs/types/types/types.d.ts +16 -5
- package/dist/cjs/types/ui/Spinner.d.ts +9 -0
- package/dist/cjs/types/utils/fileUtilities.d.ts +1 -4
- package/dist/css/weavy-chat.css +270 -94
- package/dist/css/weavy-messenger.css +274 -96
- package/dist/css/weavy.css +274 -96
- package/dist/esm/index.js +28 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/client/WeavyClient.d.ts +8 -1
- package/dist/esm/types/components/Attachment.d.ts +2 -1
- package/dist/esm/types/components/Chat.d.ts +1 -1
- package/dist/esm/types/components/PdfViewer.d.ts +3 -1
- package/dist/esm/types/components/Preview.d.ts +8 -10
- package/dist/esm/types/contexts/PreviewContext.d.ts +2 -1
- package/dist/esm/types/contexts/WeavyContext.d.ts +2 -3
- package/dist/esm/types/types/Chat.d.ts +1 -1
- package/dist/esm/types/types/types.d.ts +16 -5
- package/dist/esm/types/ui/Spinner.d.ts +9 -0
- package/dist/esm/types/utils/fileUtilities.d.ts +1 -4
- package/dist/index.d.ts +14 -7
- package/package.json +2 -2
- package/rollup.config.js +3 -1
- package/src/client/WeavyClient.ts +105 -24
- package/src/components/Attachment.tsx +8 -7
- package/src/components/Chat.tsx +3 -3
- package/src/components/Conversation.tsx +3 -3
- package/src/components/Message.tsx +1 -1
- package/src/components/Messages.tsx +1 -1
- package/src/components/PdfViewer.tsx +88 -83
- package/src/components/Preview.tsx +115 -54
- package/src/components/SearchUsers.tsx +2 -2
- package/src/contexts/PreviewContext.tsx +90 -16
- package/src/contexts/WeavyContext.tsx +7 -4
- package/src/hooks/useBadge.ts +2 -6
- package/src/hooks/useChat.ts +3 -14
- package/src/hooks/useConversation.ts +1 -7
- package/src/hooks/useConversations.ts +1 -7
- package/src/hooks/useFileUploader.ts +6 -8
- package/src/hooks/useMembers.ts +1 -7
- package/src/hooks/useMessages.ts +1 -7
- package/src/hooks/useMutateChat.ts +6 -11
- package/src/hooks/useMutateConversation.ts +7 -10
- package/src/hooks/useMutateConversationName.ts +10 -12
- package/src/hooks/useMutateDeleteReaction.ts +3 -8
- package/src/hooks/useMutateExternalBlobs.ts +6 -11
- package/src/hooks/useMutateMeeting.ts +6 -11
- package/src/hooks/useMutateMembers.ts +8 -13
- package/src/hooks/useMutateMessage.ts +10 -15
- package/src/hooks/useMutatePinned.ts +3 -8
- package/src/hooks/useMutateReaction.ts +6 -12
- package/src/hooks/useMutateRead.ts +1 -10
- package/src/hooks/useMutateRemoveMembers.ts +7 -12
- package/src/hooks/useMutateTyping.ts +6 -11
- package/src/hooks/useSearchUsers.ts +1 -6
- package/src/hooks/useUser.ts +3 -14
- package/src/scss/theme/_appbar.scss +4 -2
- package/src/scss/theme/_cm-editor.scss +1 -1
- package/src/scss/theme/_code-vscode-dark.scss +184 -0
- package/src/scss/theme/_code-vscode-light.scss +179 -0
- package/src/scss/theme/_code.scss +9 -112
- package/src/scss/theme/_files.scss +1 -1
- package/src/scss/theme/_message-editor.scss +1 -1
- package/src/scss/theme/_overlays.scss +2 -2
- package/src/scss/theme/_panels.scss +11 -7
- package/src/scss/theme/_preview-code.scss +5 -0
- package/src/scss/theme/_preview-embed.scss +3 -3
- package/src/scss/theme/_preview-image.scss +1 -1
- package/src/scss/theme/_preview-text.scss +1 -1
- package/src/scss/theme/_preview.scss +7 -2
- package/src/scss/weavy-chat.scss +1 -0
- package/src/scss/weavy-messenger.scss +1 -0
- package/src/types/Chat.ts +1 -1
- package/src/types/types.ts +16 -5
- package/src/ui/Spinner.tsx +18 -0
- package/src/utils/fileUtilities.ts +11 -125
|
@@ -2,17 +2,25 @@ import React, { createContext, useEffect, useState } from "react";
|
|
|
2
2
|
import Overlay from '../ui/Overlay';
|
|
3
3
|
import Button from '../ui/Button';
|
|
4
4
|
import Icon from '../ui/Icon';
|
|
5
|
+
import Preview from '../components/Preview';
|
|
6
|
+
import { getIcon, getExtension } from "../utils/fileUtilities";
|
|
5
7
|
|
|
6
8
|
export const PreviewContext = createContext<PreviewContextProps>({
|
|
7
9
|
openPreview: Function,
|
|
8
10
|
closePreview: Function
|
|
9
11
|
});
|
|
10
12
|
|
|
13
|
+
function allowedKeyTarget(e: any) {
|
|
14
|
+
var notInputField = !e.target.matches("input, textarea, select") && !e.target.closest('[contenteditable="true"]');
|
|
15
|
+
return notInputField;
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
type Props = {
|
|
19
|
+
client: any,
|
|
12
20
|
children: React.ReactNode
|
|
13
21
|
}
|
|
14
22
|
|
|
15
|
-
const PreviewProvider = ({ children }: Props) => {
|
|
23
|
+
const PreviewProvider = ({ client, children }: Props) => {
|
|
16
24
|
const [modalPreviewOpen, setModalPreviewOpen] = useState<boolean>(false);
|
|
17
25
|
const [attachments, setAttachments] = useState<AttachmentType[]>([]);
|
|
18
26
|
const [activeAttachment, setActiveAttchment] = useState<AttachmentType>();
|
|
@@ -53,51 +61,117 @@ const PreviewProvider = ({ children }: Props) => {
|
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
const handleDownload = () => {
|
|
56
|
-
window.open(`${activeAttachment?.download_url}&d=1`, "
|
|
64
|
+
window.open(`${activeAttachment?.download_url}&d=1`, "_top");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleExternal = () => {
|
|
68
|
+
window.open(`${activeAttachment?.external_url}`, "_blank");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const handleApplication = () => {
|
|
72
|
+
// TODO: Change to webdav-url
|
|
73
|
+
window.open(`${activeAttachment?.application_url}`, "_top");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Keyboard handlers
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (activeAttachment) {
|
|
79
|
+
const handleKey = (e: any) => {
|
|
80
|
+
if (e.which === 27) { // ESC
|
|
81
|
+
e.stopImmediatePropagation();
|
|
82
|
+
closePreview()
|
|
83
|
+
} else if (e.which === 37) { // LEFT
|
|
84
|
+
if (allowedKeyTarget(e)) {
|
|
85
|
+
setCurrentAttachmentId(previousAttachmentId);
|
|
86
|
+
}
|
|
87
|
+
} else if (e.which === 39) { // RIGHT
|
|
88
|
+
if (allowedKeyTarget(e)) {
|
|
89
|
+
setCurrentAttachmentId(nextAttachmentId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
document.addEventListener("keyup", handleKey);
|
|
95
|
+
|
|
96
|
+
return () => {
|
|
97
|
+
// cleanup
|
|
98
|
+
document.removeEventListener("keyup", handleKey);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}, [activeAttachment])
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
let activeExt: string = getExtension(activeAttachment?.name || '');
|
|
106
|
+
let activeIcon: string = getIcon(activeAttachment?.name || '').icon;
|
|
107
|
+
|
|
108
|
+
let activeSrc = activeAttachment?.preview_url || activeAttachment?.download_url || '';
|
|
109
|
+
|
|
110
|
+
// Let GIF and SVG display raw content
|
|
111
|
+
let animatedImage = activeAttachment?.preview_format === "image" && (activeExt === ".gif" || activeExt === ".svg");
|
|
112
|
+
if (animatedImage) {
|
|
113
|
+
activeSrc = activeAttachment?.download_url || '';
|
|
57
114
|
}
|
|
58
115
|
|
|
59
116
|
return (
|
|
60
117
|
<>
|
|
61
|
-
|
|
62
118
|
<PreviewContext.Provider value={{ openPreview: openPreview, closePreview: closePreview }}>
|
|
63
119
|
{children}
|
|
64
120
|
</PreviewContext.Provider>
|
|
65
121
|
|
|
66
|
-
<Overlay.UI isOpen={modalPreviewOpen} className=
|
|
67
|
-
<header className=
|
|
68
|
-
<nav className=
|
|
122
|
+
<Overlay.UI isOpen={modalPreviewOpen} className="wy-dark">
|
|
123
|
+
<header className="wy-appbars">
|
|
124
|
+
<nav className="wy-appbar">
|
|
69
125
|
<Button.UI onClick={closePreview}><Icon.UI name='close' /></Button.UI>
|
|
70
|
-
<div className=
|
|
126
|
+
<div className="wy-appbar-text">
|
|
71
127
|
{activeAttachment &&
|
|
72
128
|
<span>{activeAttachment.name}</span>
|
|
73
129
|
}
|
|
74
130
|
|
|
75
131
|
</div>
|
|
76
|
-
<
|
|
132
|
+
<div className="wy-appbar-buttons">
|
|
133
|
+
{activeAttachment?.application_url ?
|
|
134
|
+
<Button.UI onClick={handleApplication} title={`Open in app`}><Icon.UI name={activeIcon} /></Button.UI>
|
|
135
|
+
:
|
|
136
|
+
activeAttachment?.external_url ?
|
|
137
|
+
<Button.UI onClick={handleExternal} title={`Open in ${activeAttachment.provider}`}><Icon.UI name={activeIcon} /></Button.UI>
|
|
138
|
+
:
|
|
139
|
+
<Button.UI onClick={handleDownload}><Icon.UI name='download' /></Button.UI>
|
|
140
|
+
}
|
|
141
|
+
</div>
|
|
142
|
+
|
|
77
143
|
</nav>
|
|
78
144
|
</header>
|
|
79
|
-
<div
|
|
80
|
-
|
|
145
|
+
<div className="wy-preview wy-scroll-y wy-scroll-x">
|
|
81
146
|
{activeAttachment &&
|
|
82
147
|
<>
|
|
83
148
|
{previousAttachmentId &&
|
|
84
|
-
<Button.UI onClick={handlePrevious}
|
|
149
|
+
<nav className="wy-nav-prev"><Button.UI onClick={handlePrevious}><Icon.UI name="previous" /></Button.UI></nav>
|
|
85
150
|
}
|
|
86
151
|
{nextAttachmentId &&
|
|
87
|
-
<Button.UI onClick={handleNext}
|
|
152
|
+
<nav className="wy-nav-next"><Button.UI onClick={handleNext}><Icon.UI name="next" /></Button.UI></nav>
|
|
88
153
|
}
|
|
89
|
-
|
|
90
|
-
|
|
154
|
+
<Preview
|
|
155
|
+
client={client}
|
|
156
|
+
src={activeSrc}
|
|
157
|
+
link={activeAttachment.external_url}
|
|
158
|
+
format={activeAttachment.preview_format}
|
|
159
|
+
name={activeAttachment.name}
|
|
160
|
+
icon={activeIcon}
|
|
161
|
+
width={activeAttachment.width}
|
|
162
|
+
height={activeAttachment.height}
|
|
163
|
+
mediaType={activeAttachment.media_type}
|
|
164
|
+
provider={activeAttachment.provider}
|
|
165
|
+
/>
|
|
91
166
|
</>
|
|
92
167
|
}
|
|
93
|
-
|
|
94
168
|
</div>
|
|
95
169
|
</Overlay.UI>
|
|
96
170
|
|
|
97
171
|
</>
|
|
98
172
|
|
|
99
|
-
|
|
100
173
|
)
|
|
101
174
|
};
|
|
102
175
|
|
|
103
176
|
export default PreviewProvider;
|
|
177
|
+
|
|
@@ -7,7 +7,6 @@ import utc from 'dayjs/plugin/utc';
|
|
|
7
7
|
import timezone from 'dayjs/plugin/timezone';
|
|
8
8
|
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
9
9
|
import PreviewProvider from "./PreviewContext";
|
|
10
|
-
import WeavyClient from "../client/WeavyClient";
|
|
11
10
|
import detectScrollbars from '../utils/scrollbarDetection';
|
|
12
11
|
|
|
13
12
|
dayjs.extend(relativeTime);
|
|
@@ -21,7 +20,7 @@ export const WeavyContext = createContext<WeavyContextProps>({
|
|
|
21
20
|
options: {}
|
|
22
21
|
});
|
|
23
22
|
|
|
24
|
-
type
|
|
23
|
+
type WeavyProviderProperties = {
|
|
25
24
|
children: React.ReactNode,
|
|
26
25
|
client: WeavyClient,
|
|
27
26
|
options?: WeavyContextOptions
|
|
@@ -35,7 +34,7 @@ const queryClient = new QueryClient({
|
|
|
35
34
|
},
|
|
36
35
|
})
|
|
37
36
|
|
|
38
|
-
const WeavyProvider = ({ children, client, options }:
|
|
37
|
+
const WeavyProvider = ({ children, client, options }: WeavyProviderProperties) => {
|
|
39
38
|
|
|
40
39
|
let defaultOptions: WeavyContextOptions = {
|
|
41
40
|
zoomAuthenticationUrl: undefined,
|
|
@@ -52,13 +51,17 @@ const WeavyProvider = ({ children, client, options }: Props) => {
|
|
|
52
51
|
detectScrollbars();
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
if(!client){
|
|
55
|
+
queryClient.clear();
|
|
56
|
+
}
|
|
57
|
+
|
|
55
58
|
return (
|
|
56
59
|
<>
|
|
57
60
|
{client &&
|
|
58
61
|
<QueryClientProvider client={queryClient}>
|
|
59
62
|
<WeavyContext.Provider value={{ client, options: opts }}>
|
|
60
63
|
<UserProvider client={client}>
|
|
61
|
-
<PreviewProvider>
|
|
64
|
+
<PreviewProvider client={client}>
|
|
62
65
|
{children}
|
|
63
66
|
</PreviewProvider>
|
|
64
67
|
</UserProvider>
|
package/src/hooks/useBadge.ts
CHANGED
|
@@ -12,12 +12,8 @@ export default function useBadge() {
|
|
|
12
12
|
|
|
13
13
|
const getBadge = async () => {
|
|
14
14
|
|
|
15
|
-
const response = await
|
|
16
|
-
|
|
17
|
-
"content-type": "application/json",
|
|
18
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
15
|
+
const response = await client.get("/api/conversations/badge")
|
|
16
|
+
|
|
21
17
|
if(response.ok){
|
|
22
18
|
const data = await response.json();
|
|
23
19
|
return data;
|
package/src/hooks/useChat.ts
CHANGED
|
@@ -11,20 +11,9 @@ export default function useChat(id: string, options: any) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const getConversation = async () => {
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
"content-type": "application/json",
|
|
18
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
if(response.ok){
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return null;
|
|
27
|
-
|
|
14
|
+
const response = await client.get("/api/apps/" + id);
|
|
15
|
+
const data = await response.json();
|
|
16
|
+
return data;
|
|
28
17
|
};
|
|
29
18
|
|
|
30
19
|
|
|
@@ -11,13 +11,7 @@ export default function useConversation(id: number | null, options: any) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const getConversation = async () => {
|
|
14
|
-
|
|
15
|
-
const response = await fetch(client.url + "/api/conversations/" + id, {
|
|
16
|
-
headers: {
|
|
17
|
-
"content-type": "application/json",
|
|
18
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
14
|
+
const response = await client.get("/api/conversations/" + id);
|
|
21
15
|
const data = await response.json();
|
|
22
16
|
return data;
|
|
23
17
|
};
|
|
@@ -11,13 +11,7 @@ export default function useConversations() {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const getConversations = async () => {
|
|
14
|
-
|
|
15
|
-
const response = await fetch(client.url + "/api/conversations?contextual=false", {
|
|
16
|
-
headers: {
|
|
17
|
-
"content-type": "application/json",
|
|
18
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
14
|
+
const response = await client.get("/api/conversations?contextual=false");
|
|
21
15
|
const data = await response.json();
|
|
22
16
|
return data;
|
|
23
17
|
};
|
|
@@ -17,13 +17,11 @@ export default function useFileUploader(callback: Function) {
|
|
|
17
17
|
const formData = new FormData();
|
|
18
18
|
formData.append('blob', request.file);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
});
|
|
20
|
+
|
|
21
|
+
const response = await client.post("/api/blobs",
|
|
22
|
+
"POST",
|
|
23
|
+
formData,
|
|
24
|
+
"");
|
|
27
25
|
|
|
28
26
|
var uploaded = await response.json();
|
|
29
27
|
callback(uploaded);
|
|
@@ -32,7 +30,7 @@ export default function useFileUploader(callback: Function) {
|
|
|
32
30
|
onError: (e: any) => {
|
|
33
31
|
|
|
34
32
|
},
|
|
35
|
-
onSuccess: (data: any, variables: any) => {
|
|
33
|
+
onSuccess: (data: any, variables: any) => {
|
|
36
34
|
},
|
|
37
35
|
}
|
|
38
36
|
);
|
package/src/hooks/useMembers.ts
CHANGED
|
@@ -11,13 +11,7 @@ export default function useMembers(id: number | null, options: any) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const getConversationMembers = async () => {
|
|
14
|
-
|
|
15
|
-
const response = await fetch(client.url + "/api/apps/" + id + "/members", {
|
|
16
|
-
headers: {
|
|
17
|
-
"content-type": "application/json",
|
|
18
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
14
|
+
const response = await client.get("/api/apps/" + id + "/members");
|
|
21
15
|
const data = await response.json();
|
|
22
16
|
return data;
|
|
23
17
|
};
|
package/src/hooks/useMessages.ts
CHANGED
|
@@ -13,13 +13,7 @@ export default function useMessages(id: number | null, options: any) {
|
|
|
13
13
|
|
|
14
14
|
const getMessages = async (opt: any) => {
|
|
15
15
|
let skip = opt.pageParam || 0;
|
|
16
|
-
|
|
17
|
-
const response = await fetch(client.url + "/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
|
-
});
|
|
16
|
+
const response = await client.get("/api/apps/" + id + "/messages?orderby=createdat+desc&skip=" + skip + "&top=" + PAGE_SIZE);
|
|
23
17
|
let result = await response.json();
|
|
24
18
|
result.data = result.data?.reverse() || [];
|
|
25
19
|
return result;
|
|
@@ -21,17 +21,12 @@ export default function useMutateChat() {
|
|
|
21
21
|
// create new conversation
|
|
22
22
|
const mutateChat = async ({ identifier, members }: MutateProps) => {
|
|
23
23
|
|
|
24
|
-
const response = await
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const response = await client.post("/api/apps/",
|
|
25
|
+
"POST",
|
|
26
|
+
JSON.stringify({
|
|
27
27
|
identifier: identifier,
|
|
28
|
-
members: members
|
|
29
|
-
})
|
|
30
|
-
headers: {
|
|
31
|
-
"content-type": "application/json",
|
|
32
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
33
|
-
}
|
|
34
|
-
});
|
|
28
|
+
members: members
|
|
29
|
+
}));
|
|
35
30
|
|
|
36
31
|
return response.json();
|
|
37
32
|
};
|
|
@@ -39,6 +34,6 @@ export default function useMutateChat() {
|
|
|
39
34
|
return useMutation(mutateChat, {
|
|
40
35
|
onSuccess: () => {
|
|
41
36
|
//queryClient.invalidateQueries("conversations");
|
|
42
|
-
}
|
|
37
|
+
}
|
|
43
38
|
});
|
|
44
39
|
}
|
|
@@ -20,21 +20,18 @@ export default function useMutateConversation() {
|
|
|
20
20
|
// create new conversation
|
|
21
21
|
const mutateConversation = async ({ members }: MutateProps) => {
|
|
22
22
|
|
|
23
|
-
const response = await
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
29
|
-
}
|
|
30
|
-
});
|
|
23
|
+
const response = await client.post("/api/conversations/",
|
|
24
|
+
"POST",
|
|
25
|
+
JSON.stringify({
|
|
26
|
+
members: members
|
|
27
|
+
}));
|
|
31
28
|
|
|
32
29
|
return response.json();
|
|
33
30
|
};
|
|
34
31
|
|
|
35
32
|
return useMutation(mutateConversation, {
|
|
36
33
|
onSuccess: () => {
|
|
37
|
-
queryClient.invalidateQueries("conversations");
|
|
38
|
-
}
|
|
34
|
+
queryClient.invalidateQueries("conversations");
|
|
35
|
+
}
|
|
39
36
|
});
|
|
40
37
|
}
|
|
@@ -14,28 +14,26 @@ export default function useMutateConversationName() {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
type MutateProps = {
|
|
17
|
-
id: number | null,
|
|
17
|
+
id: number | null,
|
|
18
18
|
name: string
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const mutateConversationName = async ({ id, name }: MutateProps) => {
|
|
22
22
|
|
|
23
|
-
const response = await
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
23
|
+
const response = await client.post("/api/apps/" + id,
|
|
24
|
+
"PATCH",
|
|
25
|
+
JSON.stringify({
|
|
26
|
+
type: 'ChatRoom',
|
|
27
|
+
name: name
|
|
28
|
+
}));
|
|
31
29
|
|
|
32
30
|
return response.json();
|
|
33
31
|
};
|
|
34
32
|
|
|
35
33
|
return useMutation(mutateConversationName, {
|
|
36
34
|
onSuccess: (data: any, variables: any, context: any) => {
|
|
37
|
-
queryClient.invalidateQueries("conversations");
|
|
38
|
-
queryClient.invalidateQueries(["conversation", variables.id]);
|
|
39
|
-
}
|
|
35
|
+
queryClient.invalidateQueries("conversations");
|
|
36
|
+
queryClient.invalidateQueries(["conversation", variables.id]);
|
|
37
|
+
}
|
|
40
38
|
});
|
|
41
39
|
}
|
|
@@ -22,14 +22,9 @@ export default function useMutateDeleteReaction() {
|
|
|
22
22
|
const mutateDeleteReaction = async ({ id, reaction }: MutateProps) => {
|
|
23
23
|
|
|
24
24
|
// remove the existing reaction
|
|
25
|
-
const response = await
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"content-type": "application/json",
|
|
29
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
25
|
+
const response = await client.post("/api/messages/" + id + "/reactions/",
|
|
26
|
+
"DELETE",
|
|
27
|
+
"");
|
|
33
28
|
|
|
34
29
|
return response;
|
|
35
30
|
};
|
|
@@ -14,26 +14,21 @@ export default function useMutateExternalBlobs() {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
type MutateProps = {
|
|
17
|
-
blobs: []
|
|
17
|
+
blobs: []
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const mutateExternalBlobs = async ({ blobs }: MutateProps) => {
|
|
21
21
|
|
|
22
|
-
const response = await
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
headers: {
|
|
26
|
-
"content-type": "application/json",
|
|
27
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
28
|
-
}
|
|
29
|
-
});
|
|
22
|
+
const response = await client.post("/api/blobs/external",
|
|
23
|
+
"POST",
|
|
24
|
+
JSON.stringify(blobs));
|
|
30
25
|
|
|
31
26
|
return response.json();
|
|
32
27
|
};
|
|
33
28
|
|
|
34
29
|
return useMutation(mutateExternalBlobs, {
|
|
35
30
|
onSuccess: (variables: any) => {
|
|
36
|
-
|
|
37
|
-
}
|
|
31
|
+
|
|
32
|
+
}
|
|
38
33
|
});
|
|
39
34
|
}
|
|
@@ -14,26 +14,21 @@ export default function useMutateMeeting() {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
type MutateProps = {
|
|
17
|
-
provider: string
|
|
17
|
+
provider: string
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const mutateMeeting = async ({ provider }: MutateProps) => {
|
|
21
21
|
|
|
22
|
-
const response = await
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
headers: {
|
|
26
|
-
"content-type": "application/json",
|
|
27
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
28
|
-
}
|
|
29
|
-
});
|
|
22
|
+
const response = await client.post("/api/meetings",
|
|
23
|
+
"POST",
|
|
24
|
+
JSON.stringify({ provider: provider }));
|
|
30
25
|
|
|
31
26
|
return response.json();
|
|
32
27
|
};
|
|
33
28
|
|
|
34
29
|
return useMutation(mutateMeeting, {
|
|
35
30
|
onSuccess: (variables: any) => {
|
|
36
|
-
|
|
37
|
-
}
|
|
31
|
+
|
|
32
|
+
}
|
|
38
33
|
});
|
|
39
34
|
}
|
|
@@ -14,30 +14,25 @@ export default function useMutateMembers() {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
type MutateProps = {
|
|
17
|
-
id: number | null,
|
|
17
|
+
id: number | null,
|
|
18
18
|
members: number[]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// add members to conversation
|
|
22
22
|
const mutateMembers = async ({ id, members }: MutateProps) => {
|
|
23
23
|
|
|
24
|
-
const response = await
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
headers: {
|
|
28
|
-
"content-type": "application/json",
|
|
29
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
30
|
-
}
|
|
31
|
-
});
|
|
24
|
+
const response = await client.post("/api/apps/" + id + "/members/",
|
|
25
|
+
"POST",
|
|
26
|
+
JSON.stringify(members));
|
|
32
27
|
|
|
33
28
|
return response;
|
|
34
29
|
};
|
|
35
30
|
|
|
36
31
|
return useMutation(mutateMembers, {
|
|
37
32
|
onSuccess: (data: any, variables: any, context: any) => {
|
|
38
|
-
queryClient.invalidateQueries("conversations");
|
|
39
|
-
queryClient.invalidateQueries(["conversation", variables.id]);
|
|
40
|
-
queryClient.invalidateQueries(["members", variables.id]);
|
|
41
|
-
}
|
|
33
|
+
queryClient.invalidateQueries("conversations");
|
|
34
|
+
queryClient.invalidateQueries(["conversation", variables.id]);
|
|
35
|
+
queryClient.invalidateQueries(["members", variables.id]);
|
|
36
|
+
}
|
|
42
37
|
});
|
|
43
38
|
}
|
|
@@ -22,19 +22,14 @@ export default function useMutateMessage() {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const mutateMessage = async ({ id, text, userId, attachments, meetings }: MutateProps) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
const response = await client.post("/api/apps/" + id + "/messages",
|
|
27
|
+
"POST",
|
|
28
|
+
JSON.stringify({
|
|
28
29
|
text: text,
|
|
29
30
|
blobs: attachments.map((a: FileType) => { return a.id }),
|
|
30
31
|
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
|
-
|
|
32
|
+
}));
|
|
38
33
|
return response.json();
|
|
39
34
|
};
|
|
40
35
|
|
|
@@ -46,7 +41,7 @@ export default function useMutateMessage() {
|
|
|
46
41
|
// update cache
|
|
47
42
|
const newPagesArray = previousData.pages.map((page: any, i: number) => {
|
|
48
43
|
|
|
49
|
-
|
|
44
|
+
|
|
50
45
|
|
|
51
46
|
// remove temp message
|
|
52
47
|
if (i === 0) {
|
|
@@ -54,7 +49,7 @@ export default function useMutateMessage() {
|
|
|
54
49
|
...page.data.filter((message: MessageType) => message.id !== context.tempId),
|
|
55
50
|
data
|
|
56
51
|
]
|
|
57
|
-
|
|
52
|
+
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
return page;
|
|
@@ -68,7 +63,7 @@ export default function useMutateMessage() {
|
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
// refetch conversations list
|
|
71
|
-
queryClient.invalidateQueries("conversations");
|
|
66
|
+
queryClient.invalidateQueries("conversations");
|
|
72
67
|
|
|
73
68
|
},
|
|
74
69
|
onMutate: async (variables: any) => {
|
|
@@ -100,8 +95,8 @@ export default function useMutateMessage() {
|
|
|
100
95
|
|
|
101
96
|
// update cache
|
|
102
97
|
queryClient.setQueryData(["messages", variables.id], (data: any) => {
|
|
103
|
-
let updatedPages = [lastPage];
|
|
104
|
-
if (data?.pages.length > 1) {
|
|
98
|
+
let updatedPages = [lastPage];
|
|
99
|
+
if (data?.pages.length > 1) {
|
|
105
100
|
updatedPages = [lastPage, ...data?.pages.slice(1)];
|
|
106
101
|
}
|
|
107
102
|
return {
|
|
@@ -20,14 +20,9 @@ export default function useMutatePinned() {
|
|
|
20
20
|
|
|
21
21
|
const mutatePinned = async ({ id, pin }: MutateProps) => {
|
|
22
22
|
|
|
23
|
-
const response = await
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
headers: {
|
|
27
|
-
"content-type": "application/json",
|
|
28
|
-
"Authorization": "Bearer " + await client.tokenFactory()
|
|
29
|
-
}
|
|
30
|
-
});
|
|
23
|
+
const response = await client.post("/api/conversations/" + id + "/pin",
|
|
24
|
+
!pin ? "DELETE" : "PUT",
|
|
25
|
+
"");
|
|
31
26
|
|
|
32
27
|
return response.json();
|
|
33
28
|
};
|