@weavy/uikit-react 14.0.4 → 15.0.1
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,85 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { MutationKey, useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { removeCacheItem, updateCacheItem } from "../utils/cacheUtils";
|
|
5
|
+
|
|
6
|
+
export function useMutateFileVersionRestore(filesKey: MutationKey) {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateFileVersion must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type MutateProps = {
|
|
16
|
+
versionFile: FileType
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const restoreMutation = useMutation(async ({ versionFile }: MutateProps) => {
|
|
20
|
+
if (versionFile.id >= 1 && versionFile.version) {
|
|
21
|
+
const response = await client.post(`/api/files/${versionFile.id}/versions/${versionFile.version}/restore`, "POST", "");
|
|
22
|
+
return response.json();
|
|
23
|
+
} else {
|
|
24
|
+
throw new Error(`Could not restore ${versionFile.name} to version ${versionFile.version}.`);
|
|
25
|
+
}
|
|
26
|
+
},{
|
|
27
|
+
onMutate: async (variables: MutateProps) => {
|
|
28
|
+
var previousFile:FileType | undefined;
|
|
29
|
+
updateCacheItem(queryClient, filesKey, variables.versionFile.id, (existingFile: FileType) => {previousFile = existingFile; return Object.assign(existingFile, variables.versionFile, { status: "pending" })});
|
|
30
|
+
updateCacheItem(queryClient, [...filesKey, variables.versionFile.id, "versions"], variables.versionFile.id, (existingFile: FileType) => {previousFile = existingFile; return Object.assign(existingFile, { status: "pending" })});
|
|
31
|
+
return {versionFile: variables.versionFile, previousFile: previousFile }
|
|
32
|
+
},
|
|
33
|
+
onSuccess: (data: MessageType, variables: MutateProps, context: any) => {
|
|
34
|
+
updateCacheItem(queryClient, filesKey, variables.versionFile.id, (existingFile: FileType) => Object.assign(existingFile, data, { status: "ok" }));
|
|
35
|
+
queryClient.removeQueries([...filesKey, variables.versionFile.id, "versions"]);
|
|
36
|
+
},
|
|
37
|
+
onError(error: any, variables: MutateProps, context: any) {
|
|
38
|
+
updateCacheItem(queryClient, filesKey, variables.versionFile.id, (existingFile: FileType) => Object.assign(existingFile, context.previousFile, { status: "error" }));
|
|
39
|
+
updateCacheItem(queryClient, [...filesKey, variables.versionFile.id, "versions"], variables.versionFile.id, (existingFile: FileType) => Object.assign(existingFile, { status: "error" }));
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return restoreMutation;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useMutateFileVersionDelete(filesKey: MutationKey) {
|
|
47
|
+
|
|
48
|
+
const { client } = useContext(WeavyContext);
|
|
49
|
+
const queryClient = useQueryClient();
|
|
50
|
+
|
|
51
|
+
if (!client) {
|
|
52
|
+
throw new Error('useMutateFileVersionRemove must be used within an WeavyProvider');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type MutateProps = {
|
|
56
|
+
versionFile: FileType
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const deleteMutation = useMutation(async ({ versionFile }: MutateProps) => {
|
|
60
|
+
if (versionFile.id >= 1 && versionFile.version) {
|
|
61
|
+
const response = await client.post(`/api/files/${versionFile.id}/versions/${versionFile.version}`, "DELETE", "");
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw <ServerErrorResponse> await response.json();
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
throw <ServerErrorResponse> { status: 400, title: `Could not remove ${versionFile.name} version ${versionFile.version}.`};
|
|
67
|
+
}
|
|
68
|
+
},{
|
|
69
|
+
onMutate: async (variables: MutateProps) => {
|
|
70
|
+
const versionPredicate = (item: any) => item.id === variables.versionFile.id && item.version === variables.versionFile.version;
|
|
71
|
+
updateCacheItem(queryClient, [...filesKey, variables.versionFile.id, "versions"], versionPredicate, (existingFile: FileType) => Object.assign(existingFile, { status: "pending" }));
|
|
72
|
+
},
|
|
73
|
+
onSuccess: (data: any, variables: MutateProps, context: any) => {
|
|
74
|
+
const versionPredicate = (item: any) => item.id === variables.versionFile.id && item.version === variables.versionFile.version;
|
|
75
|
+
removeCacheItem(queryClient, [...filesKey, variables.versionFile.id, "versions"], versionPredicate);
|
|
76
|
+
},
|
|
77
|
+
onError(error: any, variables: MutateProps, context: any) {
|
|
78
|
+
// Show in error list instead?
|
|
79
|
+
const versionPredicate = (item: any) => item.id === variables.versionFile.id && item.version === variables.versionFile.version;
|
|
80
|
+
updateCacheItem(queryClient, [...filesKey, variables.versionFile.id, "versions"], versionPredicate, (existingFile: FileType) => Object.assign(existingFile, { status: undefined }));
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return deleteMutation;
|
|
85
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
3
|
+
import { CreateFileProps } from "./useMutateFile";
|
|
4
|
+
|
|
5
|
+
export const useMutateFilesCreate = (appId: number) => {
|
|
6
|
+
const { client } = useContext(WeavyContext);
|
|
7
|
+
|
|
8
|
+
if (!client) {
|
|
9
|
+
throw new Error('useMutateFile must be used within an WeavyProvider');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return async ({ blob, replace = false }: CreateFileProps) => {
|
|
13
|
+
const response = await client.post("/api/apps/" + appId + "/files",
|
|
14
|
+
"POST",
|
|
15
|
+
JSON.stringify({ blob_id: blob.id, replace: replace }));
|
|
16
|
+
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw <ServerErrorResponse> await response.json();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return <FileType> await response.json();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { MessengerContext } from "../contexts/MessengerContext";
|
|
4
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
5
|
+
|
|
6
|
+
/// DELETE leave conversation
|
|
7
|
+
export default function useMutateLeaveConversation() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const { setSelectedConversationId } = useContext(MessengerContext);
|
|
11
|
+
const queryClient = useQueryClient();
|
|
12
|
+
|
|
13
|
+
if (!client) {
|
|
14
|
+
throw new Error('useMutateLeaveConversation must be used within an WeavyProvider');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
type MutateProps = {
|
|
19
|
+
id: number | null,
|
|
20
|
+
members: number[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const mutateLeave = async ({ id, members }: MutateProps) => {
|
|
24
|
+
|
|
25
|
+
const response = await client.post("/api/apps/" + id + "/members/" + members.join(","),
|
|
26
|
+
"DELETE",
|
|
27
|
+
JSON.stringify(members));
|
|
28
|
+
|
|
29
|
+
return response;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return useMutation(mutateLeave, {
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
queryClient.invalidateQueries("conversations");
|
|
35
|
+
setSelectedConversationId(null);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { useMutation, useQueryClient } from "react-query";
|
|
3
3
|
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { addCacheItem } from "../utils/cacheUtils";
|
|
4
5
|
|
|
5
6
|
/// PSOT to add a new message to an app
|
|
6
7
|
export default function useMutateMessage() {
|
|
@@ -12,23 +13,21 @@ export default function useMutateMessage() {
|
|
|
12
13
|
throw new Error('useMutateMessage must be used within an WeavyProvider');
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
16
|
type MutateProps = {
|
|
17
17
|
id: number | null,
|
|
18
18
|
text: string,
|
|
19
19
|
userId: number,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
blobs: BlobType[],
|
|
21
|
+
meeting: number | null,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const mutateMessage = async ({ id, text,
|
|
25
|
-
|
|
24
|
+
const mutateMessage = async ({ id, text, blobs, meeting }: MutateProps) => {
|
|
26
25
|
const response = await client.post("/api/apps/" + id + "/messages",
|
|
27
26
|
"POST",
|
|
28
27
|
JSON.stringify({
|
|
29
28
|
text: text,
|
|
30
|
-
blobs:
|
|
31
|
-
meeting_id:
|
|
29
|
+
blobs: blobs.map((b: BlobType) => { return b.id }),
|
|
30
|
+
meeting_id: meeting,
|
|
32
31
|
}));
|
|
33
32
|
return response.json();
|
|
34
33
|
};
|
|
@@ -36,27 +35,7 @@ export default function useMutateMessage() {
|
|
|
36
35
|
return useMutation(mutateMessage, {
|
|
37
36
|
onSuccess: (data: MessageType, variables: any, context: any) => {
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
if (previousData && previousData.pages) {
|
|
41
|
-
// update cache
|
|
42
|
-
const newPagesArray = previousData.pages.map((page: any, i: number) => {
|
|
43
|
-
// remove temp message
|
|
44
|
-
if (i === 0) {
|
|
45
|
-
page.data = [
|
|
46
|
-
...page.data.filter((message: MessageType) => message.id !== context.tempId),
|
|
47
|
-
data
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return page;
|
|
52
|
-
|
|
53
|
-
}) ?? [];
|
|
54
|
-
|
|
55
|
-
queryClient.setQueryData(["messages", variables.id], (data: any) => ({
|
|
56
|
-
pages: newPagesArray,
|
|
57
|
-
pageParams: data.pageParams,
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
38
|
+
addCacheItem(queryClient, ['messages', variables.id], data, context.tempId);
|
|
60
39
|
|
|
61
40
|
// refetch conversations list
|
|
62
41
|
queryClient.invalidateQueries("conversations");
|
|
@@ -65,42 +44,24 @@ export default function useMutateMessage() {
|
|
|
65
44
|
onMutate: async (variables: any) => {
|
|
66
45
|
await queryClient.cancelQueries(['messages', variables.id]);
|
|
67
46
|
|
|
68
|
-
const previousData = queryClient.getQueryData<any>(['messages', variables.id]);
|
|
69
47
|
const tempId = Math.random();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
created_at: new Date().toUTCString(),
|
|
86
|
-
attachments: [],
|
|
87
|
-
reactions: [],
|
|
88
|
-
reactions_count: 0
|
|
89
|
-
}];
|
|
90
|
-
lastPage.data = pageMessages;
|
|
91
|
-
|
|
92
|
-
// update cache
|
|
93
|
-
queryClient.setQueryData(["messages", variables.id], (data: any) => {
|
|
94
|
-
let updatedPages = [lastPage];
|
|
95
|
-
if (data?.pages.length > 1) {
|
|
96
|
-
updatedPages = [lastPage, ...data?.pages.slice(1)];
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
pages: updatedPages,
|
|
100
|
-
pageParams: data?.pageParams,
|
|
101
|
-
}
|
|
102
|
-
});
|
|
48
|
+
const tempData: MessageType = {
|
|
49
|
+
id: tempId,
|
|
50
|
+
app_id: -1,
|
|
51
|
+
attachment_ids: [],
|
|
52
|
+
is_subscribed: true,
|
|
53
|
+
is_trashed: false,
|
|
54
|
+
text: variables.text,
|
|
55
|
+
html: variables.text,
|
|
56
|
+
plain: variables.text,
|
|
57
|
+
temp: true,
|
|
58
|
+
created_by_id: variables.userId,
|
|
59
|
+
created_by: { id: variables.userId, avatar_url: "", display_name: "", presence: "", name: "" },
|
|
60
|
+
created_at: new Date().toUTCString(),
|
|
61
|
+
attachments: [],
|
|
62
|
+
reactions: []
|
|
103
63
|
}
|
|
64
|
+
addCacheItem(queryClient, ['messages', variables.id], tempData);
|
|
104
65
|
|
|
105
66
|
return { tempId }
|
|
106
67
|
}
|
|
@@ -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
|
+
/// PSOT to add a new post to a Posts app
|
|
7
|
+
export default function useMutatePost() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutatePost must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type MutateProps = {
|
|
18
|
+
appId: number | null,
|
|
19
|
+
text: string,
|
|
20
|
+
blobs: BlobType[],
|
|
21
|
+
meeting: number | null,
|
|
22
|
+
embed: number | null,
|
|
23
|
+
options: PollOptionType[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const mutatePost = async ({ appId, text, blobs, meeting, embed, options }: MutateProps) => {
|
|
27
|
+
|
|
28
|
+
const response = await client.post("/api/apps/" + appId + "/posts",
|
|
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
|
+
options: options.filter((o: PollOptionType) => o.text.trim() !== "" ).map((o: PollOptionType) => { return {text: o.text}; })
|
|
36
|
+
}));
|
|
37
|
+
return response.json();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return useMutation(mutatePost, {
|
|
41
|
+
onSuccess: (data: MessageType, variables: any, context: any) => {
|
|
42
|
+
addCacheItem(queryClient, ['posts', variables.appId], data, context.tempId, { descending: true });
|
|
43
|
+
},
|
|
44
|
+
onMutate: async (variables: any) => {
|
|
45
|
+
await queryClient.cancelQueries(['posts', variables.appId]);
|
|
46
|
+
|
|
47
|
+
const tempId = Math.random();
|
|
48
|
+
const tempData = {
|
|
49
|
+
id: tempId,
|
|
50
|
+
text: variables.text,
|
|
51
|
+
temp: true,
|
|
52
|
+
created_by: {display_name: variables.userName },
|
|
53
|
+
created_at: new Date().toUTCString()
|
|
54
|
+
};
|
|
55
|
+
addCacheItem(queryClient, ['posts', variables.appId], tempData, undefined, { descending: true });
|
|
56
|
+
|
|
57
|
+
return { tempId }
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -1,32 +1,47 @@
|
|
|
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
|
/// POST to add a reaction to a message
|
|
7
8
|
export default function useMutateReaction() {
|
|
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('useMutateReaction must be used within an WeavyProvider');
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
17
18
|
type MutateProps = {
|
|
19
|
+
parentId: number | null,
|
|
18
20
|
id: number | null,
|
|
21
|
+
type: "messages" | "posts" | "comments",
|
|
19
22
|
reaction: string
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
const mutateReaction = async ({ id, reaction }: MutateProps) => {
|
|
23
|
-
|
|
24
|
-
const response = await client.post(
|
|
25
|
+
const mutateReaction = async ({ id, type, reaction }: MutateProps) => {
|
|
26
|
+
|
|
27
|
+
const response = await client.post(`/api/${type}/${id}/reactions`,
|
|
25
28
|
"POST",
|
|
26
29
|
JSON.stringify({ content: reaction }));
|
|
27
30
|
|
|
28
31
|
return response;
|
|
29
32
|
};
|
|
30
33
|
|
|
31
|
-
return useMutation(mutateReaction
|
|
34
|
+
return useMutation(mutateReaction, {
|
|
35
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
36
|
+
|
|
37
|
+
},
|
|
38
|
+
onMutate: async (variables: any) => {
|
|
39
|
+
updateCacheItem(queryClient, [variables.type, variables.parentId], variables.id, (item: MessageType) => {
|
|
40
|
+
item.reactions = item.reactions || [];
|
|
41
|
+
item.reactions = [...item.reactions, { content: variables.reaction, created_by_id: user.id }];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
|
|
32
47
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { useMutation, useQueryClient } from "react-query";
|
|
3
3
|
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { updateCacheItem } from "../utils/cacheUtils";
|
|
4
5
|
|
|
5
6
|
/// PUT or DELETE to update read state on a conversation
|
|
6
7
|
export default function useMutateRead() {
|
|
@@ -14,13 +15,13 @@ export default function useMutateRead() {
|
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
type MutateProps = {
|
|
17
|
-
id: number | null,
|
|
18
|
+
id: number | null,
|
|
18
19
|
read: boolean,
|
|
19
20
|
messageId: number | null
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
const mutateRead = async ({ id, read, messageId }: MutateProps) => {
|
|
23
|
-
const url = read ? `/api/conversations/${id}/
|
|
24
|
+
const url = read ? `/api/conversations/${id}/mark?messageId=${messageId}`: `/api/conversations/${id}/mark`;
|
|
24
25
|
const response = await client.post(url, !read ? "DELETE": "PUT", "")
|
|
25
26
|
return response.json();
|
|
26
27
|
};
|
|
@@ -28,6 +29,11 @@ export default function useMutateRead() {
|
|
|
28
29
|
return useMutation(mutateRead, {
|
|
29
30
|
onSuccess: () => {
|
|
30
31
|
queryClient.invalidateQueries("conversations");
|
|
32
|
+
},
|
|
33
|
+
onMutate: async (variables: any) => {
|
|
34
|
+
updateCacheItem(queryClient, 'conversations', variables.id, (item: ConversationType) => {
|
|
35
|
+
item.is_unread = !variables.read;
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
38
|
});
|
|
33
39
|
}
|
|
@@ -7,9 +7,7 @@ import { WeavyContext } from "../contexts/WeavyContext";
|
|
|
7
7
|
export default function useMutateRemoveMembers() {
|
|
8
8
|
|
|
9
9
|
const { client } = useContext(WeavyContext);
|
|
10
|
-
|
|
11
|
-
const queryClient = useQueryClient();
|
|
12
|
-
|
|
10
|
+
|
|
13
11
|
if (!client) {
|
|
14
12
|
throw new Error('useMutateRemoveMembers must be used within an WeavyProvider');
|
|
15
13
|
}
|
|
@@ -29,10 +27,5 @@ export default function useMutateRemoveMembers() {
|
|
|
29
27
|
return response;
|
|
30
28
|
};
|
|
31
29
|
|
|
32
|
-
return useMutation(mutateRemove
|
|
33
|
-
onSuccess: () => {
|
|
34
|
-
queryClient.invalidateQueries("conversations");
|
|
35
|
-
setSelectedConversationId(null);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
30
|
+
return useMutation(mutateRemove);
|
|
38
31
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { UserContext } from "../contexts/UserContext";
|
|
4
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
5
|
+
import { updateCacheItem } from "../utils/cacheUtils";
|
|
6
|
+
|
|
7
|
+
/// Replaces a reaction from on message
|
|
8
|
+
export default function useMutateReplaceReaction() {
|
|
9
|
+
|
|
10
|
+
const { client } = useContext(WeavyContext);
|
|
11
|
+
const { user } = useContext(UserContext);
|
|
12
|
+
const queryClient = useQueryClient();
|
|
13
|
+
|
|
14
|
+
if (!client) {
|
|
15
|
+
throw new Error('useMutateReplaceReaction must be used within an WeavyProvider');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
type MutateProps = {
|
|
20
|
+
id: number | null,
|
|
21
|
+
parentId: number | null,
|
|
22
|
+
type: "messages" | "posts" | "comments",
|
|
23
|
+
reaction: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const mutateReplaceReaction = async ({ id, type, reaction }: MutateProps) => {
|
|
27
|
+
|
|
28
|
+
// remove the existing reaction
|
|
29
|
+
await client.post(`/api/${type}/${id}/reactions`,
|
|
30
|
+
"DELETE",
|
|
31
|
+
"");
|
|
32
|
+
|
|
33
|
+
// add the new reaction
|
|
34
|
+
const response = await client.post(`/api/${type}/${id}/reactions`,
|
|
35
|
+
"POST",
|
|
36
|
+
JSON.stringify({ content: reaction }));
|
|
37
|
+
|
|
38
|
+
return response;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return useMutation(mutateReplaceReaction, {
|
|
42
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
43
|
+
|
|
44
|
+
},
|
|
45
|
+
onMutate: async (variables: any) => {
|
|
46
|
+
updateCacheItem(queryClient, [variables.type, variables.parentId], variables.id, (item: MessageType) => {
|
|
47
|
+
item.reactions = item.reactions.map((r: ReactableType) => {
|
|
48
|
+
if(r.created_by_id !== user.id){
|
|
49
|
+
return r;
|
|
50
|
+
}
|
|
51
|
+
// replace reaction
|
|
52
|
+
r.content = variables.reaction;
|
|
53
|
+
return r;
|
|
54
|
+
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { updateCacheItem } from "../utils/cacheUtils";
|
|
5
|
+
|
|
6
|
+
/// POST to restore a Comment
|
|
7
|
+
export default function useMutateRestoreComment() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutateRestoreComment must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
appId: number | null,
|
|
19
|
+
parentId: number | null,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const restoreComment = async ({ id }: MutateProps) => {
|
|
23
|
+
const response = await client.post(`/api/comments/${id}/restore`, "POST", "");
|
|
24
|
+
return response.json();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return useMutation(restoreComment, {
|
|
28
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
29
|
+
updateCacheItem(queryClient, ['comments', variables.parentId], variables.id, (item: MessageType) => {
|
|
30
|
+
item.is_trashed = data.is_trashed;
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
onMutate: async (variables: any) => {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { updateCacheItem } from "../utils/cacheUtils";
|
|
5
|
+
|
|
6
|
+
/// POST to update a Post
|
|
7
|
+
export default function useMutateRestorePost() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutateRestorePost must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
appId: number | null,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const restorePost = async ({ id }: MutateProps) => {
|
|
22
|
+
const response = await client.post(`/api/posts/${id}/restore`, "POST", "");
|
|
23
|
+
return response.json();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return useMutation(restorePost, {
|
|
27
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
28
|
+
updateCacheItem(queryClient, ['posts', variables.appId], variables.id, (item: MessageType) => {
|
|
29
|
+
item.is_trashed = data.is_trashed;
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
onMutate: async (variables: any) => {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 starred state on a conversation
|
|
6
|
+
export default function useMutateStarred() {
|
|
7
|
+
|
|
8
|
+
const { client } = useContext(WeavyContext);
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('useMutateStarred must be used within an WeavyProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
star: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const mutateStarred = async ({ id, star }: MutateProps) => {
|
|
22
|
+
|
|
23
|
+
const response = await client.post("/api/apps/" + id + "/stars",
|
|
24
|
+
!star ? "DELETE" : "POST",
|
|
25
|
+
"");
|
|
26
|
+
|
|
27
|
+
return response;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return useMutation(mutateStarred, {
|
|
31
|
+
onSuccess: () => {
|
|
32
|
+
queryClient.invalidateQueries("conversations");
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
3
|
+
import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
|
+
import { updateCacheItem } from "../utils/cacheUtils";
|
|
5
|
+
|
|
6
|
+
/// POST to subscribe
|
|
7
|
+
export default function useMutateSubscribe() {
|
|
8
|
+
|
|
9
|
+
const { client } = useContext(WeavyContext);
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new Error('useMutateSubscribe must be used within an WeavyProvider');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type MutateProps = {
|
|
17
|
+
id: number | null,
|
|
18
|
+
appId: number | null,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const subscribe = async ({ id }: MutateProps) => {
|
|
22
|
+
const response = await client.post(`/api/posts/${id}/subscribe`, "POST", "");
|
|
23
|
+
return response.json();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return useMutation(subscribe, {
|
|
27
|
+
onSuccess: (data: any, variables: any, context: any) => {
|
|
28
|
+
updateCacheItem(queryClient, ['posts', variables.appId], variables.id, (item: MessageType) => {
|
|
29
|
+
item.is_subscribed = data.is_subscribed;
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
onMutate: async (variables: any) => {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|