@planningcenter/chat-react-native 3.4.1-rc.8 → 3.4.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/build/components/conversation/attachments/audio_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/audio_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/audio_attachment.js +14 -11
- package/build/components/conversation/attachments/audio_attachment.js.map +1 -1
- package/build/components/conversation/attachments/expanded_link.d.ts +4 -2
- package/build/components/conversation/attachments/expanded_link.d.ts.map +1 -1
- package/build/components/conversation/attachments/expanded_link.js +5 -4
- package/build/components/conversation/attachments/expanded_link.js.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.js +5 -4
- package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.js +2 -2
- package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
- package/build/components/conversation/attachments/image_attachment.d.ts +4 -2
- package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +5 -4
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/conversation/attachments/video_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/video_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/video_attachment.js +5 -4
- package/build/components/conversation/attachments/video_attachment.js.map +1 -1
- package/build/components/conversation/message.d.ts.map +1 -1
- package/build/components/conversation/message.js +6 -1
- package/build/components/conversation/message.js.map +1 -1
- package/build/components/conversation/message_attachments.d.ts +1 -0
- package/build/components/conversation/message_attachments.d.ts.map +1 -1
- package/build/components/conversation/message_attachments.js +9 -9
- package/build/components/conversation/message_attachments.js.map +1 -1
- package/build/components/page/error_boundary.d.ts.map +1 -1
- package/build/components/page/error_boundary.js +4 -3
- package/build/components/page/error_boundary.js.map +1 -1
- package/build/components/primitive/actions_form_sheet.d.ts +34 -0
- package/build/components/primitive/actions_form_sheet.d.ts.map +1 -0
- package/build/components/primitive/actions_form_sheet.js +91 -0
- package/build/components/primitive/actions_form_sheet.js.map +1 -0
- package/build/contexts/chat_context.d.ts +7 -6
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +2 -2
- package/build/contexts/chat_context.js.map +1 -1
- package/build/hooks/use_conversation.d.ts +4 -4
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +0 -4
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_jolt.d.ts.map +1 -1
- package/build/hooks/use_jolt.js +33 -19
- package/build/hooks/use_jolt.js.map +1 -1
- package/build/hooks/use_suspense_api.d.ts +6 -5
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +16 -3
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/index.d.ts +6 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -4
- package/build/index.js.map +1 -1
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +6 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts +9 -0
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -0
- package/build/screens/attachment_actions/attachment_actions_screen.js +39 -0
- package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -0
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +2 -0
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/types/api_primitives.d.ts +1 -1
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/native_adapters/configuration.d.ts +8 -5
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +7 -5
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/log.d.ts +15 -0
- package/build/utils/native_adapters/log.d.ts.map +1 -0
- package/build/utils/native_adapters/log.js +21 -0
- package/build/utils/native_adapters/log.js.map +1 -0
- package/build/utils/navigation_constants.d.ts +2 -0
- package/build/utils/navigation_constants.d.ts.map +1 -0
- package/build/utils/navigation_constants.js +11 -0
- package/build/utils/navigation_constants.js.map +1 -0
- package/build/utils/response_error.d.ts +9 -0
- package/build/utils/response_error.d.ts.map +1 -0
- package/build/utils/response_error.js +15 -0
- package/build/utils/response_error.js.map +1 -0
- package/package.json +2 -2
- package/src/components/conversation/attachments/audio_attachment.tsx +25 -17
- package/src/components/conversation/attachments/expanded_link.tsx +17 -4
- package/src/components/conversation/attachments/generic_file_attachment.tsx +9 -3
- package/src/components/conversation/attachments/giphy_attachment.tsx +8 -1
- package/src/components/conversation/attachments/image_attachment.tsx +12 -4
- package/src/components/conversation/attachments/video_attachment.tsx +9 -3
- package/src/components/conversation/message.tsx +12 -1
- package/src/components/conversation/message_attachments.tsx +43 -8
- package/src/components/page/error_boundary.tsx +4 -3
- package/src/components/primitive/actions_form_sheet.tsx +159 -0
- package/src/contexts/chat_context.tsx +12 -8
- package/src/hooks/use_conversation_messages.ts +0 -5
- package/src/hooks/use_jolt.ts +32 -19
- package/src/hooks/use_suspense_api.ts +23 -7
- package/src/index.tsx +6 -12
- package/src/navigation/index.tsx +6 -0
- package/src/screens/attachment_actions/attachment_actions_screen.tsx +56 -0
- package/src/screens/conversation_screen.tsx +2 -0
- package/src/types/api_primitives.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/native_adapters/configuration.ts +8 -5
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/log.ts +29 -0
- package/src/utils/navigation_constants.ts +12 -0
- package/src/utils/response_error.ts +17 -0
|
@@ -8,37 +8,37 @@ import { ExpandedLink } from './attachments/expanded_link';
|
|
|
8
8
|
import { ImageAttachment } from './attachments/image_attachment';
|
|
9
9
|
export function MessageAttachments(props) {
|
|
10
10
|
const styles = useStyles();
|
|
11
|
-
const { attachments, metaProps } = props;
|
|
11
|
+
const { attachments, metaProps, onAttachmentLongPress } = props;
|
|
12
12
|
if (!attachments || attachments.length === 0)
|
|
13
13
|
return null;
|
|
14
14
|
return (<View style={styles.attachmentsContainer}>
|
|
15
15
|
{attachments.map(attachment => {
|
|
16
16
|
switch (attachment.type) {
|
|
17
17
|
case 'MessageAttachment':
|
|
18
|
-
return (<MessageAttachment key={attachment.id} attachment={attachment} metaProps={metaProps}/>);
|
|
18
|
+
return (<MessageAttachment key={attachment.id} attachment={attachment} metaProps={metaProps} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
19
19
|
case 'giphy':
|
|
20
|
-
return (<GiphyAttachment key={attachment.id || attachment.titleLink} attachment={attachment}/>);
|
|
20
|
+
return (<GiphyAttachment key={attachment.id || attachment.titleLink} attachment={attachment} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
21
21
|
case 'ExpandedLink':
|
|
22
|
-
return <ExpandedLink key={attachment.id} attachment={attachment}
|
|
22
|
+
return (<ExpandedLink key={attachment.id} attachment={attachment} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
23
23
|
default:
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
26
|
})}
|
|
27
27
|
</View>);
|
|
28
28
|
}
|
|
29
|
-
function MessageAttachment({ attachment, metaProps }) {
|
|
29
|
+
function MessageAttachment({ attachment, metaProps, onAttachmentLongPress, }) {
|
|
30
30
|
const { attributes } = attachment;
|
|
31
31
|
const contentType = attributes?.contentType;
|
|
32
32
|
const basicType = contentType ? contentType.split('/')[0] : '';
|
|
33
33
|
switch (basicType) {
|
|
34
34
|
case 'image':
|
|
35
|
-
return <ImageAttachment attachment={attachment} metaProps={metaProps}
|
|
35
|
+
return (<ImageAttachment attachment={attachment} metaProps={metaProps} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
36
36
|
case 'video':
|
|
37
|
-
return <VideoAttachment attachment={attachment}
|
|
37
|
+
return (<VideoAttachment attachment={attachment} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
38
38
|
case 'audio':
|
|
39
|
-
return <AudioAttachment attachment={attachment}
|
|
39
|
+
return (<AudioAttachment attachment={attachment} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
40
40
|
default:
|
|
41
|
-
return <GenericFileAttachment attachment={attachment}
|
|
41
|
+
return (<GenericFileAttachment attachment={attachment} onAttachmentLongPress={onAttachmentLongPress}/>);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
const useStyles = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_attachments.js","sourceRoot":"","sources":["../../../src/components/conversation/message_attachments.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"message_attachments.js","sourceRoot":"","sources":["../../../src/components/conversation/message_attachments.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAK/C,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA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'react'\nimport { View, StyleSheet } from 'react-native'\nimport {\n DenormalizedAttachmentResource,\n DenormalizedMessageAttachmentResource,\n} from '../../types/resources/denormalized_attachment_resource'\nimport { AudioAttachment } from './attachments/audio_attachment'\nimport { VideoAttachment } from './attachments/video_attachment'\nimport { GiphyAttachment } from './attachments/giphy_attachment'\nimport { GenericFileAttachment } from './attachments/generic_file_attachment'\nimport { ExpandedLink } from './attachments/expanded_link'\nimport { ImageAttachment, type MetaProps } from './attachments/image_attachment'\n\nexport function MessageAttachments(props: {\n attachments: DenormalizedAttachmentResource[]\n metaProps: MetaProps\n onAttachmentLongPress: (attachment: DenormalizedAttachmentResource) => void\n}) {\n const styles = useStyles()\n const { attachments, metaProps, onAttachmentLongPress } = props\n if (!attachments || attachments.length === 0) return null\n return (\n <View style={styles.attachmentsContainer}>\n {attachments.map(attachment => {\n switch (attachment.type) {\n case 'MessageAttachment':\n return (\n <MessageAttachment\n key={attachment.id}\n attachment={attachment}\n metaProps={metaProps}\n onAttachmentLongPress={onAttachmentLongPress}\n />\n )\n case 'giphy':\n return (\n <GiphyAttachment\n key={attachment.id || attachment.titleLink}\n attachment={attachment}\n onAttachmentLongPress={onAttachmentLongPress}\n />\n )\n case 'ExpandedLink':\n return (\n <ExpandedLink\n key={attachment.id}\n attachment={attachment}\n onAttachmentLongPress={onAttachmentLongPress}\n />\n )\n default:\n return null\n }\n })}\n </View>\n )\n}\n\nfunction MessageAttachment({\n attachment,\n metaProps,\n onAttachmentLongPress,\n}: {\n attachment: DenormalizedMessageAttachmentResource\n metaProps: MetaProps\n onAttachmentLongPress: (attachment: DenormalizedMessageAttachmentResource) => void\n}) {\n const { attributes } = attachment\n const contentType = attributes?.contentType\n const basicType = contentType ? contentType.split('/')[0] : ''\n switch (basicType) {\n case 'image':\n return (\n <ImageAttachment\n attachment={attachment}\n metaProps={metaProps}\n onAttachmentLongPress={onAttachmentLongPress}\n />\n )\n case 'video':\n return (\n <VideoAttachment attachment={attachment} onAttachmentLongPress={onAttachmentLongPress} />\n )\n case 'audio':\n return (\n <AudioAttachment attachment={attachment} onAttachmentLongPress={onAttachmentLongPress} />\n )\n default:\n return (\n <GenericFileAttachment\n attachment={attachment}\n onAttachmentLongPress={onAttachmentLongPress}\n />\n )\n }\n}\n\nconst useStyles = () => {\n return StyleSheet.create({\n attachmentsContainer: {\n gap: 4,\n padding: 2,\n },\n })\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_boundary.d.ts","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAsB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"error_boundary.d.ts","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAsB,MAAM,OAAO,CAAA;AAOpE,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAA;IAC9B,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB,CAAA;AAED,cAAM,aAAc,SAAQ,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC,CAAC;IACtF,KAAK,EAAE,kBAAkB,CAGxB;IAED,iBAAiB,CAAC,KAAK,EAAE,GAAG;IAI5B,WAAW,CAAC,KAAK,EAAE,GAAG;IAItB,WAAW,aAGV;IAED,MAAM;CAOP;AA+FD,eAAe,aAAa,CAAA"}
|
|
@@ -5,6 +5,7 @@ import { StyleSheet, View } from 'react-native';
|
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
6
|
import { Button, Heading, Icon, Text } from '../display';
|
|
7
7
|
import { useTheme } from '../../hooks';
|
|
8
|
+
import { ResponseError } from '../../utils/response_error';
|
|
8
9
|
class ErrorBoundary extends React.Component {
|
|
9
10
|
state = {
|
|
10
11
|
error: null,
|
|
@@ -39,12 +40,12 @@ function ErrorView({ error, onReset }) {
|
|
|
39
40
|
reset();
|
|
40
41
|
};
|
|
41
42
|
}, [reset, onReset]);
|
|
42
|
-
if (error instanceof
|
|
43
|
-
return <ResponseErrorView
|
|
43
|
+
if (error instanceof ResponseError) {
|
|
44
|
+
return <ResponseErrorView response={error.response} onReset={onReset}/>;
|
|
44
45
|
}
|
|
45
46
|
return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'}/>;
|
|
46
47
|
}
|
|
47
|
-
function ResponseErrorView({
|
|
48
|
+
function ResponseErrorView({ response }) {
|
|
48
49
|
const { status } = response;
|
|
49
50
|
const heading = useMemo(() => {
|
|
50
51
|
switch (status) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_boundary.js","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAAE,EAAqB,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"error_boundary.js","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAAE,EAAqB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,GAAG,EAAE,EAAE;YACP,iBAAiB,EAAE,EAAE;YACrB,aAAa,EAAE,MAAM;SACtB;QACD,WAAW,EAAE;YACX,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,CAAC;SACP;QACD,OAAO,EAAE;YACP,SAAS,EAAE,QAAQ;YACnB,UAAU,EAAE,EAAE;SACf;QACD,IAAI,EAAE;YACJ,SAAS,EAAE,QAAQ;YACnB,UAAU,EAAE,EAAE;SACf;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,wBAAwB;SAC7C;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,eAAe,aAAa,CAAA","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport { useQueryErrorResetBoundary } from '@tanstack/react-query'\nimport React, { PropsWithChildren, useEffect, useMemo } from 'react'\nimport { StyleSheet, View } from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { Button, Heading, Icon, Text } from '../display'\nimport { useTheme } from '../../hooks'\nimport { ResponseError } from '../../utils/response_error'\n\ntype ErrorBoundaryState = {\n error: Response | Error | null\n unsubscriber: () => void\n}\n\nclass ErrorBoundary extends React.Component<PropsWithChildren<{ onReset?: () => void }>> {\n state: ErrorBoundaryState = {\n error: null,\n unsubscriber: () => {},\n }\n\n componentDidCatch(error: any) {\n this.handleError(error)\n }\n\n handleError(error: any) {\n this.setState({ error })\n }\n\n handleReset = () => {\n this.props.onReset?.()\n this.setState({ error: null })\n }\n\n render() {\n if (this.state.error) {\n return <ErrorView error={this.state.error} onReset={this.handleReset} />\n } else {\n return this.props.children\n }\n }\n}\n\nfunction ErrorView({ error, onReset }: { error: Error | Response; onReset: () => void }) {\n const { reset } = useQueryErrorResetBoundary()\n useEffect(() => {\n if (!reset) return\n\n return () => {\n onReset()\n reset()\n }\n }, [reset, onReset])\n\n if (error instanceof ResponseError) {\n return <ResponseErrorView response={error.response} onReset={onReset} />\n }\n\n return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'} />\n}\n\nfunction ResponseErrorView({ response }: { response: Response; onReset: () => void }) {\n const { status } = response\n const heading = useMemo(() => {\n switch (status) {\n case 403:\n return 'Permission required'\n case 404:\n return 'Content not found'\n default:\n return 'Oops!'\n }\n }, [status])\n\n const body = useMemo(() => {\n switch (status) {\n case 403:\n return 'Contact your administrator for access.'\n case 404:\n return 'If you believe something should be here, please reach out to your administrator.'\n default:\n return 'Something unexpected happened.'\n }\n }, [status])\n\n return <ErrorContent heading={heading} body={body} />\n}\n\nfunction ErrorContent({ heading, body }: { heading: string; body: string }) {\n const styles = useStyles()\n const navigation = useNavigation()\n\n return (\n <View style={styles.container}>\n <Icon name=\"general.outlinedTextMessage\" size={32} color={styles.icon.color} />\n <View style={styles.information}>\n <Heading variant=\"h3\" style={styles.heading}>\n {heading}\n </Heading>\n <Text style={styles.body}>{body}</Text>\n </View>\n <Button variant=\"outline\" onPress={navigation.goBack} title=\"Go back\" size=\"md\" />\n </View>\n )\n}\n\nconst useStyles = () => {\n const theme = useTheme()\n const { bottom } = useSafeAreaInsets()\n return StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: 'center',\n alignItems: 'center',\n gap: 24,\n paddingHorizontal: 16,\n paddingBottom: bottom,\n },\n information: {\n alignItems: 'center',\n gap: 8,\n },\n heading: {\n textAlign: 'center',\n lineHeight: 20,\n },\n body: {\n textAlign: 'center',\n lineHeight: 20,\n },\n icon: {\n color: theme.colors.iconColorDefaultDisabled,\n },\n })\n}\n\nexport default ErrorBoundary\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NativeStackNavigationOptions } from '@react-navigation/native-stack';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
import { AccessibilityRole } from 'react-native';
|
|
4
|
+
import { IconString } from '../display';
|
|
5
|
+
export declare const BaseActionsFormSheetOptions: NativeStackNavigationOptions;
|
|
6
|
+
type ActionFormSheetComponents = {
|
|
7
|
+
Root: React.FC<ActionsFormSheetRootProps>;
|
|
8
|
+
Action: React.FC<ActionsFormSheetActionProps>;
|
|
9
|
+
};
|
|
10
|
+
declare const _default: ActionFormSheetComponents;
|
|
11
|
+
export default _default;
|
|
12
|
+
export type { ActionsFormSheetRootProps, ActionsFormSheetActionProps };
|
|
13
|
+
interface ActionsFormSheetRootProps {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare function ActionsFormSheetRoot({ children }: ActionsFormSheetRootProps): React.JSX.Element;
|
|
17
|
+
export declare namespace ActionsFormSheetRoot {
|
|
18
|
+
var displayName: string;
|
|
19
|
+
}
|
|
20
|
+
declare const ACTION_FORM_SHEET_ACTION_APPEARANCES: {
|
|
21
|
+
readonly neutral: "neutral";
|
|
22
|
+
readonly danger: "danger";
|
|
23
|
+
};
|
|
24
|
+
type ActionsFormSheetActionAppearanceUnion = (typeof ACTION_FORM_SHEET_ACTION_APPEARANCES)[keyof typeof ACTION_FORM_SHEET_ACTION_APPEARANCES];
|
|
25
|
+
interface ActionsFormSheetActionProps {
|
|
26
|
+
title: string;
|
|
27
|
+
iconName: IconString;
|
|
28
|
+
onPress: () => void;
|
|
29
|
+
accessibilityLabel?: string;
|
|
30
|
+
accessibilityHint?: string;
|
|
31
|
+
accessibilityRole?: AccessibilityRole;
|
|
32
|
+
appearance?: ActionsFormSheetActionAppearanceUnion;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=actions_form_sheet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions_form_sheet.d.ts","sourceRoot":"","sources":["../../../src/components/primitive/actions_form_sheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAA;AAC7E,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAoB,MAAM,cAAc,CAAA;AAKlE,OAAO,EAAQ,UAAU,EAAQ,MAAM,YAAY,CAAA;AAMnD,eAAO,MAAM,2BAA2B,EAAE,4BAIzC,CAAA;AAOD,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAA;IACzC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAA;CAC9C,CAAA;wBAEkC,yBAAyB;AAA5D,wBAA4D;AAC5D,YAAY,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,CAAA;AAMtE,UAAU,yBAAyB;IACjC,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,EAAE,yBAAyB,qBAS3E;yBATe,oBAAoB;;;AAiBpC,QAAA,MAAM,oCAAoC;;;CAGhC,CAAA;AAEV,KAAK,qCAAqC,GACxC,CAAC,OAAO,oCAAoC,CAAC,CAAC,MAAM,OAAO,oCAAoC,CAAC,CAAA;AAElG,UAAU,2BAA2B;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,UAAU,CAAA;IACpB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,UAAU,CAAC,EAAE,qCAAqC,CAAA;CACnD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
import { useTheme } from '../../hooks';
|
|
5
|
+
import { PLATFORM_SHEET_ALLOWED_DETENTS_FIT_TO_CONTENTS } from '../../utils/navigation_constants';
|
|
6
|
+
import { PlatformPressable } from '@react-navigation/elements';
|
|
7
|
+
import { Icon, Text } from '../display';
|
|
8
|
+
// =================================
|
|
9
|
+
// ====== Exports ==================
|
|
10
|
+
// =================================
|
|
11
|
+
export const BaseActionsFormSheetOptions = {
|
|
12
|
+
presentation: 'formSheet',
|
|
13
|
+
headerShown: false,
|
|
14
|
+
sheetAllowedDetents: PLATFORM_SHEET_ALLOWED_DETENTS_FIT_TO_CONTENTS,
|
|
15
|
+
};
|
|
16
|
+
const ActionsFormSheet = {
|
|
17
|
+
Root: ActionsFormSheetRoot,
|
|
18
|
+
Action: ActionsFormSheetAction,
|
|
19
|
+
};
|
|
20
|
+
export default ActionsFormSheet;
|
|
21
|
+
export function ActionsFormSheetRoot({ children }) {
|
|
22
|
+
const styles = useStyles();
|
|
23
|
+
return (<View style={styles.container}>
|
|
24
|
+
<View style={styles.gestureBar}/>
|
|
25
|
+
<View style={styles.actions}>{children}</View>
|
|
26
|
+
</View>);
|
|
27
|
+
}
|
|
28
|
+
ActionsFormSheetRoot.displayName = 'ActionsFormSheet.Root';
|
|
29
|
+
// ====================================
|
|
30
|
+
// ====== ActionsFormSheetAction ======
|
|
31
|
+
// ====================================
|
|
32
|
+
const ACTION_FORM_SHEET_ACTION_APPEARANCES = {
|
|
33
|
+
neutral: 'neutral',
|
|
34
|
+
danger: 'danger',
|
|
35
|
+
};
|
|
36
|
+
function ActionsFormSheetAction({ title, iconName, onPress, accessibilityLabel, accessibilityHint, accessibilityRole = 'button', appearance = 'neutral', }) {
|
|
37
|
+
const styles = useStyles({ appearance });
|
|
38
|
+
return (<PlatformPressable onPress={onPress} accessibilityLabel={accessibilityLabel} accessibilityHint={accessibilityHint} accessibilityRole={accessibilityRole} style={styles.actionPressable}>
|
|
39
|
+
<Icon name={iconName} size={16} accessibilityElementsHidden style={styles.actionIcon}/>
|
|
40
|
+
<Text style={styles.actionTitle}>{title}</Text>
|
|
41
|
+
</PlatformPressable>);
|
|
42
|
+
}
|
|
43
|
+
ActionsFormSheetAction.displayName = 'ActionsFormSheet.Action';
|
|
44
|
+
const useStyles = ({ appearance = 'neutral' } = {}) => {
|
|
45
|
+
const { colors } = useTheme();
|
|
46
|
+
const { bottom } = useSafeAreaInsets();
|
|
47
|
+
const appearanceColorsMap = {
|
|
48
|
+
neutral: {
|
|
49
|
+
iconColor: colors.iconColorDefaultPrimary,
|
|
50
|
+
textColor: colors.textColorDefaultPrimary,
|
|
51
|
+
},
|
|
52
|
+
danger: {
|
|
53
|
+
iconColor: colors.fillColorStatusErrorMedium,
|
|
54
|
+
textColor: colors.fillColorStatusErrorMedium,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
return StyleSheet.create({
|
|
58
|
+
container: {
|
|
59
|
+
flex: 1,
|
|
60
|
+
justifyContent: 'flex-start',
|
|
61
|
+
paddingTop: 12,
|
|
62
|
+
paddingBottom: bottom,
|
|
63
|
+
width: '100%',
|
|
64
|
+
backgroundColor: colors.fillColorNeutral100Inverted,
|
|
65
|
+
},
|
|
66
|
+
gestureBar: {
|
|
67
|
+
width: 32,
|
|
68
|
+
height: 4,
|
|
69
|
+
backgroundColor: colors.fillColorNeutral050Base,
|
|
70
|
+
borderRadius: 100,
|
|
71
|
+
alignSelf: 'center',
|
|
72
|
+
},
|
|
73
|
+
actions: {
|
|
74
|
+
paddingTop: 20,
|
|
75
|
+
},
|
|
76
|
+
actionPressable: {
|
|
77
|
+
flexDirection: 'row',
|
|
78
|
+
alignItems: 'center',
|
|
79
|
+
paddingVertical: 12,
|
|
80
|
+
paddingHorizontal: 16,
|
|
81
|
+
gap: 8,
|
|
82
|
+
},
|
|
83
|
+
actionIcon: {
|
|
84
|
+
color: appearanceColorsMap[appearance].iconColor,
|
|
85
|
+
},
|
|
86
|
+
actionTitle: {
|
|
87
|
+
color: appearanceColorsMap[appearance].textColor,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=actions_form_sheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions_form_sheet.js","sourceRoot":"","sources":["../../../src/components/primitive/actions_form_sheet.tsx"],"names":[],"mappings":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AS,EAAE,MAAM,CAAC,0BAA0B;SAC7C;KACF,CAAA;IAED,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE;YACT,IAAI,EAAE,CAAC;YACP,cAAc,EAAE,YAAY;YAC5B,UAAU,EAAE,EAAE;YACd,aAAa,EAAE,MAAM;YACrB,KAAK,EAAE,MAAM;YACb,eAAe,EAAE,MAAM,CAAC,2BAA2B;SACpD;QACD,UAAU,EAAE;YACV,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,CAAC;YACT,eAAe,EAAE,MAAM,CAAC,uBAAuB;YAC/C,YAAY,EAAE,GAAG;YACjB,SAAS,EAAE,QAAQ;SACpB;QACD,OAAO,EAAE;YACP,UAAU,EAAE,EAAE;SACf;QACD,eAAe,EAAE;YACf,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ;YACpB,eAAe,EAAE,EAAE;YACnB,iBAAiB,EAAE,EAAE;YACrB,GAAG,EAAE,CAAC;SACP;QACD,UAAU,EAAE;YACV,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC,SAAS;SACjD;QACD,WAAW,EAAE;YACX,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC,SAAS;SACjD;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { NativeStackNavigationOptions } from '@react-navigation/native-stack'\nimport React, { ReactNode } from 'react'\nimport { AccessibilityRole, StyleSheet, View } from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { useTheme } from '../../hooks'\nimport { PLATFORM_SHEET_ALLOWED_DETENTS_FIT_TO_CONTENTS } from '../../utils/navigation_constants'\nimport { PlatformPressable } from '@react-navigation/elements'\nimport { Icon, IconString, Text } from '../display'\n\n// =================================\n// ====== Exports ==================\n// =================================\n\nexport const BaseActionsFormSheetOptions: NativeStackNavigationOptions = {\n presentation: 'formSheet',\n headerShown: false,\n sheetAllowedDetents: PLATFORM_SHEET_ALLOWED_DETENTS_FIT_TO_CONTENTS,\n}\n\nconst ActionsFormSheet = {\n Root: ActionsFormSheetRoot,\n Action: ActionsFormSheetAction,\n} as const\n\ntype ActionFormSheetComponents = {\n Root: React.FC<ActionsFormSheetRootProps>\n Action: React.FC<ActionsFormSheetActionProps>\n}\n\nexport default ActionsFormSheet as ActionFormSheetComponents\nexport type { ActionsFormSheetRootProps, ActionsFormSheetActionProps }\n\n// ====================================\n// ====== ActionsFormSheetRoot ========\n// ====================================\n\ninterface ActionsFormSheetRootProps {\n children: ReactNode\n}\n\nexport function ActionsFormSheetRoot({ children }: ActionsFormSheetRootProps) {\n const styles = useStyles()\n\n return (\n <View style={styles.container}>\n <View style={styles.gestureBar} />\n <View style={styles.actions}>{children}</View>\n </View>\n )\n}\n\nActionsFormSheetRoot.displayName = 'ActionsFormSheet.Root'\n\n// ====================================\n// ====== ActionsFormSheetAction ======\n// ====================================\n\nconst ACTION_FORM_SHEET_ACTION_APPEARANCES = {\n neutral: 'neutral',\n danger: 'danger',\n} as const\n\ntype ActionsFormSheetActionAppearanceUnion =\n (typeof ACTION_FORM_SHEET_ACTION_APPEARANCES)[keyof typeof ACTION_FORM_SHEET_ACTION_APPEARANCES]\n\ninterface ActionsFormSheetActionProps {\n title: string\n iconName: IconString\n onPress: () => void\n accessibilityLabel?: string\n accessibilityHint?: string\n accessibilityRole?: AccessibilityRole\n appearance?: ActionsFormSheetActionAppearanceUnion\n}\n\nfunction ActionsFormSheetAction({\n title,\n iconName,\n onPress,\n accessibilityLabel,\n accessibilityHint,\n accessibilityRole = 'button',\n appearance = 'neutral',\n}: ActionsFormSheetActionProps) {\n const styles = useStyles({ appearance })\n\n return (\n <PlatformPressable\n onPress={onPress}\n accessibilityLabel={accessibilityLabel}\n accessibilityHint={accessibilityHint}\n accessibilityRole={accessibilityRole}\n style={styles.actionPressable}\n >\n <Icon name={iconName} size={16} accessibilityElementsHidden style={styles.actionIcon} />\n <Text style={styles.actionTitle}>{title}</Text>\n </PlatformPressable>\n )\n}\n\nActionsFormSheetAction.displayName = 'ActionsFormSheet.Action'\n\n// ==================================\n// ====== Styles ====================\n// ==================================\n\ninterface Styles {\n appearance?: ActionsFormSheetActionAppearanceUnion\n}\n\nconst useStyles = ({ appearance = 'neutral' }: Styles = {}) => {\n const { colors } = useTheme()\n const { bottom } = useSafeAreaInsets()\n\n const appearanceColorsMap = {\n neutral: {\n iconColor: colors.iconColorDefaultPrimary,\n textColor: colors.textColorDefaultPrimary,\n },\n danger: {\n iconColor: colors.fillColorStatusErrorMedium,\n textColor: colors.fillColorStatusErrorMedium,\n },\n }\n\n return StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: 'flex-start',\n paddingTop: 12,\n paddingBottom: bottom,\n width: '100%',\n backgroundColor: colors.fillColorNeutral100Inverted,\n },\n gestureBar: {\n width: 32,\n height: 4,\n backgroundColor: colors.fillColorNeutral050Base,\n borderRadius: 100,\n alignSelf: 'center',\n },\n actions: {\n paddingTop: 20,\n },\n actionPressable: {\n flexDirection: 'row',\n alignItems: 'center',\n paddingVertical: 12,\n paddingHorizontal: 16,\n gap: 8,\n },\n actionIcon: {\n color: appearanceColorsMap[appearance].iconColor,\n },\n actionTitle: {\n color: appearanceColorsMap[appearance].textColor,\n },\n })\n}\n"]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ColorSchemeName } from 'react-native';
|
|
3
3
|
import { DeepPartial } from '../types';
|
|
4
|
-
import { ENV, PartialToken, ResponseError, Session } from '../utils';
|
|
4
|
+
import { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils';
|
|
5
5
|
import { ChatTheme, DefaultTheme } from '../utils/theme';
|
|
6
|
-
export
|
|
6
|
+
export interface ChatProviderProps {
|
|
7
7
|
env?: ENV;
|
|
8
8
|
giphyApiKey?: string;
|
|
9
9
|
onUnauthorizedResponse: (_response: ResponseError) => void;
|
|
10
|
-
session: Session;
|
|
11
|
-
theme: ChatTheme;
|
|
12
10
|
token?: PartialToken;
|
|
13
|
-
|
|
14
|
-
export interface ChatProviderProps extends Omit<ChatContextValue, 'client' | 'theme' | 'session'> {
|
|
11
|
+
tokenType?: OauthType;
|
|
15
12
|
theme: CreateChatThemeProps;
|
|
16
13
|
}
|
|
14
|
+
export interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {
|
|
15
|
+
session: Session;
|
|
16
|
+
theme: ChatTheme;
|
|
17
|
+
}
|
|
17
18
|
export declare const ChatContext: React.Context<ChatContextValue>;
|
|
18
19
|
export declare function ChatProvider({ children, value }: {
|
|
19
20
|
children: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,EAAE,SAAS,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEtE,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sBAAsB,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAA;IAC1D,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;CAC5B;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACxE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,SAAS,CAAA;CACjB;AAED,eAAO,MAAM,WAAW,iCAOtB,CAAA;AAEF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,qBAkB5F;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACjC,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B;AAED,eAAO,MAAM,cAAc,wBAE1B,CAAA;AAED,eAAO,MAAM,kBAAkB,yDAG5B,oBAAoB,KAAG,SAYzB,CAAA"}
|
|
@@ -12,9 +12,9 @@ export const ChatContext = createContext({
|
|
|
12
12
|
token: undefined,
|
|
13
13
|
});
|
|
14
14
|
export function ChatProvider({ children, value }) {
|
|
15
|
-
const { env, token, onUnauthorizedResponse, giphyApiKey } = value;
|
|
15
|
+
const { env, token, onUnauthorizedResponse, giphyApiKey, tokenType } = value;
|
|
16
16
|
const theme = useCreateChatTheme(value.theme || {});
|
|
17
|
-
const session = useMemo(() => new Session({ token, env }), [env, token]);
|
|
17
|
+
const session = useMemo(() => new Session({ token, env, type: tokenType }), [env, token, tokenType]);
|
|
18
18
|
const contextValue = {
|
|
19
19
|
env,
|
|
20
20
|
token,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.js","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC9B,OAAO,KAAK,EAA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B;QACtB,OAAO;QACP,KAAK;QACL,WAAW;KACZ,CAAA;IAED,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;AACrF,CAAC;AAOD,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EAAE,WAAW,GAAG,EAAE,EACvB,WAAW,EAAE,cAAc,GACN,EAAa,EAAE;IACpC,MAAM,mBAAmB,GAAG,cAAc,EAAE,IAAI,OAAO,CAAA;IACvD,MAAM,WAAW,GAAG,cAAc,IAAI,mBAAmB,CAAA;IAEzD,MAAM,KAAK,GAAG;QACZ,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;QACpD,MAAM,EAAE;YACN,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC;SACpE;KACF,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { merge } from 'lodash'\nimport React, { createContext, useMemo } from 'react'\nimport { ColorSchemeName, useColorScheme } from 'react-native'\nimport { DeepPartial } from '../types'\nimport { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils'\nimport { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'\n\nexport interface ChatProviderProps {\n env?: ENV\n giphyApiKey?: string\n onUnauthorizedResponse: (_response: ResponseError) => void\n token?: PartialToken\n tokenType?: OauthType\n theme: CreateChatThemeProps\n}\n\nexport interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {\n session: Session\n theme: ChatTheme\n}\n\nexport const ChatContext = createContext<ChatContextValue>({\n env: undefined,\n giphyApiKey: undefined,\n onUnauthorizedResponse: () => {},\n session: new Session(),\n theme: defaultTheme('light'),\n token: undefined,\n})\n\nexport function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {\n const { env, token, onUnauthorizedResponse, giphyApiKey, tokenType } = value\n const theme = useCreateChatTheme(value.theme || {})\n const session = useMemo(\n () => new Session({ token, env, type: tokenType }),\n [env, token, tokenType]\n )\n\n const contextValue: ChatContextValue = {\n env,\n token,\n onUnauthorizedResponse,\n session,\n theme,\n giphyApiKey,\n }\n\n return <ChatContext.Provider value={contextValue}>{children}</ChatContext.Provider>\n}\n\nexport interface CreateChatThemeProps {\n theme?: DeepPartial<DefaultTheme>\n colorScheme?: ColorSchemeName\n}\n\nexport const useChatContext = () => {\n return React.useContext(ChatContext)\n}\n\nexport const useCreateChatTheme = ({\n theme: customTheme = {},\n colorScheme: appColorScheme,\n}: CreateChatThemeProps): ChatTheme => {\n const internalColorScheme = useColorScheme() || 'light'\n const colorScheme = appColorScheme || internalColorScheme\n\n const theme = {\n ...merge({}, defaultTheme(colorScheme), customTheme),\n colors: {\n ...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),\n },\n }\n\n return theme\n}\n"]}
|
|
@@ -16,18 +16,18 @@ export declare const getConversationRequestArgs: ({ conversation_id }: {
|
|
|
16
16
|
export declare const useConversation: ({ conversation_id }: {
|
|
17
17
|
conversation_id: number;
|
|
18
18
|
}) => {
|
|
19
|
-
|
|
19
|
+
status: "error" | "success";
|
|
20
|
+
error: import("../types").ApiError | null;
|
|
20
21
|
isError: boolean;
|
|
21
22
|
isPending: false;
|
|
22
23
|
isLoading: false;
|
|
23
24
|
isLoadingError: false;
|
|
24
25
|
isRefetchError: boolean;
|
|
25
26
|
isSuccess: boolean;
|
|
26
|
-
status: "error" | "success";
|
|
27
27
|
dataUpdatedAt: number;
|
|
28
28
|
errorUpdatedAt: number;
|
|
29
29
|
failureCount: number;
|
|
30
|
-
failureReason:
|
|
30
|
+
failureReason: import("../types").ApiError | null;
|
|
31
31
|
errorUpdateCount: number;
|
|
32
32
|
isFetched: boolean;
|
|
33
33
|
isFetchedAfterMount: boolean;
|
|
@@ -36,7 +36,7 @@ export declare const useConversation: ({ conversation_id }: {
|
|
|
36
36
|
isPaused: boolean;
|
|
37
37
|
isRefetching: boolean;
|
|
38
38
|
isStale: boolean;
|
|
39
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<ConversationResource>,
|
|
39
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<ConversationResource>, import("../types").ApiError>>;
|
|
40
40
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
41
41
|
data: ConversationResource;
|
|
42
42
|
links: Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAEL,wBAAwB,EAEzB,MAAM,oBAAoB,CAAA;AAE3B,eAAO,MAAM,uBAAuB,wBACb;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,SACzC,wBAAwB;;;;;;CAahC,CAAA;AAED,eAAO,MAAM,sBAAsB,wBAAyB;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;CAoBrF,CAAA;AAEF,eAAO,MAAM,mBAAmB,wBAAyB;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,iDAGnF,CAAA"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import { useConversationMessagesJoltEvents } from './use_conversation_messages_jolt_events';
|
|
3
2
|
import { getRequestQueryKey, useSuspensePaginator, } from './use_suspense_api';
|
|
4
3
|
export const useConversationMessages = ({ conversation_id }, opts) => {
|
|
5
4
|
const { data, refetch, isRefetching, fetchNextPage } = useSuspensePaginator(getMessagesRequestArgs({ conversation_id }), opts);
|
|
6
5
|
const queryKey = getMessagesQueryKey({ conversation_id });
|
|
7
6
|
const messages = useMemo(() => data.filter(message => !message.deletedAt).sort((a, b) => -a.id.localeCompare(b.id)), [data]);
|
|
8
|
-
useConversationMessagesJoltEvents({
|
|
9
|
-
conversationId: conversation_id,
|
|
10
|
-
});
|
|
11
7
|
return { messages, refetch, isRefetching, fetchNextPage, queryKey };
|
|
12
8
|
};
|
|
13
9
|
export const getMessagesRequestArgs = ({ conversation_id }) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,
|
|
1
|
+
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EACL,kBAAkB,EAElB,oBAAoB,GACrB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,EAAE,eAAe,EAA+B,EAChD,IAA+B,EAC/B,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,oBAAoB,CACzE,sBAAsB,CAAC,EAAE,eAAe,EAAE,CAAC,EAC3C,IAAI,CACL,CAAA;IACD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAA;IACzD,MAAM,QAAQ,GAAG,OAAO,CACtB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1F,CAAC,IAAI,CAAC,CACP,CAAA;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAA;AACrE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EAAE,eAAe,EAA+B,EAAE,EAAE,CAAC,CAAC;IAC3F,GAAG,EAAE,qBAAqB,eAAe,WAAW;IACpD,IAAI,EAAE;QACJ,OAAO,EAAE,EAAE;QACX,MAAM,EAAE;YACN,OAAO,EAAE;gBACP,MAAM;gBACN,gBAAgB;gBAChB,MAAM;gBACN,aAAa;gBACb,YAAY;gBACZ,YAAY;gBACZ,QAAQ;gBACR,iBAAiB;aAClB;YACD,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;YAC1B,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC;SACtE;QACD,OAAO,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC;KACvC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAE,eAAe,EAA+B,EAAE,EAAE;IACtF,MAAM,WAAW,GAAG,sBAAsB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAA;IAC/D,OAAO,kBAAkB,CAAC,WAAW,CAAC,CAAA;AACxC,CAAC,CAAA","sourcesContent":["import { useMemo } from 'react'\nimport { MessageResource } from '../types'\nimport {\n getRequestQueryKey,\n SuspensePaginatorOptions,\n useSuspensePaginator,\n} from './use_suspense_api'\n\nexport const useConversationMessages = (\n { conversation_id }: { conversation_id: number },\n opts?: SuspensePaginatorOptions\n) => {\n const { data, refetch, isRefetching, fetchNextPage } = useSuspensePaginator<MessageResource>(\n getMessagesRequestArgs({ conversation_id }),\n opts\n )\n const queryKey = getMessagesQueryKey({ conversation_id })\n const messages = useMemo(\n () => data.filter(message => !message.deletedAt).sort((a, b) => -a.id.localeCompare(b.id)),\n [data]\n )\n\n return { messages, refetch, isRefetching, fetchNextPage, queryKey }\n}\n\nexport const getMessagesRequestArgs = ({ conversation_id }: { conversation_id: number }) => ({\n url: `/me/conversations/${conversation_id}/messages`,\n data: {\n perPage: 25,\n fields: {\n Message: [\n 'text',\n 'text_edited_at',\n 'mine',\n 'attachments',\n 'created_at',\n 'deleted_at',\n 'author',\n 'reaction_counts',\n ],\n Person: ['name', 'avatar'],\n ReactionCount: ['value', 'count', 'mine', 'message_id', 'author_ids'],\n },\n include: ['author', 'reaction_counts'],\n },\n})\n\nexport const getMessagesQueryKey = ({ conversation_id }: { conversation_id: number }) => {\n const requestArgs = getMessagesRequestArgs({ conversation_id })\n return getRequestQueryKey(requestArgs)\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,EACL,aAAa,EAEd,MAAM,uDAAuD,CAAA;AAC9D,OAAO,EAEL,gBAAgB,EACjB,MAAM,yDAAyD,CAAA;AAahE,eAAO,MAAM,aAAa,QAAO,UAAU,GAAG,
|
|
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,SAiG7C,CAAA;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,gCAWjD;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,10 +1,11 @@
|
|
|
1
1
|
import JoltClient from '@planningcenter/jolt-client';
|
|
2
2
|
import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import { useChatContext } from '../contexts/chat_context';
|
|
5
5
|
import { Client, Uri } from '../utils';
|
|
6
6
|
export const useJoltClient = () => {
|
|
7
7
|
const { session } = useChatContext();
|
|
8
|
+
const sessionAccessToken = session.token?.access_token;
|
|
8
9
|
const queryClient = useQueryClient();
|
|
9
10
|
const uri = useMemo(() => new Uri({ session }), [session]);
|
|
10
11
|
const apiClient = useMemo(() => new Client({
|
|
@@ -12,20 +13,29 @@ export const useJoltClient = () => {
|
|
|
12
13
|
defaultHeaders: uri.headers,
|
|
13
14
|
version: '2018-11-01',
|
|
14
15
|
}), [uri]);
|
|
15
|
-
const fetchJoltToken =
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const fetchJoltToken = async () => {
|
|
17
|
+
return queryClient.fetchQuery({
|
|
18
|
+
queryKey: ['jolt-token'],
|
|
19
|
+
queryFn: () => {
|
|
20
|
+
return apiClient.post({
|
|
21
|
+
url: '/me/jolt_authorize',
|
|
22
|
+
data: {
|
|
23
|
+
data: {
|
|
24
|
+
type: 'JoltToken',
|
|
25
|
+
attributes: {},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
23
29
|
},
|
|
30
|
+
staleTime: 5000, // 5 seconds
|
|
24
31
|
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
};
|
|
33
|
+
/** The wssUrl is static and doesn't change so we can cache it to infinity and beyond */
|
|
34
|
+
const { data: wssUrl } = useSuspenseQuery({
|
|
35
|
+
queryKey: ['wss-url'],
|
|
36
|
+
queryFn: () => fetchJoltToken().then(res => res.data.wssUrl),
|
|
37
|
+
staleTime: Infinity,
|
|
38
|
+
gcTime: Infinity,
|
|
29
39
|
});
|
|
30
40
|
const fetchAuthTokenFn = () => {
|
|
31
41
|
return queryClient.fetchQuery({
|
|
@@ -57,16 +67,18 @@ export const useJoltClient = () => {
|
|
|
57
67
|
});
|
|
58
68
|
};
|
|
59
69
|
const { data: joltClient } = useQuery({
|
|
60
|
-
enabled: Boolean(
|
|
61
|
-
queryKey: ['jolt-client',
|
|
70
|
+
enabled: Boolean(wssUrl),
|
|
71
|
+
queryKey: ['jolt-client', wssUrl, sessionAccessToken],
|
|
62
72
|
queryFn: async () => {
|
|
63
|
-
if (!
|
|
73
|
+
if (!wssUrl)
|
|
64
74
|
return undefined;
|
|
65
|
-
return new JoltClient(
|
|
75
|
+
return new JoltClient(wssUrl, {
|
|
66
76
|
fetchAuthTokenFn,
|
|
67
77
|
fetchSubscribeTokenFn,
|
|
68
78
|
}, { logToConsole: false });
|
|
69
79
|
},
|
|
80
|
+
staleTime: Infinity,
|
|
81
|
+
gcTime: Infinity,
|
|
70
82
|
});
|
|
71
83
|
return joltClient;
|
|
72
84
|
};
|
|
@@ -74,8 +86,10 @@ export function useJoltChannel(channelName) {
|
|
|
74
86
|
const [joltChannel, setJoltChannel] = useState();
|
|
75
87
|
const jolt = useJoltClient();
|
|
76
88
|
useEffect(() => {
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
if (!jolt)
|
|
90
|
+
return () => { };
|
|
91
|
+
setJoltChannel(jolt.subscribe(channelName));
|
|
92
|
+
return () => jolt.unsubscribe(channelName);
|
|
79
93
|
}, [channelName, jolt]);
|
|
80
94
|
return joltChannel;
|
|
81
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_jolt.js","sourceRoot":"","sources":["../../src/hooks/use_jolt.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAA;AASpD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAClF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"use_jolt.js","sourceRoot":"","sources":["../../src/hooks/use_jolt.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAA;AASpD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAClF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEzD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAQtC,MAAM,CAAC,MAAM,aAAa,GAAG,GAA2B,EAAE;IACxD,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,kBAAkB,GAAG,OAAO,CAAC,KAAK,EAAE,YAAY,CAAA;IACtD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1D,MAAM,SAAS,GAAG,OAAO,CACvB,GAAG,EAAE,CACH,IAAI,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AO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED,MAAM,UAAU,cAAc,CAAC,WAAmB;IAChD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAoB,CAAA;IAClE,MAAM,IAAI,GAAG,aAAa,EAAE,CAAA;IAE5B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;QAC1B,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA;QAC3C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IAC5C,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAA;IAEvB,OAAO,WAAW,CAAA;AACpB,CAAC;AAID,MAAM,UAAU,YAAY,CAC1B,OAAqC,EACrC,SAAiB,EACjB,QAA2B;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;QAE7B,OAAO,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAM,CAAC,CAAC,CAAA;IACvD,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;AACpC,CAAC","sourcesContent":["import JoltClient from '@planningcenter/jolt-client'\nimport {\n CustomMessage,\n FetchAuthToken,\n} from '@planningcenter/jolt-client/dist/types/JoltConnection'\nimport {\n FetchSubscribeToken,\n JoltSubscription,\n} from '@planningcenter/jolt-client/dist/types/JoltSubscription'\nimport { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query'\nimport { useEffect, useMemo, useState } from 'react'\nimport { useChatContext } from '../contexts/chat_context'\nimport { ApiResource } from '../types'\nimport { Client, Uri } from '../utils'\n\ninterface JoltResponse {\n type: 'JoltToken'\n id: string\n wssUrl: string\n}\n\nexport const useJoltClient = (): JoltClient | undefined => {\n const { session } = useChatContext()\n const sessionAccessToken = session.token?.access_token\n const queryClient = useQueryClient()\n const uri = useMemo(() => new Uri({ session }), [session])\n const apiClient = useMemo(\n () =>\n new Client({\n root: uri.api(`/chat/v2`),\n defaultHeaders: uri.headers,\n version: '2018-11-01',\n }),\n [uri]\n )\n\n const fetchJoltToken = async () => {\n return queryClient.fetchQuery({\n queryKey: ['jolt-token'],\n queryFn: () => {\n return apiClient.post<ApiResource<JoltResponse>>({\n url: '/me/jolt_authorize',\n data: {\n data: {\n type: 'JoltToken',\n attributes: {},\n },\n },\n })\n },\n staleTime: 5000, // 5 seconds\n })\n }\n\n /** The wssUrl is static and doesn't change so we can cache it to infinity and beyond */\n const { data: wssUrl } = useSuspenseQuery<string>({\n queryKey: ['wss-url'],\n queryFn: () => fetchJoltToken().then(res => res.data.wssUrl),\n staleTime: Infinity,\n gcTime: Infinity,\n })\n\n const fetchAuthTokenFn: FetchAuthToken = () => {\n return queryClient.fetchQuery({\n queryKey: ['jolt-auth-token'],\n queryFn: () => fetchJoltToken().then(res => res.data.id),\n })\n }\n\n const fetchSubscribeToken: FetchSubscribeToken = (channel: string, connectionId: string) => {\n return apiClient\n .post<ApiResource<JoltResponse>>({\n url: '/me/jolt_subscribe',\n data: {\n data: {\n type: 'JoltSubscribeToken',\n attributes: { channel, cid: connectionId },\n },\n },\n })\n .then(res => res.data.id)\n .catch((res: unknown) => {\n console.error('failed to subscribe to Jolt channel', res)\n return ''\n })\n }\n\n const fetchSubscribeTokenFn: FetchSubscribeToken = (\n channel: string,\n connectionId: string,\n options\n ) => {\n return queryClient.fetchQuery({\n queryKey: ['jolt-subscribe-token', channel, connectionId],\n queryFn: () => fetchSubscribeToken(channel, connectionId, options),\n })\n }\n\n const { data: joltClient } = useQuery({\n enabled: Boolean(wssUrl),\n queryKey: ['jolt-client', wssUrl, sessionAccessToken],\n queryFn: async () => {\n if (!wssUrl) return undefined\n\n return new JoltClient(\n wssUrl,\n {\n fetchAuthTokenFn,\n fetchSubscribeTokenFn,\n },\n { logToConsole: false }\n )\n },\n staleTime: Infinity,\n gcTime: Infinity,\n })\n\n return joltClient\n}\n\nexport function useJoltChannel(channelName: string) {\n const [joltChannel, setJoltChannel] = useState<JoltSubscription>()\n const jolt = useJoltClient()\n\n useEffect(() => {\n if (!jolt) return () => {}\n setJoltChannel(jolt.subscribe(channelName))\n return () => jolt.unsubscribe(channelName)\n }, [channelName, jolt])\n\n return joltChannel\n}\n\ntype UserCallbackFn<T> = (_event: T) => void\n\nexport function useJoltEvent<T extends CustomMessage>(\n channel: JoltSubscription | undefined,\n eventName: string,\n callback: UserCallbackFn<T>\n) {\n useEffect(() => {\n if (!channel) return () => {}\n\n return channel.bind(eventName, e => callback(e as T))\n }, [channel, eventName, callback])\n}\n"]}
|