@weavy/uikit-react 11.0.1 → 11.1.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.
Files changed (43) hide show
  1. package/changelog.md +9 -0
  2. package/dist/cjs/index.js +2 -2
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/client/WeavyClient.d.ts +1 -1
  5. package/dist/cjs/types/hooks/useUser.d.ts +2 -1
  6. package/dist/cjs/types/types/types.d.ts +8 -2
  7. package/dist/esm/index.js +2 -2
  8. package/dist/esm/index.js.map +1 -1
  9. package/dist/esm/types/client/WeavyClient.d.ts +1 -1
  10. package/dist/esm/types/hooks/useUser.d.ts +2 -1
  11. package/dist/esm/types/types/types.d.ts +8 -2
  12. package/dist/index.d.ts +1 -1
  13. package/package.json +1 -1
  14. package/src/client/WeavyClient.ts +3 -3
  15. package/src/components/Conversation.tsx +1 -1
  16. package/src/components/ConversationListItem.tsx +2 -2
  17. package/src/components/Messages.tsx +13 -12
  18. package/src/components/SearchUsers.tsx +2 -2
  19. package/src/components/Typing.tsx +4 -4
  20. package/src/hooks/useBadge.ts +1 -1
  21. package/src/hooks/useChat.ts +1 -1
  22. package/src/hooks/useConversation.ts +1 -1
  23. package/src/hooks/useConversations.ts +1 -1
  24. package/src/hooks/useFileUploader.ts +5 -1
  25. package/src/hooks/useMembers.ts +1 -1
  26. package/src/hooks/useMessages.ts +1 -1
  27. package/src/hooks/useMutateChat.ts +1 -1
  28. package/src/hooks/useMutateConversation.ts +1 -1
  29. package/src/hooks/useMutateConversationName.ts +1 -1
  30. package/src/hooks/useMutateDeleteReaction.ts +1 -1
  31. package/src/hooks/useMutateExternalBlobs.ts +1 -1
  32. package/src/hooks/useMutateMeeting.ts +1 -1
  33. package/src/hooks/useMutateMembers.ts +1 -1
  34. package/src/hooks/useMutateMessage.ts +2 -1
  35. package/src/hooks/useMutatePinned.ts +1 -1
  36. package/src/hooks/useMutateReaction.ts +1 -1
  37. package/src/hooks/useMutateRead.ts +1 -1
  38. package/src/hooks/useMutateRemoveMembers.ts +1 -1
  39. package/src/hooks/useMutateTyping.ts +1 -1
  40. package/src/hooks/usePresence.ts +4 -0
  41. package/src/hooks/useSearchUsers.ts +1 -1
  42. package/src/hooks/useUser.ts +4 -3
  43. package/src/types/types.ts +9 -2
@@ -1,5 +1,5 @@
1
1
  export default class WeavyClient {
2
- uri: string;
2
+ url: string;
3
3
  tokenFactory: () => string | Promise<string>;
4
4
  connection: import("@microsoft/signalr").HubConnection;
5
5
  groups: string[];
@@ -1 +1,2 @@
1
- export default function useUser(client: any): import("react-query").UseQueryResult<UserType, unknown>;
1
+ import WeavyClient from "../client/WeavyClient";
2
+ export default function useUser(client: WeavyClient): import("react-query").UseQueryResult<UserType, unknown>;
@@ -1,10 +1,16 @@
1
1
  /// <reference types="react" />
2
+ interface WeavyClient {
3
+ url: string;
4
+ tokenFactory: (() => string | Promise<string>);
5
+ subscribe: Function;
6
+ unsubscribe: Function;
7
+ }
2
8
  declare type WeavyClientOptions = {
3
- uri: string;
9
+ url: string;
4
10
  tokenFactory: (() => string | Promise<string>);
5
11
  };
6
12
  declare type WeavyContextProps = {
7
- client: any;
13
+ client: WeavyClient | null;
8
14
  options?: WeavyContextOptions;
9
15
  };
10
16
  declare type WeavyContextOptions = {
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import React, { FC } from 'react';
4
4
  import { Styles } from 'react-modal';
5
5
 
6
6
  declare class WeavyClient {
7
- uri: string;
7
+ url: string;
8
8
  tokenFactory: () => string | Promise<string>;
9
9
  connection: _microsoft_signalr.HubConnection;
10
10
  groups: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weavy/uikit-react",
3
- "version": "11.0.1",
3
+ "version": "11.1.0",
4
4
  "author": "Weavy",
5
5
  "description": "React UI-kit for Weavy",
6
6
  "homepage": "https://github.com/weavy/weavy-uikit-react",
@@ -1,7 +1,7 @@
1
1
  import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr';
2
2
 
3
3
  export default class WeavyClient {
4
- uri;
4
+ url;
5
5
  tokenFactory;
6
6
  connection;
7
7
  groups: string[];
@@ -14,14 +14,14 @@ export default class WeavyClient {
14
14
  EVENT_RECONNECTED = "reconnected";
15
15
 
16
16
  constructor(options: WeavyClientOptions) {
17
- this.uri = options.uri;
17
+ this.url = options.url;
18
18
  this.tokenFactory = options.tokenFactory
19
19
  this.groups = [];
20
20
  this.connectionEvents = [];
21
21
 
22
22
  this.connection = new HubConnectionBuilder()
23
23
  .configureLogging(LogLevel.None)
24
- .withUrl(this.uri + "/hubs/rtm", {
24
+ .withUrl(this.url + "/hubs/rtm", {
25
25
  accessTokenFactory: this.tokenFactory
26
26
  })
27
27
  .withAutomaticReconnect()
@@ -157,7 +157,7 @@ const Conversation = ({ id, showBackButton }: ConversationProps) => {
157
157
  <div className={wy('avatar-header')}>
158
158
  <Avatar src={user.avatar_url} name={user.title} presence={user.presence} id={user.id} size={256} />
159
159
  <h2>Welcome {user.name}!</h2>
160
- Select a conversation to get started
160
+ Create or select a conversation to get started
161
161
  </div>
162
162
  }
163
163
  {selectedConversationId && dataMembers &&
@@ -40,10 +40,10 @@ const ConversationListItem = ({ item, refetchConversations }: ConversationListIt
40
40
  }, [item.id])
41
41
 
42
42
  useEffect(() => {
43
- client.subscribe(`a${item.id}`, "app-updated", handleAppUpdated);
43
+ client?.subscribe(`a${item.id}`, "app-updated", handleAppUpdated);
44
44
 
45
45
  return () => {
46
- client.unsubscribe(`a${item.id}`, "app-updated", handleAppUpdated);
46
+ client?.unsubscribe(`a${item.id}`, "app-updated", handleAppUpdated);
47
47
  }
48
48
  }, [item.id])
49
49
 
@@ -94,30 +94,31 @@ const Messages = ({ id, members, displayName, avatarUrl }: Props) => {
94
94
  // mark conversation as read
95
95
  readMessageMutation.mutate({ id: id, read: true })
96
96
 
97
- client.subscribe(`a${id}`, "message-inserted", handleRealtimeMessage);
98
- client.subscribe(`a${id}`, "conversation-read", handleRealtimeSeenBy);
99
- client.subscribe(`a${id}`, "reaction-inserted", handleRealtimeReactionInserted);
100
- client.subscribe(`a${id}`, "reaction-deleted", handleRealtimeReactionDeleted);
97
+ client?.subscribe(`a${id}`, "message-inserted", handleRealtimeMessage);
98
+ client?.subscribe(`a${id}`, "conversation-read", handleRealtimeSeenBy);
99
+ client?.subscribe(`a${id}`, "reaction-inserted", handleRealtimeReactionInserted);
100
+ client?.subscribe(`a${id}`, "reaction-deleted", handleRealtimeReactionDeleted);
101
101
  }
102
102
 
103
103
  return () => {
104
104
  window.removeEventListener('focus', handleFocus, false)
105
105
 
106
106
  if (id) {
107
-
108
107
  // remove additional pages in cache. Only get first page
109
108
  let qd = queryClient.getQueryData(["messages", id]);
109
+
110
110
  if (qd) {
111
+
111
112
  queryClient.setQueryData(["messages", id], (data: any) => ({
112
- pages: data?.pages.splice(0, 1),
113
- pageParams: data?.pageParams.splice(0, 1),
114
- }));
113
+ pages: data?.pages.slice(0,1),
114
+ pageParams: [undefined]
115
+ }));
115
116
  }
116
117
 
117
- client.unsubscribe(`a${id}`, "message-inserted", handleRealtimeMessage);
118
- client.unsubscribe(`a${id}`, "conversation-read", handleRealtimeSeenBy);
119
- client.unsubscribe(`a${id}`, "reaction-inserted", handleRealtimeReactionInserted);
120
- client.unsubscribe(`a${id}`, "reaction-deleted", handleRealtimeReactionDeleted);
118
+ client?.unsubscribe(`a${id}`, "message-inserted", handleRealtimeMessage);
119
+ client?.unsubscribe(`a${id}`, "conversation-read", handleRealtimeSeenBy);
120
+ client?.unsubscribe(`a${id}`, "reaction-inserted", handleRealtimeReactionInserted);
121
+ client?.unsubscribe(`a${id}`, "reaction-deleted", handleRealtimeReactionDeleted);
121
122
  }
122
123
  }
123
124
  }, [id]);
@@ -60,8 +60,8 @@ const SearchUsers = ({handleSubmit, buttonTitle}: SearchUsersProps) => {
60
60
  <td className={wy('search-result-table-icon')}>
61
61
  <Avatar src={user.avatar_url} size={24} id={user.id} presence={user.presence} name={user.display_name} />
62
62
  </td>
63
- <td>{user.display_name}</td>
64
- <td className={wy('search-result-table-icon')}><input type="checkbox" checked={isChecked(user.id)} onChange={(e) => handleSelected(e, user)} /></td>
63
+ <td><label htmlFor={'chk' + user.id}>{user.display_name}</label></td>
64
+ <td className={wy('search-result-table-icon')}><input type="checkbox" id={'chk' + user.id} checked={isChecked(user.id)} onChange={(e) => handleSelected(e, user)} /></td>
65
65
  </tr>
66
66
  )
67
67
  })}
@@ -26,12 +26,12 @@ const Typing = ({ children, id, context }: Props) => {
26
26
  useEffect(() => {
27
27
  setActiveTypers([]);
28
28
 
29
- client.subscribe(`a${id}`, "typing", handleTyping);
30
- client.subscribe(`a${id}`, "message-inserted", handleStopTyping);
29
+ client?.subscribe(`a${id}`, "typing", handleTyping);
30
+ client?.subscribe(`a${id}`, "message-inserted", handleStopTyping);
31
31
 
32
32
  return () => {
33
- client.unsubscribe(`a${id}`, "typing", handleTyping);
34
- client.unsubscribe(`a${id}`, "message-inserted", handleStopTyping);
33
+ client?.unsubscribe(`a${id}`, "typing", handleTyping);
34
+ client?.unsubscribe(`a${id}`, "message-inserted", handleStopTyping);
35
35
  }
36
36
  }, [id])
37
37
 
@@ -12,7 +12,7 @@ export default function useBadge() {
12
12
 
13
13
  const getBadge = async () => {
14
14
 
15
- const response = await fetch(client.uri + "/api/conversations/badge", {
15
+ const response = await fetch(client.url + "/api/conversations/badge", {
16
16
  headers: {
17
17
  "content-type": "application/json",
18
18
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -12,7 +12,7 @@ export default function useChat(id: string, options: any) {
12
12
 
13
13
  const getConversation = async () => {
14
14
 
15
- const response = await fetch(client.uri + "/api/apps/idf/" + id, {
15
+ const response = await fetch(client.url + "/api/apps/idf/" + id, {
16
16
  headers: {
17
17
  "content-type": "application/json",
18
18
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -13,7 +13,7 @@ export default function useConversation(id: number | null, options: any) {
13
13
 
14
14
  const getConversation = async () => {
15
15
 
16
- const response = await fetch(client.uri + "/api/conversations/" + id, {
16
+ const response = await fetch(client.url + "/api/conversations/" + id, {
17
17
  headers: {
18
18
  "content-type": "application/json",
19
19
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -12,7 +12,7 @@ export default function useConversations() {
12
12
 
13
13
  const getConversations = async () => {
14
14
 
15
- const response = await fetch(client.uri + "/api/conversations?contextual=false", {
15
+ const response = await fetch(client.url + "/api/conversations?contextual=false", {
16
16
  headers: {
17
17
  "content-type": "application/json",
18
18
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -7,13 +7,17 @@ export default function useFileUploader(callback: Function) {
7
7
 
8
8
  const { client } = useContext(WeavyContext);
9
9
 
10
+ if (!client) {
11
+ throw new Error('useFileUploader must be used within an WeavyProvider');
12
+ }
13
+
10
14
  return useMutation(
11
15
  async ({ request }: any) => {
12
16
 
13
17
  const formData = new FormData();
14
18
  formData.append('blob', request.file);
15
19
 
16
- var response = await fetch(client.uri + "/api/blobs", {
20
+ var response = await fetch(client.url + "/api/blobs", {
17
21
  method: 'POST',
18
22
  body: formData,
19
23
  headers: {
@@ -12,7 +12,7 @@ export default function useMembers(id: number | null, options: any) {
12
12
 
13
13
  const getConversationMembers = async () => {
14
14
 
15
- const response = await fetch(client.uri + "/api/apps/" + id + "/members", {
15
+ const response = await fetch(client.url + "/api/apps/" + id + "/members", {
16
16
  headers: {
17
17
  "content-type": "application/json",
18
18
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -14,7 +14,7 @@ export default function useMessages(id: number | null, options: any) {
14
14
  const getMessages = async (opt: any) => {
15
15
  let skip = opt.pageParam || 0;
16
16
 
17
- const response = await fetch(client.uri + "/api/apps/" + id + "/messages?orderby=createdat+desc&skip=" + skip + "&top=" + PAGE_SIZE, {
17
+ const response = await fetch(client.url + "/api/apps/" + id + "/messages?orderby=createdat+desc&skip=" + skip + "&top=" + PAGE_SIZE, {
18
18
  headers: {
19
19
  "content-type": "application/json",
20
20
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -21,7 +21,7 @@ export default function useMutateChat() {
21
21
  // create new conversation
22
22
  const mutateChat = async ({ identifier, members }: MutateProps) => {
23
23
 
24
- const response = await fetch(client.uri + "/api/apps/", {
24
+ const response = await fetch(client.url + "/api/apps/", {
25
25
  method: "POST",
26
26
  body: JSON.stringify({
27
27
  identifier: identifier,
@@ -20,7 +20,7 @@ export default function useMutateConversation() {
20
20
  // create new conversation
21
21
  const mutateConversation = async ({ members }: MutateProps) => {
22
22
 
23
- const response = await fetch(client.uri + "/api/conversations/", {
23
+ const response = await fetch(client.url + "/api/conversations/", {
24
24
  method: "POST",
25
25
  body: JSON.stringify({ members: members }),
26
26
  headers: {
@@ -20,7 +20,7 @@ export default function useMutateConversationName() {
20
20
 
21
21
  const mutateConversationName = async ({ id, name }: MutateProps) => {
22
22
 
23
- const response = await fetch(client.uri + "/api/apps/" + id, {
23
+ const response = await fetch(client.url + "/api/apps/" + id, {
24
24
  method: "PATCH",
25
25
  body: JSON.stringify({ name: name }),
26
26
  headers: {
@@ -22,7 +22,7 @@ export default function useMutateDeleteReaction() {
22
22
  const mutateDeleteReaction = async ({ id, reaction }: MutateProps) => {
23
23
 
24
24
  // remove the existing reaction
25
- const response = await fetch(client.uri + "/api/messages/" + id + "/reactions/", {
25
+ const response = await fetch(client.url + "/api/messages/" + id + "/reactions/", {
26
26
  method: "DELETE",
27
27
  headers: {
28
28
  "content-type": "application/json",
@@ -19,7 +19,7 @@ export default function useMutateExternalBlobs() {
19
19
 
20
20
  const mutateExternalBlobs = async ({ blobs }: MutateProps) => {
21
21
 
22
- const response = await fetch(client.uri + "/api/blobs/external", {
22
+ const response = await fetch(client.url + "/api/blobs/external", {
23
23
  method: "POST",
24
24
  body: JSON.stringify(blobs),
25
25
  headers: {
@@ -19,7 +19,7 @@ export default function useMutateMeeting() {
19
19
 
20
20
  const mutateMeeting = async ({ provider }: MutateProps) => {
21
21
 
22
- const response = await fetch(client.uri + "/api/meetings", {
22
+ const response = await fetch(client.url + "/api/meetings", {
23
23
  method: "POST",
24
24
  body: JSON.stringify({provider: provider}),
25
25
  headers: {
@@ -21,7 +21,7 @@ export default function useMutateMembers() {
21
21
  // add members to conversation
22
22
  const mutateMembers = async ({ id, members }: MutateProps) => {
23
23
 
24
- const response = await fetch(client.uri + "/api/apps/" + id + "/members/", {
24
+ const response = await fetch(client.url + "/api/apps/" + id + "/members/", {
25
25
  method: "POST",
26
26
  body: JSON.stringify(members),
27
27
  headers: {
@@ -22,7 +22,7 @@ export default function useMutateMessage() {
22
22
  }
23
23
 
24
24
  const mutateMessage = async ({ id, text, userId, attachments, meetings }: MutateProps) => {
25
- const response = await fetch(client.uri + "/api/apps/" + id + "/messages", {
25
+ const response = await fetch(client.url + "/api/apps/" + id + "/messages", {
26
26
  method: "POST",
27
27
  body: JSON.stringify({
28
28
  text: text,
@@ -86,6 +86,7 @@ export default function useMutateMessage() {
86
86
  let pageMessages = [...data, {
87
87
  id: tempId,
88
88
  text: variables.text,
89
+ html: variables.text,
89
90
  display_name: "",
90
91
  temp: true,
91
92
  parent_id: null,
@@ -20,7 +20,7 @@ export default function useMutatePinned() {
20
20
 
21
21
  const mutatePinned = async ({ id, pin }: MutateProps) => {
22
22
 
23
- const response = await fetch(client.uri + "/api/conversations/" + id + "/pin", {
23
+ const response = await fetch(client.url + "/api/conversations/" + id + "/pin", {
24
24
  method: + !pin ? "DELETE": "PUT",
25
25
  body: "",
26
26
  headers: {
@@ -22,7 +22,7 @@ export default function useMutateReaction() {
22
22
  const mutateReaction = async ({id, reaction }: MutateProps) => {
23
23
 
24
24
 
25
- const response = await fetch(client.uri + "/api/messages/" + id + "/reactions/", {
25
+ const response = await fetch(client.url + "/api/messages/" + id + "/reactions/", {
26
26
  method: "POST",
27
27
  body: JSON.stringify({ content: reaction}),
28
28
  headers: {
@@ -20,7 +20,7 @@ export default function useMutateRead() {
20
20
 
21
21
  const mutateRead = async ({ id, read }: MutateProps) => {
22
22
 
23
- const response = await fetch(client.uri + "/api/conversations/" + id + "/read", {
23
+ const response = await fetch(client.url + "/api/conversations/" + id + "/read", {
24
24
  method: !read ? "DELETE": "PUT",
25
25
  body: "",
26
26
  headers: {
@@ -22,7 +22,7 @@ export default function useMutateRemoveMembers() {
22
22
 
23
23
  const mutateRemove = async ({ id, members }: MutateProps) => {
24
24
 
25
- const response = await fetch(client.uri + "/api/apps/" + id + "/members/" + members.join(","), {
25
+ const response = await fetch(client.url + "/api/apps/" + id + "/members/" + members.join(","), {
26
26
  method: "DELETE",
27
27
  body: JSON.stringify(members),
28
28
  headers: {
@@ -18,7 +18,7 @@ export default function useMutateTyping() {
18
18
 
19
19
  const mutateTyping = async ({ id }: MutateProps) => {
20
20
 
21
- const response = await fetch(client.uri + "/api/conversations/" + id + "/typing", {
21
+ const response = await fetch(client.url + "/api/conversations/" + id + "/typing", {
22
22
  method: "PUT",
23
23
  body: JSON.stringify({}),
24
24
  headers: {
@@ -6,6 +6,10 @@ export default function usePresence() {
6
6
 
7
7
  const {client} = useContext(WeavyContext);
8
8
 
9
+ if (!client) {
10
+ throw new Error('usePresence must be used within an WeavyProvider');
11
+ }
12
+
9
13
  useEffect(() => {
10
14
  client.subscribe("online", "online", handlePresenceChange)
11
15
  }, []);
@@ -12,7 +12,7 @@ export default function useSearchUsers(text: string, options: any) {
12
12
  }
13
13
 
14
14
  const getUsers = async () => {
15
- const response = await fetch(client.uri + "/api/users?q=" + text + "&skip=0&top=" + PAGE_SIZE, {
15
+ const response = await fetch(client.url + "/api/users?q=" + text + "&skip=0&top=" + PAGE_SIZE, {
16
16
  headers: {
17
17
  "content-type": "application/json",
18
18
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -1,9 +1,10 @@
1
1
  //import { useContext } from "react";
2
2
  import { useQuery } from "react-query";
3
+ import WeavyClient from "../client/WeavyClient";
3
4
  //import { WeavyContext } from "../contexts/WeavyContext";
4
5
 
5
6
  /// GET current user
6
- export default function useUser(client: any) {
7
+ export default function useUser(client: WeavyClient) {
7
8
  //const { client } = useContext(WeavyContext);
8
9
 
9
10
  if (!client) {
@@ -13,7 +14,7 @@ export default function useUser(client: any) {
13
14
  const getUser = async () => {
14
15
 
15
16
  try {
16
- const response = await fetch(client.uri + "/api/user", {
17
+ const response = await fetch(client.url + "/api/user", {
17
18
  headers: {
18
19
  "content-type": "application/json",
19
20
  "Authorization": "Bearer " + await client.tokenFactory()
@@ -27,7 +28,7 @@ export default function useUser(client: any) {
27
28
  console.error("Could not load Weavy user data...")
28
29
  return null;
29
30
  } catch(err: any){
30
- console.error(`Could not connect to the Weavy backend. Please make sure ${client.uri} is up and running!`)
31
+ console.error(`Could not connect to the Weavy backend. Please make sure ${client.url} is up and running!`)
31
32
  }
32
33
 
33
34
 
@@ -1,10 +1,17 @@
1
+ interface WeavyClient {
2
+ url: string,
3
+ tokenFactory: (() => string | Promise<string>),
4
+ subscribe: Function,
5
+ unsubscribe: Function,
6
+ }
7
+
1
8
  type WeavyClientOptions = {
2
- uri: string,
9
+ url: string,
3
10
  tokenFactory: (() => string | Promise<string>)
4
11
  }
5
12
 
6
13
  type WeavyContextProps = {
7
- client: any,
14
+ client: WeavyClient | null,
8
15
  options?: WeavyContextOptions
9
16
  };
10
17