@weavy/uikit-react 14.0.3 → 15.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/.vscode/settings.json +2 -0
- package/changelog.md +10 -0
- package/dist/cjs/client/WeavyClient.d.ts +1 -0
- package/dist/cjs/components/Attachment.d.ts +5 -5
- package/dist/cjs/components/Blob.d.ts +9 -0
- package/dist/cjs/components/Comment.d.ts +18 -0
- package/dist/cjs/components/CommentCount.d.ts +7 -0
- package/dist/cjs/components/CommentEdit.d.ts +16 -0
- package/dist/cjs/components/CommentPlaceholder.d.ts +8 -0
- package/dist/cjs/components/CommentTrashed.d.ts +15 -0
- package/dist/cjs/components/CommentView.d.ts +18 -0
- package/dist/cjs/components/Comments.d.ts +8 -0
- package/dist/cjs/components/ConversationListItem.d.ts +1 -1
- package/dist/cjs/components/Dropzone.d.ts +10 -0
- package/dist/cjs/components/Editor.d.ts +25 -0
- package/dist/cjs/components/Embed.d.ts +8 -0
- package/dist/cjs/components/FileItem.d.ts +41 -0
- package/dist/cjs/components/FileList.d.ts +11 -0
- package/dist/cjs/components/FileVersions.d.ts +9 -0
- package/dist/cjs/components/Files.d.ts +4 -0
- package/dist/cjs/components/Image.d.ts +3 -3
- package/dist/cjs/components/MeetingCard.d.ts +1 -1
- package/dist/cjs/components/Meetings.d.ts +2 -1
- package/dist/cjs/components/Poll.d.ts +8 -0
- package/dist/cjs/components/PollOption.d.ts +10 -0
- package/dist/cjs/components/Post.d.ts +21 -0
- package/dist/cjs/components/PostEdit.d.ts +17 -0
- package/dist/cjs/components/PostList.d.ts +6 -0
- package/dist/cjs/components/PostPlaceholder.d.ts +8 -0
- package/dist/cjs/components/PostTrashed.d.ts +14 -0
- package/dist/cjs/components/PostView.d.ts +21 -0
- package/dist/cjs/components/Posts.d.ts +4 -0
- package/dist/cjs/components/Preview.d.ts +1 -3
- package/dist/cjs/components/PreviewFiles.d.ts +10 -0
- package/dist/cjs/components/Reactions.d.ts +6 -2
- package/dist/cjs/components/SearchUsers.d.ts +2 -1
- package/dist/cjs/contexts/CloudFilesContext.d.ts +9 -0
- package/dist/cjs/hooks/useApps.d.ts +1 -0
- package/dist/cjs/hooks/useCloudFiles.d.ts +3 -0
- package/dist/cjs/hooks/useCommentList.d.ts +1 -0
- package/dist/cjs/hooks/useEmbeds.d.ts +5 -0
- package/dist/cjs/hooks/useFileList.d.ts +1 -0
- package/dist/cjs/hooks/useFileUploader.d.ts +8 -0
- package/dist/cjs/hooks/useFileVersions.d.ts +2 -0
- package/dist/cjs/hooks/useInfiniteScroll.d.ts +4 -0
- package/dist/cjs/hooks/useIsFirstRender.d.ts +2 -0
- package/dist/cjs/hooks/useMutateApps.d.ts +5 -0
- package/dist/cjs/hooks/useMutateComment.d.ts +10 -0
- package/dist/cjs/hooks/useMutateConversationName.d.ts +1 -1
- package/dist/cjs/hooks/useMutateDeleteReaction.d.ts +3 -1
- package/dist/cjs/hooks/useMutateEditComment.d.ts +10 -0
- package/dist/cjs/hooks/useMutateEditPost.d.ts +10 -0
- package/dist/cjs/hooks/useMutateExternalBlobs.d.ts +2 -2
- package/dist/cjs/hooks/useMutateFile.d.ts +26 -0
- package/dist/cjs/hooks/useMutateFileRename.d.ts +5 -0
- package/dist/cjs/hooks/useMutateFileSubscribe.d.ts +7 -0
- package/dist/cjs/hooks/useMutateFileTrash.d.ts +10 -0
- package/dist/cjs/hooks/useMutateFileVersion.d.ts +7 -0
- package/dist/cjs/hooks/useMutateFiles.d.ts +2 -0
- package/dist/cjs/hooks/useMutateLeaveConversation.d.ts +4 -0
- package/dist/cjs/hooks/useMutateMessage.d.ts +2 -2
- package/dist/cjs/hooks/useMutatePost.d.ts +10 -0
- package/dist/cjs/hooks/useMutateReaction.d.ts +3 -1
- package/dist/cjs/hooks/useMutateRead.d.ts +1 -1
- package/dist/cjs/hooks/useMutateReplaceReaction.d.ts +6 -0
- package/dist/cjs/hooks/useMutateRestoreComment.d.ts +5 -0
- package/dist/cjs/hooks/useMutateRestorePost.d.ts +4 -0
- package/dist/cjs/hooks/useMutateStarred.d.ts +4 -0
- package/dist/cjs/hooks/useMutateSubscribe.d.ts +4 -0
- package/dist/cjs/hooks/useMutateTrashComment.d.ts +5 -0
- package/dist/cjs/hooks/useMutateTrashPost.d.ts +4 -0
- package/dist/cjs/hooks/useMutateTyping.d.ts +2 -0
- package/dist/cjs/hooks/useMutateUnsubscribe.d.ts +4 -0
- package/dist/cjs/hooks/useMutateVote.d.ts +5 -0
- package/dist/cjs/hooks/usePost.d.ts +1 -0
- package/dist/cjs/hooks/usePosts.d.ts +1 -0
- package/dist/cjs/hooks/usePostsList.d.ts +1 -0
- package/dist/cjs/hooks/useReactionList.d.ts +1 -0
- package/dist/cjs/hooks/useSessionState.d.ts +2 -0
- package/dist/cjs/hooks/useUnload.d.ts +2 -0
- package/dist/cjs/hooks/useUpdateEffect.d.ts +3 -0
- package/dist/cjs/hooks/useVotes.d.ts +1 -0
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +28 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/ConversationListItem.d.ts +1 -0
- package/dist/cjs/types/Files.d.ts +7 -0
- package/dist/cjs/types/Message.d.ts +2 -2
- package/dist/cjs/types/Posts.d.ts +4 -0
- package/dist/cjs/types/interfaces.d.ts +9 -0
- package/dist/cjs/types/types.d.ts +138 -22
- package/dist/cjs/ui/Dropdown.d.ts +18 -2
- package/dist/cjs/ui/Icon.d.ts +10 -2
- package/dist/cjs/ui/Overlay.d.ts +3 -1
- package/dist/cjs/ui/Sheet.d.ts +14 -0
- package/dist/cjs/ui/Spinner.d.ts +2 -1
- package/dist/cjs/utils/cacheUtils.d.ts +14 -0
- package/dist/cjs/utils/fileUtilities.d.ts +10 -1
- package/dist/cjs/utils/mentions.d.ts +6 -0
- package/dist/cjs/utils/openUrl.d.ts +1 -0
- package/dist/css/weavy-chat.css +637 -218
- package/dist/css/weavy-files.css +3046 -0
- package/dist/css/weavy-messenger.css +643 -213
- package/dist/css/weavy-posts.css +2773 -0
- package/dist/css/weavy.css +1749 -308
- package/dist/esm/client/WeavyClient.d.ts +1 -0
- package/dist/esm/components/Attachment.d.ts +5 -5
- package/dist/esm/components/Blob.d.ts +9 -0
- package/dist/esm/components/Comment.d.ts +18 -0
- package/dist/esm/components/CommentCount.d.ts +7 -0
- package/dist/esm/components/CommentEdit.d.ts +16 -0
- package/dist/esm/components/CommentPlaceholder.d.ts +8 -0
- package/dist/esm/components/CommentTrashed.d.ts +15 -0
- package/dist/esm/components/CommentView.d.ts +18 -0
- package/dist/esm/components/Comments.d.ts +8 -0
- package/dist/esm/components/ConversationListItem.d.ts +1 -1
- package/dist/esm/components/Dropzone.d.ts +10 -0
- package/dist/esm/components/Editor.d.ts +25 -0
- package/dist/esm/components/Embed.d.ts +8 -0
- package/dist/esm/components/FileItem.d.ts +41 -0
- package/dist/esm/components/FileList.d.ts +11 -0
- package/dist/esm/components/FileVersions.d.ts +9 -0
- package/dist/esm/components/Files.d.ts +4 -0
- package/dist/esm/components/Image.d.ts +3 -3
- package/dist/esm/components/MeetingCard.d.ts +1 -1
- package/dist/esm/components/Meetings.d.ts +2 -1
- package/dist/esm/components/Poll.d.ts +8 -0
- package/dist/esm/components/PollOption.d.ts +10 -0
- package/dist/esm/components/Post.d.ts +21 -0
- package/dist/esm/components/PostEdit.d.ts +17 -0
- package/dist/esm/components/PostList.d.ts +6 -0
- package/dist/esm/components/PostPlaceholder.d.ts +8 -0
- package/dist/esm/components/PostTrashed.d.ts +14 -0
- package/dist/esm/components/PostView.d.ts +21 -0
- package/dist/esm/components/Posts.d.ts +4 -0
- package/dist/esm/components/Preview.d.ts +1 -3
- package/dist/esm/components/PreviewFiles.d.ts +10 -0
- package/dist/esm/components/Reactions.d.ts +6 -2
- package/dist/esm/components/SearchUsers.d.ts +2 -1
- package/dist/esm/contexts/CloudFilesContext.d.ts +9 -0
- package/dist/esm/hooks/useApps.d.ts +1 -0
- package/dist/esm/hooks/useCloudFiles.d.ts +3 -0
- package/dist/esm/hooks/useCommentList.d.ts +1 -0
- package/dist/esm/hooks/useEmbeds.d.ts +5 -0
- package/dist/esm/hooks/useFileList.d.ts +1 -0
- package/dist/esm/hooks/useFileUploader.d.ts +8 -0
- package/dist/esm/hooks/useFileVersions.d.ts +2 -0
- package/dist/esm/hooks/useInfiniteScroll.d.ts +4 -0
- package/dist/esm/hooks/useIsFirstRender.d.ts +2 -0
- package/dist/esm/hooks/useMutateApps.d.ts +5 -0
- package/dist/esm/hooks/useMutateComment.d.ts +10 -0
- package/dist/esm/hooks/useMutateConversationName.d.ts +1 -1
- package/dist/esm/hooks/useMutateDeleteReaction.d.ts +3 -1
- package/dist/esm/hooks/useMutateEditComment.d.ts +10 -0
- package/dist/esm/hooks/useMutateEditPost.d.ts +10 -0
- package/dist/esm/hooks/useMutateExternalBlobs.d.ts +2 -2
- package/dist/esm/hooks/useMutateFile.d.ts +26 -0
- package/dist/esm/hooks/useMutateFileRename.d.ts +5 -0
- package/dist/esm/hooks/useMutateFileSubscribe.d.ts +7 -0
- package/dist/esm/hooks/useMutateFileTrash.d.ts +10 -0
- package/dist/esm/hooks/useMutateFileVersion.d.ts +7 -0
- package/dist/esm/hooks/useMutateFiles.d.ts +2 -0
- package/dist/esm/hooks/useMutateLeaveConversation.d.ts +4 -0
- package/dist/esm/hooks/useMutateMessage.d.ts +2 -2
- package/dist/esm/hooks/useMutatePost.d.ts +10 -0
- package/dist/esm/hooks/useMutateReaction.d.ts +3 -1
- package/dist/esm/hooks/useMutateRead.d.ts +1 -1
- package/dist/esm/hooks/useMutateReplaceReaction.d.ts +6 -0
- package/dist/esm/hooks/useMutateRestoreComment.d.ts +5 -0
- package/dist/esm/hooks/useMutateRestorePost.d.ts +4 -0
- package/dist/esm/hooks/useMutateStarred.d.ts +4 -0
- package/dist/esm/hooks/useMutateSubscribe.d.ts +4 -0
- package/dist/esm/hooks/useMutateTrashComment.d.ts +5 -0
- package/dist/esm/hooks/useMutateTrashPost.d.ts +4 -0
- package/dist/esm/hooks/useMutateTyping.d.ts +2 -0
- package/dist/esm/hooks/useMutateUnsubscribe.d.ts +4 -0
- package/dist/esm/hooks/useMutateVote.d.ts +5 -0
- package/dist/esm/hooks/usePost.d.ts +1 -0
- package/dist/esm/hooks/usePosts.d.ts +1 -0
- package/dist/esm/hooks/usePostsList.d.ts +1 -0
- package/dist/esm/hooks/useReactionList.d.ts +1 -0
- package/dist/esm/hooks/useSessionState.d.ts +2 -0
- package/dist/esm/hooks/useUnload.d.ts +2 -0
- package/dist/esm/hooks/useUpdateEffect.d.ts +3 -0
- package/dist/esm/hooks/useVotes.d.ts +1 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +28 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/ConversationListItem.d.ts +1 -0
- package/dist/esm/types/Files.d.ts +7 -0
- package/dist/esm/types/Message.d.ts +2 -2
- package/dist/esm/types/Posts.d.ts +4 -0
- package/dist/esm/types/interfaces.d.ts +9 -0
- package/dist/esm/types/types.d.ts +138 -22
- package/dist/esm/ui/Dropdown.d.ts +18 -2
- package/dist/esm/ui/Icon.d.ts +10 -2
- package/dist/esm/ui/Overlay.d.ts +3 -1
- package/dist/esm/ui/Sheet.d.ts +14 -0
- package/dist/esm/ui/Spinner.d.ts +2 -1
- package/dist/esm/utils/cacheUtils.d.ts +14 -0
- package/dist/esm/utils/fileUtilities.d.ts +10 -1
- package/dist/esm/utils/mentions.d.ts +6 -0
- package/dist/esm/utils/openUrl.d.ts +1 -0
- package/dist/index.d.ts +50 -6
- package/package.json +8 -2
- package/src/client/WeavyClient.ts +35 -1
- package/src/components/Attachment.tsx +20 -13
- package/src/components/Blob.tsx +28 -0
- package/src/components/Comment.tsx +43 -0
- package/src/components/CommentCount.tsx +15 -0
- package/src/components/CommentEdit.tsx +48 -0
- package/src/components/CommentPlaceholder.tsx +34 -0
- package/src/components/CommentTrashed.tsx +45 -0
- package/src/components/CommentView.tsx +142 -0
- package/src/components/Comments.tsx +78 -0
- package/src/components/Conversation.tsx +85 -31
- package/src/components/ConversationList.tsx +12 -41
- package/src/components/ConversationListItem.tsx +125 -74
- package/src/components/Dropzone.tsx +26 -0
- package/src/components/Editor.tsx +700 -0
- package/src/components/Embed.tsx +80 -0
- package/src/components/FileItem.tsx +391 -0
- package/src/components/FileList.tsx +166 -0
- package/src/components/FileVersions.tsx +100 -0
- package/src/components/Files.tsx +294 -0
- package/src/components/Image.tsx +11 -10
- package/src/components/Meeting.tsx +1 -2
- package/src/components/MeetingCard.tsx +1 -1
- package/src/components/Meetings.tsx +13 -5
- package/src/components/Message.tsx +14 -19
- package/src/components/Messages.tsx +38 -64
- package/src/components/NewConversation.tsx +8 -6
- package/src/components/PdfViewer.tsx +2 -2
- package/src/components/Poll.tsx +45 -0
- package/src/components/PollOption.tsx +65 -0
- package/src/components/Post.tsx +45 -0
- package/src/components/PostEdit.tsx +49 -0
- package/src/components/PostList.tsx +95 -0
- package/src/components/PostPlaceholder.tsx +32 -0
- package/src/components/PostTrashed.tsx +35 -0
- package/src/components/PostView.tsx +194 -0
- package/src/components/Posts.tsx +59 -0
- package/src/components/Preview.tsx +16 -23
- package/src/components/PreviewFiles.tsx +336 -0
- package/src/components/Reactions.tsx +142 -38
- package/src/components/SearchUsers.tsx +77 -37
- package/src/components/Typing.tsx +1 -1
- package/src/{components/FileBrowser.tsx → contexts/CloudFilesContext.tsx} +46 -30
- package/src/contexts/PreviewContext.tsx +102 -85
- package/src/contexts/WeavyContext.tsx +10 -6
- package/src/hooks/useApps.ts +23 -0
- package/src/hooks/useCloudFiles.ts +12 -0
- package/src/hooks/useCommentList.ts +30 -0
- package/src/hooks/useEmbeds.ts +126 -0
- package/src/hooks/useEvents.ts +3 -1
- package/src/hooks/useFileList.ts +84 -0
- package/src/hooks/useFileUploader.ts +38 -1
- package/src/hooks/useFileVersions.ts +20 -0
- package/src/hooks/useInfiniteScroll.ts +45 -0
- package/src/hooks/useIsFirstRender.ts +15 -0
- package/src/hooks/useMembers.ts +3 -3
- package/src/hooks/useMutateApps.ts +48 -0
- package/src/hooks/useMutateComment.ts +60 -0
- package/src/hooks/useMutateConversationName.ts +1 -1
- package/src/hooks/useMutateDeleteReaction.ts +17 -4
- package/src/hooks/useMutateEditComment.ts +63 -0
- package/src/hooks/useMutateEditPost.ts +64 -0
- package/src/hooks/useMutateExternalBlobs.ts +5 -9
- package/src/hooks/useMutateFile.ts +311 -0
- package/src/hooks/useMutateFileRename.ts +51 -0
- package/src/hooks/useMutateFileSubscribe.ts +80 -0
- package/src/hooks/useMutateFileTrash.ts +115 -0
- package/src/hooks/useMutateFileVersion.ts +85 -0
- package/src/hooks/useMutateFiles.ts +23 -0
- package/src/hooks/useMutateLeaveConversation.ts +38 -0
- package/src/hooks/useMutateMessage.ts +23 -62
- package/src/hooks/useMutatePost.ts +60 -0
- package/src/hooks/useMutateReaction.ts +21 -6
- package/src/hooks/useMutateRead.ts +8 -2
- package/src/hooks/useMutateRemoveMembers.ts +2 -9
- package/src/hooks/useMutateReplaceReaction.ts +59 -0
- package/src/hooks/useMutateRestoreComment.ts +37 -0
- package/src/hooks/useMutateRestorePost.ts +36 -0
- package/src/hooks/useMutateStarred.ts +35 -0
- package/src/hooks/useMutateSubscribe.ts +36 -0
- package/src/hooks/useMutateTrashComment.ts +37 -0
- package/src/hooks/useMutateTrashPost.ts +36 -0
- package/src/hooks/useMutateTyping.ts +5 -3
- package/src/hooks/useMutateUnsubscribe.ts +36 -0
- package/src/hooks/useMutateVote.ts +59 -0
- package/src/hooks/usePost.ts +20 -0
- package/src/hooks/usePosts.ts +21 -0
- package/src/hooks/usePostsList.ts +31 -0
- package/src/hooks/useReactionList.ts +21 -0
- package/src/hooks/useSearchUsers.ts +2 -2
- package/src/hooks/useSessionState.ts +23 -0
- package/src/hooks/useUnload.ts +19 -0
- package/src/hooks/useUpdateEffect.ts +16 -0
- package/src/hooks/useVotes.ts +21 -0
- package/src/index.ts +5 -1
- package/src/scss/theme/_appbar.scss +8 -4
- package/src/scss/theme/_card.scss +2 -0
- package/src/scss/theme/_comment-editor-cm.scss +5 -1
- package/src/scss/theme/_comments.scss +9 -8
- package/src/scss/theme/_conversations.scss +4 -0
- package/src/scss/theme/_files.scss +2 -81
- package/src/scss/theme/_icons.scss +21 -3
- package/src/scss/theme/_input.scss +13 -7
- package/src/scss/theme/_item.scss +23 -1
- package/src/scss/theme/_message-editor-cm.scss +5 -1
- package/src/scss/theme/_pager.scss +1 -1
- package/src/scss/theme/_post-editor-cm.scss +2 -2
- package/src/scss/theme/_post.scss +3 -10
- package/src/scss/theme/_preview-pdf-viewer.scss +996 -0
- package/src/scss/theme/_preview-pdf.scss +57 -783
- package/src/scss/theme/_sheet.scss +4 -1
- package/src/scss/theme/_spinner.scss +10 -1
- package/src/scss/theme/_tables.scss +2 -0
- package/src/scss/theme/base/_scroll.scss +3 -0
- package/src/scss/weavy-chat.scss +3 -1
- package/src/scss/weavy-files.scss +31 -0
- package/src/scss/weavy-messenger.scss +3 -1
- package/src/scss/weavy-posts.scss +35 -0
- package/src/scss/weavy.scss +2 -0
- package/src/types/ConversationListItem.ts +1 -0
- package/src/types/Files.ts +7 -0
- package/src/types/Message.ts +2 -2
- package/src/types/Posts.ts +4 -0
- package/src/types/interfaces.ts +13 -0
- package/src/types/types.ts +157 -28
- package/src/ui/Button.tsx +6 -5
- package/src/ui/Dropdown.tsx +67 -16
- package/src/ui/Icon.tsx +112 -15
- package/src/ui/Overlay.tsx +6 -2
- package/src/ui/Sheet.tsx +87 -0
- package/src/ui/Spinner.tsx +7 -4
- package/src/utils/cacheUtils.ts +246 -0
- package/src/utils/fileUtilities.ts +208 -24
- package/src/utils/infinite-scroll.js +103 -0
- package/src/utils/mentions.ts +50 -0
- package/src/utils/openUrl.ts +41 -0
- package/src/utils/{scrollToBottom.js → scroll-position.js} +50 -9
- package/src/utils/{scrollbarDetection.js → scrollbar-detection.js} +0 -0
- package/src/utils/utils.js +15 -1
- package/tsconfig.json +1 -1
- package/dist/cjs/components/ConversationForm.d.ts +0 -7
- package/dist/cjs/components/File.d.ts +0 -9
- package/dist/cjs/components/FileBrowser.d.ts +0 -6
- package/dist/cjs/hooks/usePreview.d.ts +0 -4
- package/dist/cjs/hooks/useReactions.d.ts +0 -3
- package/dist/esm/components/ConversationForm.d.ts +0 -7
- package/dist/esm/components/File.d.ts +0 -9
- package/dist/esm/components/FileBrowser.d.ts +0 -6
- package/dist/esm/hooks/usePreview.d.ts +0 -4
- package/dist/esm/hooks/useReactions.d.ts +0 -3
- package/src/components/ConversationForm.tsx +0 -210
- package/src/components/File.tsx +0 -21
- package/src/hooks/usePreview.ts +0 -21
- package/src/hooks/useReactions.ts +0 -51
- package/src/utils/infiniteScroll.js +0 -184
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useInfiniteQuery, useQuery } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// GET all comment for a parent
|
|
6
|
+
export default function useCommentList(parentId: number | null, type: "posts" | "files" | "apps", options: any) {
|
|
7
|
+
const PAGE_SIZE = 10;
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
|
|
10
|
+
if (!client) {
|
|
11
|
+
throw new Error('useCommentList must be used within an WeavyProvider');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const getPosts = async (opt: any) => {
|
|
15
|
+
let skip = opt.pageParam || 0;
|
|
16
|
+
const response = await client.get(`/api/${type}/${parentId}/comments?orderby=createdat+asc&skip=${skip}&top=${PAGE_SIZE}`);
|
|
17
|
+
|
|
18
|
+
return await response.json();
|
|
19
|
+
};
|
|
20
|
+
var opts = {
|
|
21
|
+
...options,
|
|
22
|
+
getNextPageParam: (lastPage:any, pages:any) => {
|
|
23
|
+
if (lastPage?.end < lastPage?.count) {
|
|
24
|
+
return pages.length * PAGE_SIZE;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return useInfiniteQuery<MessagesResult>(["comments", parentId], getPosts, opts)
|
|
30
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { useContext, useState } from "react";
|
|
2
|
+
import { useQuery } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
interface IIndexable {
|
|
6
|
+
url: string[],
|
|
7
|
+
[key: string]: string[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// handle embeds
|
|
11
|
+
export default function useEmbeds(callback: Function) {
|
|
12
|
+
const { client } = useContext(WeavyContext);
|
|
13
|
+
const regexp = /(((https?|ftp):\/\/|(www|ftp)\.)[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#]))/gmi;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const [latest, setLatest] = useState<string[]>([])
|
|
17
|
+
const [embeds, setEmbeds] = useState<string[]>([])
|
|
18
|
+
const [failed, setFailed] = useState<string[]>([])
|
|
19
|
+
const [rejected, setRejected] = useState<string[]>([])
|
|
20
|
+
const [candidates, setCandidates] = useState<{ [string: string]: number }>({})
|
|
21
|
+
|
|
22
|
+
if (!client) {
|
|
23
|
+
throw new Error('useEmbeds must be used within an WeavyProvider');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const arrayEquals = (a: string[], b: string[]) =>
|
|
27
|
+
a.length === b.length &&
|
|
28
|
+
a.every((v, i) => v === b[i]);
|
|
29
|
+
|
|
30
|
+
const fetchEmbed = async (url: string) => {
|
|
31
|
+
const data = new FormData();
|
|
32
|
+
data.append("url", url);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
|
|
36
|
+
const response = await client.post("/api/embeds",
|
|
37
|
+
"POST",
|
|
38
|
+
JSON.stringify({ url: url }));
|
|
39
|
+
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var json = await response.json();
|
|
45
|
+
|
|
46
|
+
setEmbeds((prev) => [...prev, url]);
|
|
47
|
+
setCandidates((prev) => {
|
|
48
|
+
delete prev[url];
|
|
49
|
+
return prev;
|
|
50
|
+
});
|
|
51
|
+
callback(json);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
// error, add to failed so that we don't fetch again
|
|
54
|
+
setFailed((prev) => [...prev, url]);
|
|
55
|
+
setCandidates((prev) => {
|
|
56
|
+
delete prev[url];
|
|
57
|
+
return prev;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const initEmbeds = (urls: string[]) =>{
|
|
64
|
+
setEmbeds(urls);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const clearEmbeds = () => {
|
|
68
|
+
setLatest([]);
|
|
69
|
+
setEmbeds([]);
|
|
70
|
+
setFailed([]);
|
|
71
|
+
setRejected([]);
|
|
72
|
+
setCandidates({});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const getEmbeds = async (content: string) => {
|
|
76
|
+
|
|
77
|
+
let matches = content.match(regexp);
|
|
78
|
+
|
|
79
|
+
if (matches !== null) {
|
|
80
|
+
matches = matches.map(url => {
|
|
81
|
+
if (url.startsWith("//")) {
|
|
82
|
+
return "http:" + url;
|
|
83
|
+
} else if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
84
|
+
return "http://" + url;
|
|
85
|
+
} else {
|
|
86
|
+
return url;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (matches === null || matches.length === 0) { // no matches
|
|
92
|
+
//console.log(latest, embeds, failed, candidates, rejected)
|
|
93
|
+
} else if (matches.length !== latest.length || !arrayEquals(matches, latest)) { // matches has changed{
|
|
94
|
+
// keep matches for comparing next time the doc is updated
|
|
95
|
+
setLatest(matches);
|
|
96
|
+
|
|
97
|
+
matches.forEach((match: string) => {
|
|
98
|
+
// add match if not already an embed, not failed or rejected before and not already a candidate
|
|
99
|
+
if (!embeds.includes(match) && !failed.includes(match) && !rejected.includes(match) && typeof (candidates[match]) === "undefined") {
|
|
100
|
+
setCandidates((prev) => {
|
|
101
|
+
prev[match] = setTimeout(() => { fetchEmbed(match); }, 500);
|
|
102
|
+
return prev;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// remove from rejected
|
|
108
|
+
setRejected((prev) => prev.filter(rejected => latest.includes(rejected)))
|
|
109
|
+
|
|
110
|
+
// remove candidates
|
|
111
|
+
for (let candidate in candidates) {
|
|
112
|
+
if (!latest.includes(candidate)) {
|
|
113
|
+
clearTimeout(candidates[candidate]);
|
|
114
|
+
//delete candidates[candidate];
|
|
115
|
+
setCandidates((prev) => {
|
|
116
|
+
delete prev[candidate];
|
|
117
|
+
return prev;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
return { getEmbeds, initEmbeds, clearEmbeds };
|
|
126
|
+
}
|
package/src/hooks/useEvents.ts
CHANGED
|
@@ -36,7 +36,9 @@ export default function useEvents() {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const off = (event: string, cb: Function) => {
|
|
39
|
-
|
|
39
|
+
if (callbacks[event]) {
|
|
40
|
+
callbacks[event] = callbacks[event].filter((i: any) => i !== cb);
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
return { dispatch, on, off, events };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useContext, useEffect } from "react";
|
|
2
|
+
import { Mutation, QueryFunctionContext, QueryKey, useInfiniteQuery, UseInfiniteQueryOptions, useQuery, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { addToQueryData, findAnyExistingItem, updateQueryData } from "../utils/cacheUtils";
|
|
5
|
+
import { FileMutation } from "./useMutateFile";
|
|
6
|
+
|
|
7
|
+
/// GET all posts in an app
|
|
8
|
+
export default function useFileList(appId: number | null, options: any = {}) {
|
|
9
|
+
const PAGE_SIZE = 25;
|
|
10
|
+
const { client } = useContext(WeavyContext);
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useFileList must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const queryClient = useQueryClient();
|
|
17
|
+
|
|
18
|
+
const filesKey = ['files', appId];
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
// Refetch data when meta changes
|
|
22
|
+
queryClient.removeQueries({
|
|
23
|
+
queryKey: filesKey,
|
|
24
|
+
exact: true,
|
|
25
|
+
predicate: (query) => {
|
|
26
|
+
let mismatch = JSON.stringify(query.meta) !== JSON.stringify(options.meta);
|
|
27
|
+
if (mismatch) {
|
|
28
|
+
//console.log("file query mismatch, removing query")
|
|
29
|
+
}
|
|
30
|
+
return mismatch;
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}, [options]);
|
|
34
|
+
|
|
35
|
+
const updateDataWithMutations = (data: any) => {
|
|
36
|
+
const mutatingFiles = queryClient.getMutationCache()
|
|
37
|
+
.findAll({mutationKey: filesKey, predicate: (mutation: Mutation) => !!(<unknown>mutation as FileMutation).state.context?.file})
|
|
38
|
+
.map((mutation: Mutation) => (<unknown>mutation as FileMutation).state.context!.file);
|
|
39
|
+
|
|
40
|
+
const meta = queryClient.getQueryCache().find<FilesResult>(filesKey)?.meta;
|
|
41
|
+
const order = meta?.order as FileOrder;
|
|
42
|
+
|
|
43
|
+
mutatingFiles.forEach((file) => {
|
|
44
|
+
//if (meta?.trashed === file.is_trashed) {
|
|
45
|
+
if (file.id < 1 && file.status !== "ok" && file.status !== "error") {
|
|
46
|
+
let existingFile = findAnyExistingItem<FileType>(data, "name", file.name, true);
|
|
47
|
+
if (existingFile) {
|
|
48
|
+
file.id = existingFile.id;
|
|
49
|
+
}
|
|
50
|
+
data = addToQueryData(data, file, order);
|
|
51
|
+
} else {
|
|
52
|
+
data = updateQueryData(data, file.id, (cacheFile: FileType) => { Object.assign(cacheFile, file)});
|
|
53
|
+
}
|
|
54
|
+
//}
|
|
55
|
+
});
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getFiles = async (opt: QueryFunctionContext) => {
|
|
60
|
+
let skip = opt.pageParam || 0;
|
|
61
|
+
let order: FileOrder | undefined = opt.meta && opt.meta.order as FileOrder;
|
|
62
|
+
let trashed: boolean = !!opt.meta?.trashed;
|
|
63
|
+
let orderParam = order ? order.by + (order.descending ? "+desc" : "") : "";
|
|
64
|
+
let url = "/api/apps/" + appId + "/files?skip=" + skip + "&top=" + PAGE_SIZE + "&orderby=" + orderParam;
|
|
65
|
+
if (trashed) {
|
|
66
|
+
url += "&trashed=null";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const response = await client.get(url);
|
|
70
|
+
return await response.json();
|
|
71
|
+
};
|
|
72
|
+
var opts: Omit<UseInfiniteQueryOptions<FilesResult, unknown, FilesResult, FilesResult, QueryKey>, "queryKey" | "queryFn"> | undefined = {
|
|
73
|
+
...options,
|
|
74
|
+
getNextPageParam: (lastPage:any, pages:any) => {
|
|
75
|
+
if (lastPage?.end < lastPage?.count) {
|
|
76
|
+
return pages.length * PAGE_SIZE;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
select: updateDataWithMutations
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return useInfiniteQuery<FilesResult>(['files', appId], getFiles, opts)
|
|
84
|
+
}
|
|
@@ -2,6 +2,43 @@ import { useContext } from "react";
|
|
|
2
2
|
import { useMutation } from "react-query";
|
|
3
3
|
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
4
|
|
|
5
|
+
export type UploadFileProps = {
|
|
6
|
+
file: File,
|
|
7
|
+
onProgress?: (variables: UploadProgressProps) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type UploadProgressProps = {
|
|
11
|
+
progress: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function useUploadFile() {
|
|
15
|
+
const { client } = useContext(WeavyContext);
|
|
16
|
+
|
|
17
|
+
if (!client) {
|
|
18
|
+
throw new Error('useMutateFile must be used within an WeavyProvider');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return async (file: File, onProgress?: (variables: UploadProgressProps) => void) => {
|
|
22
|
+
const formData = new FormData();
|
|
23
|
+
formData.append('blob', file);
|
|
24
|
+
|
|
25
|
+
const response = await client.upload("/api/blobs", "POST", formData, "",
|
|
26
|
+
(progress) => {
|
|
27
|
+
if (onProgress) {
|
|
28
|
+
onProgress({ progress: progress})
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw <ServerErrorResponse> await response.json();
|
|
34
|
+
}
|
|
35
|
+
const blob: BlobType = await response.json();
|
|
36
|
+
return blob;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
5
42
|
/// POST to upload a a file
|
|
6
43
|
export default function useFileUploader(callback: Function) {
|
|
7
44
|
|
|
@@ -23,7 +60,7 @@ export default function useFileUploader(callback: Function) {
|
|
|
23
60
|
formData,
|
|
24
61
|
"");
|
|
25
62
|
|
|
26
|
-
var uploaded = await response.json();
|
|
63
|
+
var uploaded = await response.json();
|
|
27
64
|
callback(uploaded);
|
|
28
65
|
},
|
|
29
66
|
{
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { QueryKey, useQuery } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// GET versions of a file
|
|
6
|
+
export default function useFileVersions(filesKey: QueryKey, fileId: number, options: any) {
|
|
7
|
+
const { client } = useContext(WeavyContext);
|
|
8
|
+
|
|
9
|
+
if (!client) {
|
|
10
|
+
throw new Error('useReactionList must be used within an WeavyProvider');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getVersions = async () => {
|
|
14
|
+
const response = await client.get(`/api/files/${fileId}/versions`);
|
|
15
|
+
const data = await response.json();
|
|
16
|
+
return data;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return useQuery<FileType[]>([...filesKey, fileId, "versions"], getVersions, options);
|
|
20
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useState, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { UseInfiniteQueryResult } from "react-query/types/react/types";
|
|
3
|
+
import { createScroller, createReverseScroller } from "../utils/infinite-scroll";
|
|
4
|
+
|
|
5
|
+
export default function useInfinteScroll(infiniteQuery: UseInfiniteQueryResult, deps: React.DependencyList = [], reverse: boolean = false) {
|
|
6
|
+
const loadMoreRef = useRef<any>();
|
|
7
|
+
const [resolveScrollerFetch, setResolveScrollerFetch] = useState<Function | undefined>()
|
|
8
|
+
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
if(!infiniteQuery.isLoading){
|
|
11
|
+
var scroller: IntersectionObserver | undefined;
|
|
12
|
+
|
|
13
|
+
requestAnimationFrame(() => {
|
|
14
|
+
scroller = createScroller(loadMoreRef.current, () => {
|
|
15
|
+
if (infiniteQuery.hasNextPage || infiniteQuery.isFetching) {
|
|
16
|
+
//console.log("infinite scroll fetch");
|
|
17
|
+
|
|
18
|
+
return infiniteQuery.fetchNextPage({ cancelRefetch: false }).then(() => {
|
|
19
|
+
// Wait for effects and trigger render before resolving
|
|
20
|
+
if (reverse) {
|
|
21
|
+
return new Promise((resolve: Function) => { setResolveScrollerFetch(() => {
|
|
22
|
+
//console.log("infinite scroll fetch resolved");
|
|
23
|
+
resolve()
|
|
24
|
+
})})
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}, reverse)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
//console.log("infinite scroll disconnect");
|
|
33
|
+
scroller?.disconnect();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
}, [infiniteQuery.isLoading, infiniteQuery.dataUpdatedAt, ...deps]);
|
|
39
|
+
|
|
40
|
+
return loadMoreRef;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useReverseInfiniteScroll(infiniteQuery: UseInfiniteQueryResult, deps: React.DependencyList = []) {
|
|
44
|
+
return useInfinteScroll(infiniteQuery, deps, true);
|
|
45
|
+
}
|
package/src/hooks/useMembers.ts
CHANGED
|
@@ -10,12 +10,12 @@ export default function useMembers(id: number | null, options: any) {
|
|
|
10
10
|
throw new Error('useMembers must be used within an WeavyProvider');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
const response = await client.get(
|
|
13
|
+
const getMembers = async () => {
|
|
14
|
+
const response = await client.get(`/api/apps/${id}/members?top=1000`);
|
|
15
15
|
const data = await response.json();
|
|
16
16
|
return data;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
return useQuery<MembersResult>(["members", id],
|
|
20
|
+
return useQuery<MembersResult>(["members", id], getMembers, options);
|
|
21
21
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { QueryKey, useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
export function useMutateAppsSubscribe(appKey: QueryKey) {
|
|
6
|
+
|
|
7
|
+
const { client } = useContext(WeavyContext);
|
|
8
|
+
const queryClient = useQueryClient();
|
|
9
|
+
|
|
10
|
+
if (!client) {
|
|
11
|
+
throw new Error('useMutateAppsSubscribe must be used within an WeavyProvider');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type MutateProps = {
|
|
15
|
+
appId: number,
|
|
16
|
+
subscribe: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const subscribeMutation = useMutation(async ({ appId, subscribe }: MutateProps) => {
|
|
20
|
+
if (appId >= 1) {
|
|
21
|
+
const response = await client.post(`/api/apps/${appId}/${subscribe ? "subscribe": "unsubscribe"}`, "POST", "");
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw await response.json();
|
|
24
|
+
}
|
|
25
|
+
return response.json();
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error(`Could not subscribe to app ${appId}.`);
|
|
28
|
+
}
|
|
29
|
+
},{
|
|
30
|
+
onMutate: async (variables: MutateProps) => {
|
|
31
|
+
var previousSubscribe: boolean | undefined;
|
|
32
|
+
queryClient.setQueryData(appKey, (filesApp: any) => {
|
|
33
|
+
previousSubscribe = filesApp.is_subscribed;
|
|
34
|
+
return Object.assign(filesApp, { is_subscribed: variables.subscribe })
|
|
35
|
+
})
|
|
36
|
+
return { previousSubscribe: previousSubscribe, subscribe: variables.subscribe }
|
|
37
|
+
},
|
|
38
|
+
onSuccess: (data: AppType, variables: MutateProps, context: any) => {
|
|
39
|
+
queryClient.setQueryData(appKey, (app: any) => Object.assign(app, data), { updatedAt: Date.now() })
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: appKey, exact: true });
|
|
41
|
+
},
|
|
42
|
+
onError(error: any, variables: MutateProps, context: any) {
|
|
43
|
+
queryClient.setQueryData(appKey, (app: any) => Object.assign(app, { is_subscribed: context.previousSubscribe }))
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return subscribeMutation;
|
|
48
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { addCacheItem } from "../utils/cacheUtils";
|
|
5
|
+
|
|
6
|
+
/// POST to add a new comment to a parent entity
|
|
7
|
+
export default function useMutateComment() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutateComment must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type MutateProps = {
|
|
18
|
+
parentId: number | null,
|
|
19
|
+
type: "posts" | "files" | "apps",
|
|
20
|
+
text: string,
|
|
21
|
+
blobs: BlobType[],
|
|
22
|
+
meeting: number | null,
|
|
23
|
+
embed: number | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const mutateComment = async ({ parentId, type, text, blobs, meeting, embed }: MutateProps) => {
|
|
27
|
+
|
|
28
|
+
const response = await client.post(`/api/${type}/${parentId}/comments`,
|
|
29
|
+
"POST",
|
|
30
|
+
JSON.stringify({
|
|
31
|
+
text: text,
|
|
32
|
+
blobs: blobs.map((b: BlobType) => { return b.id }),
|
|
33
|
+
meeting_id: meeting,
|
|
34
|
+
embed_id: embed
|
|
35
|
+
}));
|
|
36
|
+
return response.json();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return useMutation(mutateComment, {
|
|
40
|
+
onSuccess: (data: MessageType, variables: any, context: any) => {
|
|
41
|
+
addCacheItem(queryClient, ['comments', variables.parentId], data, context.tempId);
|
|
42
|
+
},
|
|
43
|
+
onMutate: async (variables: any) => {
|
|
44
|
+
await queryClient.cancelQueries(['comments', variables.parentId]);
|
|
45
|
+
|
|
46
|
+
const tempId = Math.random();
|
|
47
|
+
const tempData = {
|
|
48
|
+
id: tempId,
|
|
49
|
+
text: variables.text,
|
|
50
|
+
temp: true,
|
|
51
|
+
created_by: {display_name: variables.userName },
|
|
52
|
+
created_at: new Date().toUTCString()
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
addCacheItem(queryClient, ['comments', variables.parentId], tempData);
|
|
56
|
+
|
|
57
|
+
return { tempId }
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
-
import { useMutation } from "react-query";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
3
|
import { UserContext } from "../contexts/UserContext";
|
|
4
4
|
import { WeavyContext } from "../contexts/WeavyContext";
|
|
5
|
+
import { updateCacheItem } from "../utils/cacheUtils";
|
|
5
6
|
|
|
6
7
|
/// DELETE to remove a reaction from a message
|
|
7
8
|
export default function useMutateDeleteReaction() {
|
|
8
9
|
|
|
9
10
|
const { client } = useContext(WeavyContext);
|
|
10
11
|
const { user } = useContext(UserContext);
|
|
12
|
+
const queryClient = useQueryClient();
|
|
11
13
|
|
|
12
14
|
if (!client) {
|
|
13
15
|
throw new Error('useMutateDeleteReaction must be used within an WeavyProvider');
|
|
@@ -16,18 +18,29 @@ export default function useMutateDeleteReaction() {
|
|
|
16
18
|
|
|
17
19
|
type MutateProps = {
|
|
18
20
|
id: number | null,
|
|
21
|
+
parentId: number | null,
|
|
22
|
+
type: "messages" | "posts" | "comments",
|
|
19
23
|
reaction: string
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
const mutateDeleteReaction = async ({ id,
|
|
26
|
+
const mutateDeleteReaction = async ({ id, type }: MutateProps) => {
|
|
23
27
|
|
|
24
28
|
// remove the existing reaction
|
|
25
|
-
const response = await client.post(
|
|
29
|
+
const response = await client.post(`/api/${type}/${id}/reactions`,
|
|
26
30
|
"DELETE",
|
|
27
31
|
"");
|
|
28
32
|
|
|
29
33
|
return response;
|
|
30
34
|
};
|
|
31
35
|
|
|
32
|
-
return useMutation(mutateDeleteReaction
|
|
36
|
+
return useMutation(mutateDeleteReaction, {
|
|
37
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
38
|
+
|
|
39
|
+
},
|
|
40
|
+
onMutate: async (variables: any) => {
|
|
41
|
+
updateCacheItem(queryClient, [variables.type, variables.parentId], variables.id, (item: MessageType) => {
|
|
42
|
+
item.reactions = [...item.reactions.filter((r: ReactableType) => r.created_by_id !== user.id )];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
33
46
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
|
|
5
|
+
/// PATCH to update a Comment
|
|
6
|
+
export default function useMutateEditPost() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateEditComment must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type MutateProps = {
|
|
16
|
+
id: number | null,
|
|
17
|
+
appId: number | null,
|
|
18
|
+
parentId: number | null,
|
|
19
|
+
text: string,
|
|
20
|
+
blobs: BlobType[],
|
|
21
|
+
attachments: FileType[],
|
|
22
|
+
meeting: number | null,
|
|
23
|
+
embed: number | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const mutatePost = async ({ id, text, blobs, attachments, meeting, embed }: MutateProps) => {
|
|
27
|
+
|
|
28
|
+
const response = await client.post("/api/comments/" + id,
|
|
29
|
+
"PATCH",
|
|
30
|
+
JSON.stringify({
|
|
31
|
+
text: text,
|
|
32
|
+
blobs: blobs.map((b: BlobType) => { return b.id }),
|
|
33
|
+
attachments: attachments.map((a: FileType) => { return a.id }),
|
|
34
|
+
meeting_id: meeting,
|
|
35
|
+
embed_id: embed
|
|
36
|
+
}));
|
|
37
|
+
return response.json();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return useMutation(mutatePost, {
|
|
41
|
+
onSuccess: (data: MessageType, variables: any, context: any) => {
|
|
42
|
+
|
|
43
|
+
const previousData = queryClient.getQueryData<any>(['comments', variables.parentId]);
|
|
44
|
+
|
|
45
|
+
if (previousData && previousData.pages) {
|
|
46
|
+
// update cache
|
|
47
|
+
const newPagesArray = previousData.pages.map((page: any, i: number) => {
|
|
48
|
+
// update comment
|
|
49
|
+
page.data = [...page.data.map((message: MessageType) => message.id === variables.id ? data : message)]
|
|
50
|
+
return page;
|
|
51
|
+
}) ?? [];
|
|
52
|
+
|
|
53
|
+
queryClient.setQueryData(["comments", variables.parentId], (data: any) => ({
|
|
54
|
+
pages: newPagesArray,
|
|
55
|
+
pageParams: data.pageParams,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
onMutate: async (variables: any) => {
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|