@planningcenter/chat-react-native 3.2.0-rc.1 → 3.2.0-rc.11
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/build/components/conversation/message_form.d.ts +2 -2
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +95 -41
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_reaction.d.ts +2 -2
- package/build/components/conversations/action_toggle_button.d.ts +21 -0
- package/build/components/conversations/action_toggle_button.d.ts.map +1 -0
- package/build/components/conversations/action_toggle_button.js +48 -0
- package/build/components/conversations/action_toggle_button.js.map +1 -0
- package/build/components/conversations/conversation_actions.d.ts +10 -0
- package/build/components/conversations/conversation_actions.d.ts.map +1 -0
- package/build/components/conversations/conversation_actions.js +84 -0
- package/build/components/conversations/conversation_actions.js.map +1 -0
- package/build/components/conversations/conversation_preview.d.ts +2 -1
- package/build/components/conversations/conversation_preview.d.ts.map +1 -1
- package/build/components/conversations/conversation_preview.js +27 -9
- package/build/components/conversations/conversation_preview.js.map +1 -1
- package/build/components/conversations/conversations.d.ts +2 -3
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +5 -11
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/conversations/mute_indicator.d.ts +5 -0
- package/build/components/conversations/mute_indicator.d.ts.map +1 -0
- package/build/components/conversations/mute_indicator.js +19 -0
- package/build/components/conversations/mute_indicator.js.map +1 -0
- package/build/components/conversations/unread_count_badge.d.ts +2 -1
- package/build/components/conversations/unread_count_badge.d.ts.map +1 -1
- package/build/components/conversations/unread_count_badge.js +9 -1
- package/build/components/conversations/unread_count_badge.js.map +1 -1
- package/build/components/display/action_button.d.ts +2 -1
- package/build/components/display/action_button.d.ts.map +1 -1
- package/build/components/display/action_button.js +3 -4
- package/build/components/display/action_button.js.map +1 -1
- package/build/components/display/badge.d.ts +5 -4
- package/build/components/display/badge.d.ts.map +1 -1
- package/build/components/display/badge.js +5 -2
- package/build/components/display/badge.js.map +1 -1
- package/build/components/display/button.d.ts +3 -2
- package/build/components/display/button.d.ts.map +1 -1
- package/build/components/display/button.js.map +1 -1
- package/build/components/display/icon.d.ts +14 -1
- package/build/components/display/icon.d.ts.map +1 -1
- package/build/components/display/icon.js +9 -0
- package/build/components/display/icon.js.map +1 -1
- package/build/components/display/icon_button.d.ts +2 -2
- package/build/components/display/icon_button.d.ts.map +1 -1
- package/build/components/display/icon_button.js.map +1 -1
- package/build/components/display/person.d.ts +3 -1
- package/build/components/display/person.d.ts.map +1 -1
- package/build/components/display/person.js +2 -2
- package/build/components/display/person.js.map +1 -1
- package/build/components/display/text.js.map +1 -1
- package/build/components/display/toggle_button.d.ts +3 -2
- package/build/components/display/toggle_button.d.ts.map +1 -1
- package/build/components/display/toggle_button.js.map +1 -1
- package/build/components/display/utils/button_colors.d.ts +3 -3
- package/build/components/display/utils/button_colors.d.ts.map +1 -1
- package/build/components/display/utils/button_colors.js +1 -1
- package/build/components/display/utils/button_colors.js.map +1 -1
- package/build/components/page/error_boundary.d.ts +1 -1
- package/build/components/primitive/avatar_primitive.d.ts.map +1 -1
- package/build/components/primitive/avatar_primitive.js +3 -2
- package/build/components/primitive/avatar_primitive.js.map +1 -1
- package/build/components/primitive/banner_primitive.d.ts +2 -1
- package/build/components/primitive/banner_primitive.d.ts.map +1 -1
- package/build/components/primitive/banner_primitive.js +0 -1
- package/build/components/primitive/banner_primitive.js.map +1 -1
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/chat_context.d.ts +2 -0
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +6 -1
- package/build/contexts/chat_context.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +14 -0
- package/build/contexts/conversations_context.d.ts.map +1 -0
- package/build/contexts/conversations_context.js +38 -0
- package/build/contexts/conversations_context.js.map +1 -0
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +214 -0
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -0
- package/build/hooks/groups/use_group_members_for_new_conversation.js +50 -0
- package/build/hooks/groups/use_group_members_for_new_conversation.js.map +1 -0
- package/build/hooks/groups/use_groups_conversation_create.d.ts +9 -0
- package/build/hooks/groups/use_groups_conversation_create.d.ts.map +1 -0
- package/build/hooks/groups/use_groups_conversation_create.js +36 -0
- package/build/hooks/groups/use_groups_conversation_create.js.map +1 -0
- package/build/hooks/use_conversation.d.ts +1 -1
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +1 -1
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_conversations.d.ts +6 -32
- package/build/hooks/use_conversations.d.ts.map +1 -1
- package/build/hooks/use_conversations.js +15 -14
- package/build/hooks/use_conversations.js.map +1 -1
- package/build/hooks/use_conversations_actions.d.ts +221 -0
- package/build/hooks/use_conversations_actions.d.ts.map +1 -0
- package/build/hooks/use_conversations_actions.js +93 -0
- package/build/hooks/use_conversations_actions.js.map +1 -0
- package/build/hooks/use_conversations_cache.d.ts +18 -0
- package/build/hooks/use_conversations_cache.d.ts.map +1 -0
- package/build/hooks/{use_conversation_jolt_events.js → use_conversations_cache.js} +27 -17
- package/build/hooks/use_conversations_cache.js.map +1 -0
- package/build/hooks/use_conversations_jolt_events.d.ts +3 -0
- package/build/hooks/use_conversations_jolt_events.d.ts.map +1 -0
- package/build/hooks/use_conversations_jolt_events.js +12 -0
- package/build/hooks/use_conversations_jolt_events.js.map +1 -0
- package/build/hooks/use_create_android_ripple_color.d.ts +1 -1
- package/build/hooks/use_create_android_ripple_color.d.ts.map +1 -1
- package/build/hooks/use_giphy.d.ts +9 -0
- package/build/hooks/use_giphy.d.ts.map +1 -0
- package/build/hooks/use_giphy.js +63 -0
- package/build/hooks/use_giphy.js.map +1 -0
- package/build/hooks/use_jolt.d.ts.map +1 -1
- package/build/hooks/use_jolt.js +39 -10
- package/build/hooks/use_jolt.js.map +1 -1
- package/build/hooks/use_message_create.d.ts +11 -0
- package/build/hooks/use_message_create.d.ts.map +1 -0
- package/build/hooks/use_message_create.js +35 -0
- package/build/hooks/use_message_create.js.map +1 -0
- package/build/navigation/index.d.ts +23 -6
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +25 -8
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_filter_recipients/conversation_filter_recipients_screen.d.ts.map +1 -0
- package/build/screens/conversation_filter_recipients/conversation_filter_recipients_screen.js.map +1 -0
- package/build/screens/conversation_filters/components/conversation_filters.js.map +1 -1
- package/build/screens/conversation_filters/components/rows.d.ts +2 -1
- package/build/screens/conversation_filters/components/rows.d.ts.map +1 -1
- package/build/screens/conversation_filters/components/rows.js +19 -14
- package/build/screens/conversation_filters/components/rows.js.map +1 -1
- package/build/screens/conversation_filters/hooks/filters.js +1 -1
- package/build/screens/conversation_filters/hooks/filters.js.map +1 -1
- package/build/screens/conversation_new/components/form_list.d.ts +12 -0
- package/build/screens/conversation_new/components/form_list.d.ts.map +1 -0
- package/build/screens/conversation_new/components/form_list.js +42 -0
- package/build/screens/conversation_new/components/form_list.js.map +1 -0
- package/build/screens/conversation_new/components/groups_form.d.ts +7 -0
- package/build/screens/conversation_new/components/groups_form.d.ts.map +1 -0
- package/build/screens/conversation_new/components/groups_form.js +101 -0
- package/build/screens/conversation_new/components/groups_form.js.map +1 -0
- package/build/screens/conversation_new/components/member_error_card.d.ts +5 -0
- package/build/screens/conversation_new/components/member_error_card.d.ts.map +1 -0
- package/build/screens/conversation_new/components/member_error_card.js +17 -0
- package/build/screens/conversation_new/components/member_error_card.js.map +1 -0
- package/build/screens/conversation_new/components/source_app_error_card.d.ts +2 -0
- package/build/screens/conversation_new/components/source_app_error_card.d.ts.map +1 -0
- package/build/screens/conversation_new/components/source_app_error_card.js +16 -0
- package/build/screens/conversation_new/components/source_app_error_card.js.map +1 -0
- package/build/screens/conversation_new/components/team_form.d.ts +8 -0
- package/build/screens/conversation_new/components/team_form.d.ts.map +1 -0
- package/build/screens/conversation_new/components/team_form.js +11 -0
- package/build/screens/conversation_new/components/team_form.js.map +1 -0
- package/build/screens/conversation_new/conversation_new_screen.d.ts +12 -0
- package/build/screens/conversation_new/conversation_new_screen.d.ts.map +1 -0
- package/build/screens/conversation_new/conversation_new_screen.js +16 -0
- package/build/screens/conversation_new/conversation_new_screen.js.map +1 -0
- package/build/screens/conversation_new/utils/fake_member_data.d.ts +3 -0
- package/build/screens/conversation_new/utils/fake_member_data.d.ts.map +1 -0
- package/build/screens/conversation_new/utils/fake_member_data.js +129 -0
- package/build/screens/conversation_new/utils/fake_member_data.js.map +1 -0
- package/build/screens/conversation_screen.d.ts +1 -0
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +1 -1
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_recipients_screen.d.ts.map +1 -0
- package/build/screens/{create → conversation_select_recipients}/conversation_select_recipients_screen.js +6 -5
- package/build/screens/conversation_select_recipients/conversation_select_recipients_screen.js.map +1 -0
- package/build/screens/conversations/components/chat_group_badge.js +1 -1
- package/build/screens/conversations/components/chat_group_badge.js.map +1 -1
- package/build/screens/conversations/components/list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/list_header_component.js +6 -2
- package/build/screens/conversations/components/list_header_component.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +6 -13
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/design_system_screen.js +1 -0
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/screens/message_actions_screen.d.ts +2 -2
- package/build/screens/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +1 -1
- package/build/screens/message_actions_screen.js.map +1 -1
- package/build/screens/send_giphy_screen.d.ts +10 -0
- package/build/screens/send_giphy_screen.d.ts.map +1 -0
- package/build/screens/send_giphy_screen.js +98 -0
- package/build/screens/send_giphy_screen.js.map +1 -0
- package/build/types/resources/groups/groups_group_resource.d.ts +1 -1
- package/build/types/resources/groups/groups_group_resource.js.map +1 -1
- package/build/types/resources/groups/groups_member_resource_with_person.d.ts +14 -0
- package/build/types/resources/groups/groups_member_resource_with_person.d.ts.map +1 -0
- package/build/types/resources/groups/groups_member_resource_with_person.js +2 -0
- package/build/types/resources/groups/groups_member_resource_with_person.js.map +1 -0
- package/build/types/resources/member.d.ts +0 -10
- package/build/types/resources/member.d.ts.map +1 -1
- package/build/types/resources/member.js.map +1 -1
- package/build/utils/cache/page_mutations.d.ts +18 -0
- package/build/utils/cache/page_mutations.d.ts.map +1 -1
- package/build/utils/cache/page_mutations.js +13 -0
- package/build/utils/cache/page_mutations.js.map +1 -1
- package/build/utils/client/client.d.ts +2 -2
- package/build/utils/client/client.d.ts.map +1 -1
- package/build/utils/client/client.js +12 -4
- package/build/utils/client/client.js.map +1 -1
- package/build/utils/client/request_helpers.d.ts +15 -8
- package/build/utils/client/request_helpers.d.ts.map +1 -1
- package/build/utils/client/request_helpers.js +2 -1
- package/build/utils/client/request_helpers.js.map +1 -1
- package/build/utils/client/transform_request_data.d.ts +11 -6
- package/build/utils/client/transform_request_data.d.ts.map +1 -1
- package/build/utils/client/transform_request_data.js +1 -1
- package/build/utils/client/transform_request_data.js.map +1 -1
- package/build/utils/client/transform_response.d.ts +1 -1
- package/build/utils/client/transform_response.d.ts.map +1 -1
- package/build/utils/client/transform_response.js +2 -0
- package/build/utils/client/transform_response.js.map +1 -1
- package/build/utils/client/utils.d.ts +3 -3
- package/build/utils/client/utils.d.ts.map +1 -1
- package/build/utils/client/utils.js +6 -6
- package/build/utils/client/utils.js.map +1 -1
- package/build/utils/date.d.ts.map +1 -1
- package/build/utils/date.js +1 -0
- package/build/utils/date.js.map +1 -1
- package/build/utils/deepCamelCaseKeys.d.ts.map +1 -1
- package/build/utils/deepCamelCaseKeys.js +3 -1
- package/build/utils/deepCamelCaseKeys.js.map +1 -1
- package/build/utils/parse_simple_markdown.d.ts +1 -1
- package/build/utils/parse_simple_markdown.d.ts.map +1 -1
- package/build/utils/parse_simple_markdown.js +2 -1
- package/build/utils/parse_simple_markdown.js.map +1 -1
- package/build/utils/request/conversation.d.ts +1 -3
- package/build/utils/request/conversation.d.ts.map +1 -1
- package/build/utils/request/conversation.js +37 -30
- package/build/utils/request/conversation.js.map +1 -1
- package/build/utils/space.js.map +1 -1
- package/build/utils/uri.d.ts +2 -2
- package/build/utils/uri.d.ts.map +1 -1
- package/build/utils/uri.js +2 -2
- package/build/utils/uri.js.map +1 -1
- package/build/vendor/tapestry/alias_tokens_color_map.d.ts +8 -0
- package/build/vendor/tapestry/alias_tokens_color_map.d.ts.map +1 -1
- package/build/vendor/tapestry/alias_tokens_color_map.js +8 -0
- package/build/vendor/tapestry/alias_tokens_color_map.js.map +1 -1
- package/build/vendor/tapestry/tokens.d.ts +2 -0
- package/build/vendor/tapestry/tokens.d.ts.map +1 -1
- package/build/vendor/tapestry/tokens.js +2 -0
- package/build/vendor/tapestry/tokens.js.map +1 -1
- package/package.json +8 -6
- package/src/__tests__/utils/cache/page_mutations.ts +49 -15
- package/src/components/conversation/message_form.tsx +127 -58
- package/src/components/conversations/action_toggle_button.tsx +84 -0
- package/src/components/conversations/conversation_actions.tsx +146 -0
- package/src/components/conversations/conversation_preview.tsx +46 -16
- package/src/components/conversations/conversations.tsx +13 -18
- package/src/components/conversations/mute_indicator.tsx +21 -0
- package/src/components/conversations/unread_count_badge.tsx +8 -1
- package/src/components/display/action_button.tsx +4 -3
- package/src/components/display/badge.tsx +12 -8
- package/src/components/display/button.tsx +3 -3
- package/src/components/display/icon.tsx +16 -3
- package/src/components/display/icon_button.tsx +2 -2
- package/src/components/display/person.tsx +4 -3
- package/src/components/display/text.tsx +1 -1
- package/src/components/display/toggle_button.tsx +3 -3
- package/src/components/display/utils/button_colors.ts +8 -3
- package/src/components/primitive/avatar_primitive.tsx +5 -3
- package/src/components/primitive/banner_primitive.tsx +2 -3
- package/src/contexts/api_provider.tsx +1 -1
- package/src/contexts/chat_context.tsx +8 -1
- package/src/contexts/conversations_context.tsx +69 -0
- package/src/hooks/groups/use_group_members_for_new_conversation.ts +57 -0
- package/src/hooks/groups/use_groups_conversation_create.ts +50 -0
- package/src/hooks/use_conversation.ts +5 -5
- package/src/hooks/use_conversations.ts +34 -16
- package/src/hooks/use_conversations_actions.ts +108 -0
- package/src/hooks/{use_conversation_jolt_events.ts → use_conversations_cache.ts} +35 -20
- package/src/hooks/use_conversations_jolt_events.ts +21 -0
- package/src/hooks/use_giphy.ts +97 -0
- package/src/hooks/use_jolt.ts +53 -12
- package/src/hooks/use_message_create.ts +55 -0
- package/src/navigation/index.tsx +31 -8
- package/src/screens/conversation_filters/components/conversation_filters.tsx +1 -1
- package/src/screens/conversation_filters/components/rows.tsx +44 -14
- package/src/screens/conversation_filters/hooks/filters.ts +1 -1
- package/src/screens/conversation_new/components/form_list.tsx +67 -0
- package/src/screens/conversation_new/components/groups_form.tsx +153 -0
- package/src/screens/conversation_new/components/member_error_card.tsx +20 -0
- package/src/screens/conversation_new/components/source_app_error_card.tsx +24 -0
- package/src/screens/conversation_new/components/team_form.tsx +18 -0
- package/src/screens/conversation_new/conversation_new_screen.tsx +26 -0
- package/src/screens/conversation_new/utils/fake_member_data.ts +130 -0
- package/src/screens/conversation_screen.tsx +2 -1
- package/src/screens/{create → conversation_select_recipients}/conversation_select_recipients_screen.tsx +6 -5
- package/src/screens/conversations/components/chat_group_badge.tsx +1 -1
- package/src/screens/conversations/components/list_header_component.tsx +7 -2
- package/src/screens/conversations/conversations_screen.tsx +6 -19
- package/src/screens/design_system_screen.tsx +1 -0
- package/src/screens/message_actions_screen.tsx +4 -4
- package/src/screens/send_giphy_screen.tsx +155 -0
- package/src/types/resources/groups/groups_group_resource.ts +1 -1
- package/src/types/resources/groups/groups_member_resource_with_person.ts +13 -0
- package/src/types/resources/member.ts +0 -11
- package/src/utils/cache/page_mutations.ts +22 -0
- package/src/utils/client/client.ts +15 -7
- package/src/utils/client/request_helpers.ts +15 -6
- package/src/utils/client/transform_request_data.ts +13 -4
- package/src/utils/client/transform_response.ts +3 -0
- package/src/utils/client/types.d.ts +2 -1
- package/src/utils/client/utils.ts +13 -12
- package/src/utils/date.ts +1 -0
- package/src/utils/deepCamelCaseKeys.ts +3 -2
- package/src/utils/parse_simple_markdown.ts +3 -1
- package/src/utils/request/conversation.ts +39 -34
- package/src/utils/space.ts +1 -1
- package/src/utils/uri.ts +2 -2
- package/src/vendor/tapestry/alias_tokens_color_map.ts +12 -0
- package/src/vendor/tapestry/tokens.ts +2 -0
- package/build/hooks/use_conversation_jolt_events.d.ts +0 -2
- package/build/hooks/use_conversation_jolt_events.d.ts.map +0 -1
- package/build/hooks/use_conversation_jolt_events.js.map +0 -1
- package/build/screens/create/conversation_create_screen.d.ts +0 -9
- package/build/screens/create/conversation_create_screen.d.ts.map +0 -1
- package/build/screens/create/conversation_create_screen.js +0 -123
- package/build/screens/create/conversation_create_screen.js.map +0 -1
- package/build/screens/create/conversation_filter_recipients_screen.d.ts.map +0 -1
- package/build/screens/create/conversation_filter_recipients_screen.js.map +0 -1
- package/build/screens/create/conversation_select_recipients_screen.d.ts.map +0 -1
- package/build/screens/create/conversation_select_recipients_screen.js.map +0 -1
- package/src/screens/create/conversation_create_screen.tsx +0 -148
- /package/build/screens/{create → conversation_filter_recipients}/conversation_filter_recipients_screen.d.ts +0 -0
- /package/build/screens/{create → conversation_filter_recipients}/conversation_filter_recipients_screen.js +0 -0
- /package/build/screens/{create → conversation_select_recipients}/conversation_select_recipients_screen.d.ts +0 -0
- /package/src/screens/{create → conversation_filter_recipients}/conversation_filter_recipients_screen.tsx +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { ApiResource, ConversationResource } from '../types';
|
|
2
|
+
export declare const useConversationsMarkRead: ({ conversation, }: {
|
|
3
|
+
conversation: ConversationResource;
|
|
4
|
+
}) => {
|
|
5
|
+
data: undefined;
|
|
6
|
+
variables: undefined;
|
|
7
|
+
error: null;
|
|
8
|
+
isError: false;
|
|
9
|
+
isIdle: true;
|
|
10
|
+
isPending: false;
|
|
11
|
+
isSuccess: false;
|
|
12
|
+
status: "idle";
|
|
13
|
+
reset: () => void;
|
|
14
|
+
context: void | undefined;
|
|
15
|
+
failureCount: number;
|
|
16
|
+
failureReason: Error | null;
|
|
17
|
+
isPaused: boolean;
|
|
18
|
+
submittedAt: number;
|
|
19
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
20
|
+
read: boolean;
|
|
21
|
+
markRead: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
22
|
+
} | {
|
|
23
|
+
data: undefined;
|
|
24
|
+
variables: boolean;
|
|
25
|
+
error: null;
|
|
26
|
+
isError: false;
|
|
27
|
+
isIdle: false;
|
|
28
|
+
isPending: true;
|
|
29
|
+
isSuccess: false;
|
|
30
|
+
status: "pending";
|
|
31
|
+
reset: () => void;
|
|
32
|
+
context: void | undefined;
|
|
33
|
+
failureCount: number;
|
|
34
|
+
failureReason: Error | null;
|
|
35
|
+
isPaused: boolean;
|
|
36
|
+
submittedAt: number;
|
|
37
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
38
|
+
read: boolean;
|
|
39
|
+
markRead: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
40
|
+
} | {
|
|
41
|
+
data: undefined;
|
|
42
|
+
error: Error;
|
|
43
|
+
variables: boolean;
|
|
44
|
+
isError: true;
|
|
45
|
+
isIdle: false;
|
|
46
|
+
isPending: false;
|
|
47
|
+
isSuccess: false;
|
|
48
|
+
status: "error";
|
|
49
|
+
reset: () => void;
|
|
50
|
+
context: void | undefined;
|
|
51
|
+
failureCount: number;
|
|
52
|
+
failureReason: Error | null;
|
|
53
|
+
isPaused: boolean;
|
|
54
|
+
submittedAt: number;
|
|
55
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
56
|
+
read: boolean;
|
|
57
|
+
markRead: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
58
|
+
} | {
|
|
59
|
+
data: ApiResource<ConversationResource>;
|
|
60
|
+
error: null;
|
|
61
|
+
variables: boolean;
|
|
62
|
+
isError: false;
|
|
63
|
+
isIdle: false;
|
|
64
|
+
isPending: false;
|
|
65
|
+
isSuccess: true;
|
|
66
|
+
status: "success";
|
|
67
|
+
reset: () => void;
|
|
68
|
+
context: void | undefined;
|
|
69
|
+
failureCount: number;
|
|
70
|
+
failureReason: Error | null;
|
|
71
|
+
isPaused: boolean;
|
|
72
|
+
submittedAt: number;
|
|
73
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
74
|
+
read: boolean;
|
|
75
|
+
markRead: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
76
|
+
};
|
|
77
|
+
export declare const useConversationsMute: ({ conversation }: {
|
|
78
|
+
conversation: ConversationResource;
|
|
79
|
+
}) => {
|
|
80
|
+
data: undefined;
|
|
81
|
+
variables: undefined;
|
|
82
|
+
error: null;
|
|
83
|
+
isError: false;
|
|
84
|
+
isIdle: true;
|
|
85
|
+
isPending: false;
|
|
86
|
+
isSuccess: false;
|
|
87
|
+
status: "idle";
|
|
88
|
+
reset: () => void;
|
|
89
|
+
context: void | undefined;
|
|
90
|
+
failureCount: number;
|
|
91
|
+
failureReason: Error | null;
|
|
92
|
+
isPaused: boolean;
|
|
93
|
+
submittedAt: number;
|
|
94
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
95
|
+
muted: boolean;
|
|
96
|
+
setMuted: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
97
|
+
} | {
|
|
98
|
+
data: undefined;
|
|
99
|
+
variables: boolean;
|
|
100
|
+
error: null;
|
|
101
|
+
isError: false;
|
|
102
|
+
isIdle: false;
|
|
103
|
+
isPending: true;
|
|
104
|
+
isSuccess: false;
|
|
105
|
+
status: "pending";
|
|
106
|
+
reset: () => void;
|
|
107
|
+
context: void | undefined;
|
|
108
|
+
failureCount: number;
|
|
109
|
+
failureReason: Error | null;
|
|
110
|
+
isPaused: boolean;
|
|
111
|
+
submittedAt: number;
|
|
112
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
113
|
+
muted: boolean;
|
|
114
|
+
setMuted: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
115
|
+
} | {
|
|
116
|
+
data: undefined;
|
|
117
|
+
error: Error;
|
|
118
|
+
variables: boolean;
|
|
119
|
+
isError: true;
|
|
120
|
+
isIdle: false;
|
|
121
|
+
isPending: false;
|
|
122
|
+
isSuccess: false;
|
|
123
|
+
status: "error";
|
|
124
|
+
reset: () => void;
|
|
125
|
+
context: void | undefined;
|
|
126
|
+
failureCount: number;
|
|
127
|
+
failureReason: Error | null;
|
|
128
|
+
isPaused: boolean;
|
|
129
|
+
submittedAt: number;
|
|
130
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
131
|
+
muted: boolean;
|
|
132
|
+
setMuted: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
133
|
+
} | {
|
|
134
|
+
data: ApiResource<ConversationResource>;
|
|
135
|
+
error: null;
|
|
136
|
+
variables: boolean;
|
|
137
|
+
isError: false;
|
|
138
|
+
isIdle: false;
|
|
139
|
+
isPending: false;
|
|
140
|
+
isSuccess: true;
|
|
141
|
+
status: "success";
|
|
142
|
+
reset: () => void;
|
|
143
|
+
context: void | undefined;
|
|
144
|
+
failureCount: number;
|
|
145
|
+
failureReason: Error | null;
|
|
146
|
+
isPaused: boolean;
|
|
147
|
+
submittedAt: number;
|
|
148
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
149
|
+
muted: boolean;
|
|
150
|
+
setMuted: import("@tanstack/react-query").UseMutateFunction<ApiResource<ConversationResource>, Error, boolean, void>;
|
|
151
|
+
};
|
|
152
|
+
export declare const useMarkAllRead: () => {
|
|
153
|
+
data: undefined;
|
|
154
|
+
variables: undefined;
|
|
155
|
+
error: null;
|
|
156
|
+
isError: false;
|
|
157
|
+
isIdle: true;
|
|
158
|
+
isPending: false;
|
|
159
|
+
isSuccess: false;
|
|
160
|
+
status: "idle";
|
|
161
|
+
reset: () => void;
|
|
162
|
+
context: void | undefined;
|
|
163
|
+
failureCount: number;
|
|
164
|
+
failureReason: Error | null;
|
|
165
|
+
isPaused: boolean;
|
|
166
|
+
submittedAt: number;
|
|
167
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
168
|
+
markAllRead: import("@tanstack/react-query").UseMutateFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
169
|
+
} | {
|
|
170
|
+
data: undefined;
|
|
171
|
+
variables: void;
|
|
172
|
+
error: null;
|
|
173
|
+
isError: false;
|
|
174
|
+
isIdle: false;
|
|
175
|
+
isPending: true;
|
|
176
|
+
isSuccess: false;
|
|
177
|
+
status: "pending";
|
|
178
|
+
reset: () => void;
|
|
179
|
+
context: void | undefined;
|
|
180
|
+
failureCount: number;
|
|
181
|
+
failureReason: Error | null;
|
|
182
|
+
isPaused: boolean;
|
|
183
|
+
submittedAt: number;
|
|
184
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
185
|
+
markAllRead: import("@tanstack/react-query").UseMutateFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
186
|
+
} | {
|
|
187
|
+
data: undefined;
|
|
188
|
+
error: Error;
|
|
189
|
+
variables: void;
|
|
190
|
+
isError: true;
|
|
191
|
+
isIdle: false;
|
|
192
|
+
isPending: false;
|
|
193
|
+
isSuccess: false;
|
|
194
|
+
status: "error";
|
|
195
|
+
reset: () => void;
|
|
196
|
+
context: void | undefined;
|
|
197
|
+
failureCount: number;
|
|
198
|
+
failureReason: Error | null;
|
|
199
|
+
isPaused: boolean;
|
|
200
|
+
submittedAt: number;
|
|
201
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
202
|
+
markAllRead: import("@tanstack/react-query").UseMutateFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
203
|
+
} | {
|
|
204
|
+
data: import("../types").ApiCollection | ApiResource;
|
|
205
|
+
error: null;
|
|
206
|
+
variables: void;
|
|
207
|
+
isError: false;
|
|
208
|
+
isIdle: false;
|
|
209
|
+
isPending: false;
|
|
210
|
+
isSuccess: true;
|
|
211
|
+
status: "success";
|
|
212
|
+
reset: () => void;
|
|
213
|
+
context: void | undefined;
|
|
214
|
+
failureCount: number;
|
|
215
|
+
failureReason: Error | null;
|
|
216
|
+
isPaused: boolean;
|
|
217
|
+
submittedAt: number;
|
|
218
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
219
|
+
markAllRead: import("@tanstack/react-query").UseMutateFunction<import("../types").ApiCollection | ApiResource, Error, void, void>;
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=use_conversations_actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_conversations_actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversations_actions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAI5D,eAAO,MAAM,wBAAwB,sBAElC;IACD,YAAY,EAAE,oBAAoB,CAAA;CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCA,CAAA;AAED,eAAO,MAAM,oBAAoB,qBAAsB;IAAE,YAAY,EAAE,oBAAoB,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmC5F,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsB1B,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { Alert } from 'react-native';
|
|
3
|
+
import { useConversationsContext } from '../contexts/conversations_context';
|
|
4
|
+
import { useApiClient } from './use_api_client';
|
|
5
|
+
import { useConversationsCache } from './use_conversations_cache';
|
|
6
|
+
export const useConversationsMarkRead = ({ conversation, }) => {
|
|
7
|
+
const apiClient = useApiClient();
|
|
8
|
+
const { args } = useConversationsContext();
|
|
9
|
+
const { update, invalidate } = useConversationsCache(args);
|
|
10
|
+
const { mutate: handleMarkRead, ...mutation } = useMutation({
|
|
11
|
+
onMutate: async (read) => {
|
|
12
|
+
update({
|
|
13
|
+
...conversation,
|
|
14
|
+
unreadCount: read ? 0 : 1,
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
mutationKey: ['markRead', conversation.id],
|
|
18
|
+
mutationFn: async (read) => {
|
|
19
|
+
const action = read ? 'mark_read' : 'mark_unread';
|
|
20
|
+
return apiClient.chat.post({
|
|
21
|
+
url: `/me/conversations/${conversation.id}/${action}`,
|
|
22
|
+
data: { data: { type: '', attributes: {} }, fields: { Conversation: 'unread_count' } },
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (response) => {
|
|
26
|
+
update(response.data);
|
|
27
|
+
},
|
|
28
|
+
onError: () => {
|
|
29
|
+
Alert.alert('Oops', 'Something went wrong updating this conversation, please try again');
|
|
30
|
+
invalidate();
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
read: conversation.unreadCount < 1, // prefer cache
|
|
35
|
+
markRead: handleMarkRead,
|
|
36
|
+
...mutation,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export const useConversationsMute = ({ conversation }) => {
|
|
40
|
+
const apiClient = useApiClient();
|
|
41
|
+
const { args } = useConversationsContext();
|
|
42
|
+
const { update, invalidate } = useConversationsCache(args);
|
|
43
|
+
const { mutate: setMuted, ...mutation } = useMutation({
|
|
44
|
+
onMutate: async (muted) => {
|
|
45
|
+
update({
|
|
46
|
+
...conversation,
|
|
47
|
+
muted,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
mutationKey: ['muteConversation'],
|
|
51
|
+
mutationFn: async (muted) => {
|
|
52
|
+
const action = muted ? 'mute' : 'unmute';
|
|
53
|
+
return apiClient.chat.post({
|
|
54
|
+
url: `/me/conversations/${conversation.id}/${action}`,
|
|
55
|
+
data: { data: { type: '', attributes: {} }, fields: { Conversation: 'muted' } },
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
onSuccess: (response) => {
|
|
59
|
+
update(response.data);
|
|
60
|
+
},
|
|
61
|
+
onError: () => {
|
|
62
|
+
Alert.alert('Oops', 'Something went wrong muting this conversation, please try again');
|
|
63
|
+
invalidate();
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
muted: conversation.muted, // prefer cache
|
|
68
|
+
setMuted,
|
|
69
|
+
...mutation,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export const useMarkAllRead = () => {
|
|
73
|
+
const apiClient = useApiClient();
|
|
74
|
+
const { args } = useConversationsContext();
|
|
75
|
+
const { invalidate, updateAll } = useConversationsCache(args);
|
|
76
|
+
const { mutate: markAllRead, ...query } = useMutation({
|
|
77
|
+
onMutate: () => {
|
|
78
|
+
updateAll({
|
|
79
|
+
unreadCount: 0,
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
mutationKey: ['markAllRead', args],
|
|
83
|
+
mutationFn: () => apiClient.chat.post({
|
|
84
|
+
url: '/me/mark_all_read',
|
|
85
|
+
}),
|
|
86
|
+
onSettled: invalidate,
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
markAllRead,
|
|
90
|
+
...query,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=use_conversations_actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_conversations_actions.js","sourceRoot":"","sources":["../../src/hooks/use_conversations_actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAEjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,YAAY,GAGb,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;IAE1D,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAE,GAAG,WAAW,CAAC;QAC1D,QAAQ,EAAE,KAAK,EAAE,IAAa,EAAE,EA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AAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;IAC7D,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,GAAG,WAAW,CAAC;QACpD,QAAQ,EAAE,GAAG,EAAE;YACb,SAAS,CAAC;gBACR,WAAW,EAAE,CAAC;aACf,CAAC,CAAA;QACJ,CAAC;QACD,WAAW,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC;QAClC,UAAU,EAAE,GAAG,EAAE,CACf,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;YAClB,GAAG,EAAE,mBAAmB;SACzB,CAAC;QACJ,SAAS,EAAE,UAAU;KACtB,CAAC,CAAA;IAEF,OAAO;QACL,WAAW;QACX,GAAG,KAAK;KACT,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { useMutation } from '@tanstack/react-query'\nimport { Alert } from 'react-native'\nimport { useConversationsContext } from '../contexts/conversations_context'\nimport { ApiResource, ConversationResource } from '../types'\nimport { useApiClient } from './use_api_client'\nimport { useConversationsCache } from './use_conversations_cache'\n\nexport const useConversationsMarkRead = ({\n conversation,\n}: {\n conversation: ConversationResource\n}) => {\n const apiClient = useApiClient()\n const { args } = useConversationsContext()\n const { update, invalidate } = useConversationsCache(args)\n\n const { mutate: handleMarkRead, ...mutation } = useMutation({\n onMutate: async (read: boolean) => {\n update({\n ...conversation,\n unreadCount: read ? 0 : 1,\n })\n },\n mutationKey: ['markRead', conversation.id],\n mutationFn: async (read: boolean) => {\n const action = read ? 'mark_read' : 'mark_unread'\n\n return apiClient.chat.post<ApiResource<ConversationResource>>({\n url: `/me/conversations/${conversation.id}/${action}`,\n data: { data: { type: '', attributes: {} }, fields: { Conversation: 'unread_count' } },\n })\n },\n onSuccess: (response: ApiResource<ConversationResource>) => {\n update(response.data)\n },\n onError: () => {\n Alert.alert('Oops', 'Something went wrong updating this conversation, please try again')\n invalidate()\n },\n })\n\n return {\n read: conversation.unreadCount < 1, // prefer cache\n markRead: handleMarkRead,\n ...mutation,\n }\n}\n\nexport const useConversationsMute = ({ conversation }: { conversation: ConversationResource }) => {\n const apiClient = useApiClient()\n const { args } = useConversationsContext()\n const { update, invalidate } = useConversationsCache(args)\n\n const { mutate: setMuted, ...mutation } = useMutation({\n onMutate: async (muted: boolean) => {\n update({\n ...conversation,\n muted,\n })\n },\n mutationKey: ['muteConversation'],\n mutationFn: async (muted: boolean) => {\n const action = muted ? 'mute' : 'unmute'\n\n return apiClient.chat.post<ApiResource<ConversationResource>>({\n url: `/me/conversations/${conversation.id}/${action}`,\n data: { data: { type: '', attributes: {} }, fields: { Conversation: 'muted' } },\n })\n },\n onSuccess: (response: ApiResource<ConversationResource>) => {\n update(response.data)\n },\n onError: () => {\n Alert.alert('Oops', 'Something went wrong muting this conversation, please try again')\n invalidate()\n },\n })\n\n return {\n muted: conversation.muted, // prefer cache\n setMuted,\n ...mutation,\n }\n}\n\nexport const useMarkAllRead = () => {\n const apiClient = useApiClient()\n const { args } = useConversationsContext()\n const { invalidate, updateAll } = useConversationsCache(args)\n const { mutate: markAllRead, ...query } = useMutation({\n onMutate: () => {\n updateAll({\n unreadCount: 0,\n })\n },\n mutationKey: ['markAllRead', args],\n mutationFn: () =>\n apiClient.chat.post({\n url: '/me/mark_all_read',\n }),\n onSettled: invalidate,\n })\n\n return {\n markAllRead,\n ...query,\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConversationResource } from '../types';
|
|
2
|
+
import { ConversationRequestArgs } from '../utils/request/conversation';
|
|
3
|
+
export declare function useConversationsCache(args?: Partial<ConversationRequestArgs>): {
|
|
4
|
+
create: (conversation: ConversationResource) => Promise<void>;
|
|
5
|
+
destroy: ({ id }: {
|
|
6
|
+
id: number;
|
|
7
|
+
}) => void;
|
|
8
|
+
fetchCreate: ({ id }: {
|
|
9
|
+
id: number;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
fetchUpdate: ({ id }: {
|
|
12
|
+
id: number;
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
invalidate: () => Promise<void>;
|
|
15
|
+
update: (conversation: ConversationResource) => Promise<void>;
|
|
16
|
+
updateAll: (update: Partial<ConversationResource>) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=use_conversations_cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_conversations_cache.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversations_cache.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAM3E,OAAO,EAAE,uBAAuB,EAA+B,MAAM,+BAA+B,CAAA;AAMpG,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC;2BAmB/B,oBAAoB;sBA2BrB;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;0BANX;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;0BAAd;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;;2BArBhB,oBAAoB;wBAY/B,OAAO,CAAC,oBAAoB,CAAC;EAiC/D"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { deleteRecordInPagesData, updateOrCreateRecordInPagesData } from '../utils';
|
|
2
|
+
import { deleteRecordInPagesData, updateAllRecordsInPagesData, updateOrCreateRecordInPagesData, } from '../utils';
|
|
3
|
+
import { getConversationsRequestArgs } from '../utils/request/conversation';
|
|
3
4
|
import { useApiClient } from './use_api_client';
|
|
4
|
-
import { useCurrentPerson } from './use_current_person';
|
|
5
|
-
import { useJoltChannel, useJoltEvent } from './use_jolt';
|
|
6
5
|
import { getRequestQueryKey } from './use_suspense_api';
|
|
7
|
-
|
|
8
|
-
export function useConversationsJoltEvents() {
|
|
6
|
+
export function useConversationsCache(args) {
|
|
9
7
|
const apiClient = useApiClient();
|
|
10
8
|
const queryClient = useQueryClient();
|
|
11
|
-
const
|
|
12
|
-
const joltChannel = useJoltChannel(`chat.people.${currentPerson.id}`);
|
|
13
|
-
const conversationsRequestArgs = getConversationsRequestArgs();
|
|
9
|
+
const conversationsRequestArgs = getConversationsRequestArgs(args);
|
|
14
10
|
const conversationQueryKey = getRequestQueryKey(conversationsRequestArgs);
|
|
15
11
|
const fetchConversation = async (id) => {
|
|
16
12
|
const { data: argsData } = conversationsRequestArgs;
|
|
@@ -23,9 +19,7 @@ export function useConversationsJoltEvents() {
|
|
|
23
19
|
});
|
|
24
20
|
return data;
|
|
25
21
|
};
|
|
26
|
-
const
|
|
27
|
-
const { data } = e.data;
|
|
28
|
-
const conversation = await fetchConversation(data.id).catch(c => c);
|
|
22
|
+
const updateOrCreate = async (conversation) => {
|
|
29
23
|
queryClient.setQueryData(conversationQueryKey, prev => updateOrCreateRecordInPagesData({
|
|
30
24
|
data: prev,
|
|
31
25
|
record: conversation,
|
|
@@ -34,14 +28,30 @@ export function useConversationsJoltEvents() {
|
|
|
34
28
|
},
|
|
35
29
|
}));
|
|
36
30
|
};
|
|
37
|
-
const
|
|
31
|
+
const updateAll = async (update) => {
|
|
32
|
+
queryClient.setQueryData(conversationQueryKey, prev => updateAllRecordsInPagesData({
|
|
33
|
+
data: prev,
|
|
34
|
+
processRecord: record => ({ ...record, ...update }),
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
const fetchAndUpdateOrCreate = async ({ id }) => {
|
|
38
|
+
const conversation = await fetchConversation(id).catch(c => c);
|
|
39
|
+
updateOrCreate(conversation);
|
|
40
|
+
};
|
|
41
|
+
const handleConversationDestroy = ({ id }) => {
|
|
38
42
|
queryClient.setQueryData(conversationQueryKey, prev => deleteRecordInPagesData({
|
|
39
43
|
data: prev,
|
|
40
|
-
record: { id
|
|
44
|
+
record: { id },
|
|
41
45
|
}));
|
|
42
46
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
return {
|
|
48
|
+
create: updateOrCreate,
|
|
49
|
+
destroy: handleConversationDestroy,
|
|
50
|
+
fetchCreate: fetchAndUpdateOrCreate,
|
|
51
|
+
fetchUpdate: fetchAndUpdateOrCreate,
|
|
52
|
+
invalidate: () => queryClient.invalidateQueries({ queryKey: conversationQueryKey }),
|
|
53
|
+
update: updateOrCreate,
|
|
54
|
+
updateAll,
|
|
55
|
+
};
|
|
46
56
|
}
|
|
47
|
-
//# sourceMappingURL=
|
|
57
|
+
//# sourceMappingURL=use_conversations_cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_conversations_cache.js","sourceRoot":"","sources":["../../src/hooks/use_conversations_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,+BAA+B,GAChC,MAAM,UAAU,CAAA;AACjB,OAAO,EAA2B,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AACpG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAIvD,MAAM,UAAU,qBAAqB,CAAC,IAAuC;IAC3E,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,wBAAwB,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAA;IAClE,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,wBAAwB,CAAC,CAAA;IAEzE,MAAM,iBAAiB,GAAG,KAAK,EAAE,EAAU,EAAE,EAAE;QAC7C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,wBAAwB,CAAA;QACnD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,CAAoC;YAC3E,GAAG,EAAE,qBAAqB,EAAE,EAAE;YAC9B,IAAI,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EAAE,EAAE,EAAE;SACf,CAAC,CACH,CAAA;IACH,CAAC,CAAA;IAED,OAAO;QACL,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,yBAAyB;QAClC,WAAW,EAAE,sBAAsB;QACnC,WAAW,EAAE,sBAAsB;QACnC,UAAU,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC;QACnF,MAAM,EAAE,cAAc;QACtB,SAAS;KACV,CAAA;AACH,CAAC","sourcesContent":["import { InfiniteData, useQueryClient } from '@tanstack/react-query'\nimport { ApiCollection, ApiResource, ConversationResource } from '../types'\nimport {\n deleteRecordInPagesData,\n updateAllRecordsInPagesData,\n updateOrCreateRecordInPagesData,\n} from '../utils'\nimport { ConversationRequestArgs, getConversationsRequestArgs } from '../utils/request/conversation'\nimport { useApiClient } from './use_api_client'\nimport { getRequestQueryKey } from './use_suspense_api'\n\ntype QueryData = InfiniteData<ApiCollection<ConversationResource>>\n\nexport function useConversationsCache(args?: Partial<ConversationRequestArgs>) {\n const apiClient = useApiClient()\n const queryClient = useQueryClient()\n const conversationsRequestArgs = getConversationsRequestArgs(args)\n const conversationQueryKey = getRequestQueryKey(conversationsRequestArgs)\n\n const fetchConversation = async (id: number) => {\n const { data: argsData } = conversationsRequestArgs\n const { data } = await apiClient.chat.get<ApiResource<ConversationResource>>({\n url: `/me/conversations/${id}`,\n data: {\n fields: argsData.fields,\n include: argsData.include,\n },\n })\n\n return data\n }\n\n const updateOrCreate = async (conversation: ConversationResource) => {\n queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>\n updateOrCreateRecordInPagesData({\n data: prev,\n record: conversation,\n processRecord: (record, current) => {\n return { ...current, ...record }\n },\n })\n )\n }\n\n const updateAll = async (update: Partial<ConversationResource>) => {\n queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>\n updateAllRecordsInPagesData({\n data: prev,\n processRecord: record => ({ ...record, ...update }),\n })\n )\n }\n\n const fetchAndUpdateOrCreate = async ({ id }: { id: number }) => {\n const conversation: ConversationResource = await fetchConversation(id).catch(c => c)\n\n updateOrCreate(conversation)\n }\n\n const handleConversationDestroy = ({ id }: { id: number }) => {\n queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>\n deleteRecordInPagesData({\n data: prev,\n record: { id },\n })\n )\n }\n\n return {\n create: updateOrCreate,\n destroy: handleConversationDestroy,\n fetchCreate: fetchAndUpdateOrCreate,\n fetchUpdate: fetchAndUpdateOrCreate,\n invalidate: () => queryClient.invalidateQueries({ queryKey: conversationQueryKey }),\n update: updateOrCreate,\n updateAll,\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_conversations_jolt_events.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversations_jolt_events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAKvE,wBAAgB,0BAA0B,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,QAcjF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useConversationsCache } from './use_conversations_cache';
|
|
2
|
+
import { useCurrentPerson } from './use_current_person';
|
|
3
|
+
import { useJoltChannel, useJoltEvent } from './use_jolt';
|
|
4
|
+
export function useConversationsJoltEvents(args) {
|
|
5
|
+
const currentPerson = useCurrentPerson();
|
|
6
|
+
const joltChannel = useJoltChannel(`chat.people.${currentPerson.id}`);
|
|
7
|
+
const cache = useConversationsCache(args);
|
|
8
|
+
useJoltEvent(joltChannel, 'conversation.updated', (e) => cache.fetchUpdate({ id: e.data.data.id }));
|
|
9
|
+
useJoltEvent(joltChannel, 'conversation.created', (e) => cache.fetchCreate({ id: e.data.data.id }));
|
|
10
|
+
useJoltEvent(joltChannel, 'conversation.destroyed', (e) => cache.destroy({ id: e.data.data.id }));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=use_conversations_jolt_events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_conversations_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversations_jolt_events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,UAAU,0BAA0B,CAAC,IAAuC;IAChF,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,WAAW,GAAG,cAAc,CAAC,eAAe,aAAa,CAAC,EAAE,EAAE,CAAC,CAAA;IACrE,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;IAEzC,YAAY,CAAC,WAAW,EAAE,sBAAsB,EAAE,CAAC,CAAwB,EAAE,EAAE,CAC7E,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAC1C,CAAA;IACD,YAAY,CAAC,WAAW,EAAE,sBAAsB,EAAE,CAAC,CAAwB,EAAE,EAAE,CAC7E,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAC1C,CAAA;IACD,YAAY,CAAC,WAAW,EAAE,wBAAwB,EAAE,CAAC,CAAwB,EAAE,EAAE,CAC/E,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CACtC,CAAA;AACH,CAAC","sourcesContent":["import { JoltConversationEvent } from '../types/jolt_events'\nimport { ConversationRequestArgs } from '../utils/request/conversation'\nimport { useConversationsCache } from './use_conversations_cache'\nimport { useCurrentPerson } from './use_current_person'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\n\nexport function useConversationsJoltEvents(args?: Partial<ConversationRequestArgs>) {\n const currentPerson = useCurrentPerson()\n const joltChannel = useJoltChannel(`chat.people.${currentPerson.id}`)\n const cache = useConversationsCache(args)\n\n useJoltEvent(joltChannel, 'conversation.updated', (e: JoltConversationEvent) =>\n cache.fetchUpdate({ id: e.data.data.id })\n )\n useJoltEvent(joltChannel, 'conversation.created', (e: JoltConversationEvent) =>\n cache.fetchCreate({ id: e.data.data.id })\n )\n useJoltEvent(joltChannel, 'conversation.destroyed', (e: JoltConversationEvent) =>\n cache.destroy({ id: e.data.data.id })\n )\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_create_android_ripple_color.d.ts","sourceRoot":"","sources":["../../src/hooks/use_create_android_ripple_color.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B,cAAe;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"use_create_android_ripple_color.d.ts","sourceRoot":"","sources":["../../src/hooks/use_create_android_ripple_color.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B,cAAe;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,WAavE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DenormalizedGiphyAttachmentResourceForCreate } from '../types/resources/denormalized_attachment_resource';
|
|
2
|
+
export declare function useGiphy(term?: string): {
|
|
3
|
+
isSearching: boolean;
|
|
4
|
+
result: DenormalizedGiphyAttachmentResourceForCreate;
|
|
5
|
+
resultIndex: number;
|
|
6
|
+
nextResult: () => void;
|
|
7
|
+
prevResult: () => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=use_giphy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_giphy.d.ts","sourceRoot":"","sources":["../../src/hooks/use_giphy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4CAA4C,EAAE,MAAM,qDAAqD,CAAA;AA0BlH,wBAAgB,QAAQ,CAAC,IAAI,GAAE,MAAW;;;;;;EA8CzC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { ChatContext } from '../contexts/chat_context';
|
|
3
|
+
export function useGiphy(term = '') {
|
|
4
|
+
const { giphyApiKey } = useContext(ChatContext);
|
|
5
|
+
const [isSearching, setIsSearching] = useState(false);
|
|
6
|
+
const [results, setResults] = useState([]);
|
|
7
|
+
const [resultIndex, setResultIndex] = useState(0);
|
|
8
|
+
const result = results[resultIndex];
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!giphyApiKey || !term) {
|
|
11
|
+
setResults([]);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
setIsSearching(true);
|
|
15
|
+
fetch(`https://api.giphy.com/v1/gifs/search?api_key=${giphyApiKey}&q=${term}&limit=20&rating=g`)
|
|
16
|
+
.then(response => response.json())
|
|
17
|
+
.then(data => {
|
|
18
|
+
const originalGiphys = data.data;
|
|
19
|
+
const denormalizedGiphys = denormalizeGiphys(term, originalGiphys);
|
|
20
|
+
setResults(denormalizedGiphys);
|
|
21
|
+
setResultIndex(0);
|
|
22
|
+
})
|
|
23
|
+
.catch(error => {
|
|
24
|
+
console.error('Error fetching gifs:', error);
|
|
25
|
+
})
|
|
26
|
+
.finally(() => {
|
|
27
|
+
setIsSearching(false);
|
|
28
|
+
});
|
|
29
|
+
}, [giphyApiKey, term]);
|
|
30
|
+
const nextResult = useCallback(() => {
|
|
31
|
+
setResultIndex(oldResultIndex => (oldResultIndex < results.length - 1 ? oldResultIndex + 1 : 0));
|
|
32
|
+
}, [results.length]);
|
|
33
|
+
const prevResult = useCallback(() => {
|
|
34
|
+
setResultIndex(oldResultIndex => (oldResultIndex > 0 ? oldResultIndex - 1 : results.length - 1));
|
|
35
|
+
}, [results.length]);
|
|
36
|
+
return {
|
|
37
|
+
isSearching,
|
|
38
|
+
result,
|
|
39
|
+
resultIndex,
|
|
40
|
+
nextResult,
|
|
41
|
+
prevResult,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function denormalizeGiphys(term, giphys) {
|
|
45
|
+
return giphys.map(giphy => ({
|
|
46
|
+
type: 'giphy',
|
|
47
|
+
id: giphy.id,
|
|
48
|
+
title: term,
|
|
49
|
+
original_giphy_title: giphy.title,
|
|
50
|
+
title_link: giphy.url,
|
|
51
|
+
thumb_url: giphy.images.fixed_width.url,
|
|
52
|
+
giphy: {
|
|
53
|
+
original: giphy.images.original,
|
|
54
|
+
fixed_height: giphy.images.fixed_height,
|
|
55
|
+
fixed_height_still: giphy.images.fixed_height_still,
|
|
56
|
+
fixed_height_downsampled: giphy.images.fixed_height_downsampled,
|
|
57
|
+
fixed_width: giphy.images.fixed_width,
|
|
58
|
+
fixed_width_still: giphy.images.fixed_width_still,
|
|
59
|
+
fixed_width_downsampled: giphy.images.fixed_width_downsampled,
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=use_giphy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_giphy.js","sourceRoot":"","sources":["../../src/hooks/use_giphy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAyBtD,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE;IACxC,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAA;IAC/C,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACrD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAiD,EAAE,CAAC,CAAA;IAC1F,MAAM,CAAC,WAAW,EAA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G,WAAW,CAAC,GAAG,EAAE;QAClC,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;IAClG,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;IAEpB,OAAO;QACL,WAAW;QACX,MAAM;QACN,WAAW;QACX,UAAU;QACV,UAAU;KACX,CAAA;AACH,CAAC;AAED,SAAS,iBAAiB,CACxB,IAAY,EACZ,MAAkB;IAElB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,OAAO;QACb,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,KAAK,EAAE,IAAI;QACX,oBAAoB,EAAE,KAAK,CAAC,KAAK;QACjC,UAAU,EAAE,KAAK,CAAC,GAAG;QACrB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG;QACvC,KAAK,EAAE;YACL,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;YAC/B,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,YAAY;YACvC,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,kBAAkB;YACnD,wBAAwB,EAAE,KAAK,CAAC,MAAM,CAAC,wBAAwB;YAC/D,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW;YACrC,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAAC,iBAAiB;YACjD,uBAAuB,EAAE,KAAK,CAAC,MAAM,CAAC,uBAAuB;SAC9D;KACF,CAAC,CAAC,CAAA;AACL,CAAC","sourcesContent":["import { useCallback, useContext, useEffect, useState } from 'react'\nimport { DenormalizedGiphyAttachmentResourceForCreate } from '../types/resources/denormalized_attachment_resource'\nimport { ChatContext } from '../contexts/chat_context'\n\ninterface GiphyGif {\n id: string\n url: string\n title: string\n images: {\n original: GiphyVariant\n fixed_height: GiphyVariant\n fixed_height_still: GiphyVariant\n fixed_height_downsampled: GiphyVariant\n fixed_width: GiphyVariant\n fixed_width_still: GiphyVariant\n fixed_width_downsampled: GiphyVariant\n }\n}\n\ninterface GiphyVariant {\n url: string\n width: number\n height: number\n size: string\n frames: string\n}\n\nexport function useGiphy(term: string = '') {\n const { giphyApiKey } = useContext(ChatContext)\n const [isSearching, setIsSearching] = useState(false)\n const [results, setResults] = useState<DenormalizedGiphyAttachmentResourceForCreate[]>([])\n const [resultIndex, setResultIndex] = useState(0)\n const result = results[resultIndex]\n\n useEffect(() => {\n if (!giphyApiKey || !term) {\n setResults([])\n return\n }\n\n setIsSearching(true)\n fetch(`https://api.giphy.com/v1/gifs/search?api_key=${giphyApiKey}&q=${term}&limit=20&rating=g`)\n .then(response => response.json())\n .then(data => {\n const originalGiphys: GiphyGif[] = data.data\n const denormalizedGiphys = denormalizeGiphys(term, originalGiphys)\n\n setResults(denormalizedGiphys)\n setResultIndex(0)\n })\n .catch(error => {\n console.error('Error fetching gifs:', error)\n })\n .finally(() => {\n setIsSearching(false)\n })\n }, [giphyApiKey, term])\n\n const nextResult = useCallback(() => {\n setResultIndex(oldResultIndex => (oldResultIndex < results.length - 1 ? oldResultIndex + 1 : 0))\n }, [results.length])\n\n const prevResult = useCallback(() => {\n setResultIndex(oldResultIndex => (oldResultIndex > 0 ? oldResultIndex - 1 : results.length - 1))\n }, [results.length])\n\n return {\n isSearching,\n result,\n resultIndex,\n nextResult,\n prevResult,\n }\n}\n\nfunction denormalizeGiphys(\n term: string,\n giphys: GiphyGif[]\n): DenormalizedGiphyAttachmentResourceForCreate[] {\n return giphys.map(giphy => ({\n type: 'giphy',\n id: giphy.id,\n title: term,\n original_giphy_title: giphy.title,\n title_link: giphy.url,\n thumb_url: giphy.images.fixed_width.url,\n giphy: {\n original: giphy.images.original,\n fixed_height: giphy.images.fixed_height,\n fixed_height_still: giphy.images.fixed_height_still,\n fixed_height_downsampled: giphy.images.fixed_height_downsampled,\n fixed_width: giphy.images.fixed_width,\n fixed_width_still: giphy.images.fixed_width_still,\n fixed_width_downsampled: giphy.images.fixed_width_downsampled,\n },\n }))\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_jolt.d.ts","sourceRoot":"","sources":["../../src/hooks/use_jolt.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAA;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"use_jolt.d.ts","sourceRoot":"","sources":["../../src/hooks/use_jolt.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAA;AACpD,OAAO,EACL,aAAa,EAEd,MAAM,uDAAuD,CAAA;AAC9D,OAAO,EAEL,gBAAgB,EACjB,MAAM,yDAAyD,CAAA;AAahE,eAAO,MAAM,aAAa,QAAO,UAAU,GAAG,SA0F7C,CAAA;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,gCAUjD;AAED,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAA;AAE5C,wBAAgB,YAAY,CAAC,CAAC,SAAS,aAAa,EAClD,OAAO,EAAE,gBAAgB,GAAG,SAAS,EACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,QAO5B"}
|
package/build/hooks/use_jolt.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import JoltClient from '@planningcenter/jolt-client';
|
|
2
|
-
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
import {
|
|
2
|
+
import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { useChatContext } from '../contexts/chat_context';
|
|
5
|
+
import { Client } from '../utils';
|
|
5
6
|
export const useJoltClient = () => {
|
|
6
|
-
const
|
|
7
|
+
const { session } = useChatContext();
|
|
8
|
+
const queryClient = useQueryClient();
|
|
9
|
+
const apiClient = useMemo(
|
|
10
|
+
// Client that does not relay 401 errors
|
|
11
|
+
() => new Client({ app: 'chat', session, version: '2018-11-01' }), [session]);
|
|
7
12
|
const { data: joltToken } = useSuspenseQuery({
|
|
8
13
|
queryKey: ['jolt-token'],
|
|
9
14
|
queryFn: () => {
|
|
10
|
-
return apiClient.
|
|
15
|
+
return apiClient.post({
|
|
11
16
|
url: '/me/jolt_authorize',
|
|
12
17
|
data: {
|
|
13
18
|
data: {
|
|
@@ -18,11 +23,25 @@ export const useJoltClient = () => {
|
|
|
18
23
|
});
|
|
19
24
|
},
|
|
20
25
|
});
|
|
21
|
-
const
|
|
22
|
-
return
|
|
26
|
+
const fetchJoltToken = async () => {
|
|
27
|
+
return apiClient.post({
|
|
28
|
+
url: '/me/jolt_authorize',
|
|
29
|
+
data: {
|
|
30
|
+
data: {
|
|
31
|
+
type: 'JoltToken',
|
|
32
|
+
attributes: {},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const fetchAuthTokenFn = () => {
|
|
38
|
+
return queryClient.fetchQuery({
|
|
39
|
+
queryKey: ['jolt-token'],
|
|
40
|
+
queryFn: () => fetchJoltToken().then(res => res.data.id),
|
|
41
|
+
});
|
|
23
42
|
};
|
|
24
|
-
const
|
|
25
|
-
return apiClient
|
|
43
|
+
const fetchSubscribeToken = (channel, connectionId) => {
|
|
44
|
+
return apiClient
|
|
26
45
|
.post({
|
|
27
46
|
url: '/me/jolt_subscribe',
|
|
28
47
|
data: {
|
|
@@ -32,7 +51,17 @@ export const useJoltClient = () => {
|
|
|
32
51
|
},
|
|
33
52
|
},
|
|
34
53
|
})
|
|
35
|
-
.then(
|
|
54
|
+
.then(res => res.data.id)
|
|
55
|
+
.catch((res) => {
|
|
56
|
+
console.error('failed to subscribe to Jolt channel', res);
|
|
57
|
+
return '';
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const fetchSubscribeTokenFn = (channel, connectionId, options) => {
|
|
61
|
+
return queryClient.fetchQuery({
|
|
62
|
+
queryKey: ['jolt-subscribe-token', channel, connectionId],
|
|
63
|
+
queryFn: () => fetchSubscribeToken(channel, connectionId, options),
|
|
64
|
+
});
|
|
36
65
|
};
|
|
37
66
|
const { data: joltClient } = useQuery({
|
|
38
67
|
enabled: Boolean(joltToken),
|