@planningcenter/chat-react-native 3.2.0-rc.4 → 3.2.0-rc.5
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/contexts/chat_context.d.ts +1 -0
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +3 -1
- package/build/contexts/chat_context.js.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_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 +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.js.map +1 -1
- 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/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.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/package.json +2 -2
- package/src/components/conversation/message_form.tsx +127 -58
- package/src/contexts/chat_context.tsx +4 -1
- package/src/hooks/use_giphy.ts +97 -0
- package/src/hooks/use_message_create.ts +55 -0
- package/src/navigation/index.tsx +5 -0
- package/src/screens/conversation_screen.tsx +2 -1
- package/src/screens/message_actions_screen.tsx +2 -2
- package/src/screens/send_giphy_screen.tsx +155 -0
|
@@ -14,7 +14,7 @@ interface MessagesFormRootProps extends ViewProps {
|
|
|
14
14
|
declare function MessageFormRoot({ conversation, children }: MessagesFormRootProps): React.JSX.Element;
|
|
15
15
|
declare function MessageFormInput(): React.JSX.Element;
|
|
16
16
|
declare function MessageFormSubmitBtn(): React.JSX.Element;
|
|
17
|
-
declare function MessageFormAttachmentPicker(): React.JSX.Element;
|
|
18
|
-
declare function MessageFormCommands(): React.JSX.Element;
|
|
17
|
+
declare function MessageFormAttachmentPicker(): React.JSX.Element | null;
|
|
18
|
+
declare function MessageFormCommands(): React.JSX.Element | null;
|
|
19
19
|
export {};
|
|
20
20
|
//# sourceMappingURL=message_form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_form.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_form.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message_form.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_form.tsx"],"names":[],"mappings":"AACA,OAAO,KAA0C,MAAM,OAAO,CAAA;AAC9D,OAAO,EAA+B,SAAS,EAAE,MAAM,cAAc,CAAA;AAGrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAKlD,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAA;AAED,UAAU,qBAAsB,SAAQ,SAAS;IAC/C,YAAY,EAAE,oBAAoB,CAAA;CACnC;AAYD,iBAAS,eAAe,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,qBAAqB,qBAsEzE;AAED,iBAAS,gBAAgB,sBAqBxB;AAED,iBAAS,oBAAoB,sBAe5B;AAED,iBAAS,2BAA2B,6BAenC;AAED,iBAAS,mBAAmB,6BA4B3B"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { useTheme as useNavigationTheme } from '@react-navigation/native';
|
|
2
|
-
import {
|
|
3
|
-
import React from 'react';
|
|
1
|
+
import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native';
|
|
2
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
4
3
|
import { StyleSheet, TextInput, View } from 'react-native';
|
|
5
|
-
import { IconButton } from '../../components';
|
|
4
|
+
import { IconButton, Text } from '../../components';
|
|
6
5
|
import { useTheme } from '../../hooks';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { updateOrCreateRecordInPagesData } from '../../utils';
|
|
6
|
+
import { useMessageCreate } from '../../hooks/use_message_create';
|
|
7
|
+
import { ChatContext } from '../../contexts/chat_context';
|
|
10
8
|
export const MessageForm = {
|
|
11
9
|
Root: MessageFormRoot,
|
|
12
10
|
TextInput: MessageFormInput,
|
|
@@ -19,57 +17,106 @@ const MessageFormContext = React.createContext({
|
|
|
19
17
|
setText: (_text) => { },
|
|
20
18
|
onSubmit: () => { },
|
|
21
19
|
disabled: false,
|
|
20
|
+
canGiphy: false,
|
|
21
|
+
usingGiphy: false,
|
|
22
|
+
setUsingGiphy: (_usingGiphy) => { },
|
|
22
23
|
});
|
|
23
24
|
function MessageFormRoot({ conversation, children }) {
|
|
25
|
+
const { giphyApiKey } = useContext(ChatContext);
|
|
26
|
+
const canGiphy = !!giphyApiKey;
|
|
24
27
|
const styles = useMessageFormStyles();
|
|
25
28
|
const [text, setText] = React.useState('');
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
url: `/me/conversations/${conversation.id}/messages`,
|
|
34
|
-
data: {
|
|
35
|
-
...requestParams.data,
|
|
36
|
-
data: {
|
|
37
|
-
type: 'Message',
|
|
38
|
-
attributes: { text },
|
|
39
|
-
},
|
|
40
|
-
fields: fieldsWithValueJoined,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
onSuccess: (result) => {
|
|
45
|
-
const updatedMessage = result.data;
|
|
46
|
-
const queryKey = getMessagesQueryKey({ conversation_id: conversation.id });
|
|
29
|
+
const [usingGiphy, setUsingGiphy] = useState(false);
|
|
30
|
+
const navigation = useNavigation();
|
|
31
|
+
const route = useRoute();
|
|
32
|
+
const { status, isPending, reset, mutate } = useMessageCreate({ conversationId: conversation.id });
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (canGiphy && !usingGiphy && text.startsWith('/giphy ')) {
|
|
35
|
+
setUsingGiphy(true);
|
|
47
36
|
setText('');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
}
|
|
38
|
+
}, [canGiphy, text, usingGiphy]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
switch (status) {
|
|
41
|
+
case 'success':
|
|
42
|
+
setText('');
|
|
43
|
+
reset();
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}, [reset, status]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (route.params.clear_input) {
|
|
49
|
+
setText('');
|
|
50
|
+
setUsingGiphy(false);
|
|
51
|
+
navigation.setParams({ ...route.params, clear_input: false });
|
|
52
|
+
}
|
|
53
|
+
}, [navigation, route.params]);
|
|
54
|
+
const canSubmit = (() => {
|
|
55
|
+
if (isPending)
|
|
56
|
+
return false;
|
|
57
|
+
if (text.length > 0)
|
|
58
|
+
return true;
|
|
59
|
+
return false;
|
|
60
|
+
})();
|
|
61
|
+
const disabled = !canSubmit;
|
|
62
|
+
const handleSubmit = () => {
|
|
63
|
+
if (!canSubmit)
|
|
64
|
+
return;
|
|
65
|
+
if (canGiphy && usingGiphy) {
|
|
66
|
+
TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput());
|
|
67
|
+
navigation.navigate('SendGiphy', {
|
|
68
|
+
conversation_id: conversation.id,
|
|
69
|
+
search_term: text,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
mutate({ text });
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return (<MessageFormContext.Provider value={{
|
|
77
|
+
text,
|
|
78
|
+
setText,
|
|
79
|
+
onSubmit: handleSubmit,
|
|
80
|
+
disabled,
|
|
81
|
+
canGiphy,
|
|
82
|
+
usingGiphy,
|
|
83
|
+
setUsingGiphy,
|
|
84
|
+
}}>
|
|
55
85
|
<View style={styles.textInputContainer}>{children}</View>
|
|
56
86
|
</MessageFormContext.Provider>);
|
|
57
87
|
}
|
|
58
88
|
function MessageFormInput() {
|
|
59
89
|
const styles = useMessageFormStyles();
|
|
60
|
-
const { text, setText, onSubmit } = React.useContext(MessageFormContext);
|
|
61
|
-
return (<
|
|
90
|
+
const { text, setText, onSubmit, usingGiphy } = React.useContext(MessageFormContext);
|
|
91
|
+
return (<View style={styles.textInput}>
|
|
92
|
+
{usingGiphy ? (<View style={styles.giphyBadge}>
|
|
93
|
+
<Text>/Giphy</Text>
|
|
94
|
+
</View>) : null}
|
|
95
|
+
|
|
96
|
+
<TextInput aria-disabled={true} placeholder="Send a message" onChangeText={setText} value={text} onSubmitEditing={onSubmit}/>
|
|
97
|
+
</View>);
|
|
62
98
|
}
|
|
63
99
|
function MessageFormSubmitBtn() {
|
|
64
100
|
const styles = useMessageFormStyles();
|
|
65
|
-
const { onSubmit, disabled } = React.useContext(MessageFormContext);
|
|
66
|
-
return (<IconButton disabled={disabled} accessibilityLabel=
|
|
101
|
+
const { onSubmit, disabled, usingGiphy } = React.useContext(MessageFormContext);
|
|
102
|
+
return (<IconButton disabled={disabled} accessibilityLabel={usingGiphy ? 'Search Giphy' : 'Send message'} size="md" appearance="neutral" style={styles.textInputSend} name={usingGiphy ? 'general.search' : 'general.upArrow'} onPress={onSubmit}/>);
|
|
67
103
|
}
|
|
68
104
|
function MessageFormAttachmentPicker() {
|
|
105
|
+
const { usingGiphy } = React.useContext(MessageFormContext);
|
|
106
|
+
if (usingGiphy) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
69
109
|
return (<IconButton accessibilityLabel="Shazam" size="md" appearance="neutral" name={'general.paperclip'}/>);
|
|
70
110
|
}
|
|
71
111
|
function MessageFormCommands() {
|
|
72
|
-
|
|
112
|
+
const { canGiphy, usingGiphy, setUsingGiphy } = React.useContext(MessageFormContext);
|
|
113
|
+
if (!canGiphy) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
if (usingGiphy) {
|
|
117
|
+
return (<IconButton accessibilityLabel="Exit Giphy Search" size="md" appearance="neutral" name={'general.x'} onPress={() => setUsingGiphy(false)}/>);
|
|
118
|
+
}
|
|
119
|
+
return (<IconButton accessibilityLabel="Search Giphy" size="md" appearance="neutral" name={'general.bolt'} onPress={() => setUsingGiphy(true)}/>);
|
|
73
120
|
}
|
|
74
121
|
const useMessageFormStyles = () => {
|
|
75
122
|
const theme = useTheme();
|
|
@@ -91,12 +138,19 @@ const useMessageFormStyles = () => {
|
|
|
91
138
|
paddingHorizontal: 20,
|
|
92
139
|
borderColor: theme.colors.fillColorNeutral050Base,
|
|
93
140
|
flex: 1,
|
|
141
|
+
flexDirection: 'row',
|
|
142
|
+
gap: 12,
|
|
143
|
+
},
|
|
144
|
+
giphyBadge: {
|
|
145
|
+
backgroundColor: theme.colors.fillColorNeutral050Base,
|
|
146
|
+
borderRadius: 24,
|
|
147
|
+
padding: 8,
|
|
148
|
+
paddingHorizontal: 12,
|
|
94
149
|
},
|
|
95
150
|
textInputSend: {
|
|
96
151
|
borderRadius: 24,
|
|
97
152
|
height: 36,
|
|
98
153
|
width: 36,
|
|
99
|
-
backgroundColor: theme.colors.fillColorNeutral040,
|
|
100
154
|
},
|
|
101
155
|
});
|
|
102
156
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_form.js","sourceRoot":"","sources":["../../../src/components/conversation/message_form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAA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AA;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO,CACL,CAAC,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,EAAG,CAChG,CAAA;AACH,CAAC;AAED,MAAM,oBAAoB,GAAG,GAAG,EAAE;IAChC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IACxB,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAA;IAE5C,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,kBAAkB,EAAE;YAClB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,uBAAuB;YACjD,cAAc,EAAE,CAAC;YACjB,OAAO,EAAE,EAAE;YACX,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI;YAC5C,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,EAAE;SACR;QACD,SAAS,EAAE;YACT,YAAY,EAAE,EAAE;YAChB,WAAW,EAAE,CAAC;YACd,OAAO,EAAE,EAAE;YACX,iBAAiB,EAAE,EAAE;YACrB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,uBAAuB;YACjD,IAAI,EAAE,CAAC;SACR;QACD,aAAa,EAAE;YACb,YAAY,EAAE,EAAE;YAChB,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,mBAAmB;SAClD;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { useTheme as useNavigationTheme } from '@react-navigation/native'\nimport { InfiniteData, useMutation, useQueryClient } from '@tanstack/react-query'\nimport React from 'react'\nimport { StyleSheet, TextInput, View, ViewProps } from 'react-native'\nimport { IconButton } from '../../components'\nimport { useTheme } from '../../hooks'\nimport { useApiClient } from '../../hooks/use_api_client'\nimport { getMessagesQueryKey, getMessagesRequestArgs } from '../../hooks/use_conversation_messages'\nimport { ApiCollection, ApiResource, ConversationResource, MessageResource } from '../../types'\nimport { updateOrCreateRecordInPagesData } from '../../utils'\n\nexport const MessageForm = {\n Root: MessageFormRoot,\n TextInput: MessageFormInput,\n SubmitButton: MessageFormSubmitBtn,\n AttachmentPicker: MessageFormAttachmentPicker,\n Commands: MessageFormCommands,\n}\n\ninterface MessagesFormRootProps extends ViewProps {\n conversation: ConversationResource\n}\n\nconst MessageFormContext = React.createContext({\n text: '',\n setText: (_text: string) => {},\n onSubmit: () => {},\n disabled: false,\n})\n\nfunction MessageFormRoot({ conversation, children }: MessagesFormRootProps) {\n const styles = useMessageFormStyles()\n const [text, setText] = React.useState('')\n const apiClient = useApiClient()\n const queryClient = useQueryClient()\n\n const { mutate, isPending } = useMutation({\n mutationFn: async () => {\n const requestParams = getMessagesRequestArgs({ conversation_id: conversation.id })\n const fieldsWithValueJoined = Object.fromEntries(\n Object.entries(requestParams.data.fields).map(([k, v]) => [k, v.join(',')])\n )\n\n return apiClient.chat.post<ApiResource<MessageResource>>({\n url: `/me/conversations/${conversation.id}/messages`,\n data: {\n ...requestParams.data,\n data: {\n type: 'Message',\n attributes: { text },\n },\n fields: fieldsWithValueJoined,\n },\n })\n },\n onSuccess: (result: ApiResource<MessageResource>) => {\n const updatedMessage = result.data\n type QueryData = InfiniteData<ApiCollection<MessageResource>>\n const queryKey = getMessagesQueryKey({ conversation_id: conversation.id })\n\n setText('')\n queryClient.setQueryData<QueryData>(queryKey, data =>\n updateOrCreateRecordInPagesData({\n data,\n record: updatedMessage,\n })\n )\n },\n })\n\n return (\n <MessageFormContext.Provider\n value={{ text, setText, onSubmit: () => mutate(), disabled: isPending }}\n >\n <View style={styles.textInputContainer}>{children}</View>\n </MessageFormContext.Provider>\n )\n}\n\nfunction MessageFormInput() {\n const styles = useMessageFormStyles()\n const { text, setText, onSubmit } = React.useContext(MessageFormContext)\n\n return (\n <TextInput\n aria-disabled={true}\n placeholder=\"Send a message\"\n onChangeText={setText}\n value={text}\n style={styles.textInput}\n onSubmitEditing={onSubmit}\n />\n )\n}\n\nfunction MessageFormSubmitBtn() {\n const styles = useMessageFormStyles()\n const { onSubmit, disabled } = React.useContext(MessageFormContext)\n\n return (\n <IconButton\n disabled={disabled}\n accessibilityLabel=\"Send message\"\n size=\"md\"\n appearance=\"neutral\"\n style={styles.textInputSend}\n name={'general.upArrow'}\n onPress={onSubmit}\n />\n )\n}\n\nfunction MessageFormAttachmentPicker() {\n return (\n <IconButton\n accessibilityLabel=\"Shazam\"\n size=\"md\"\n appearance=\"neutral\"\n name={'general.paperclip'}\n />\n )\n}\n\nfunction MessageFormCommands() {\n return (\n <IconButton accessibilityLabel=\"Shazam\" size=\"md\" appearance=\"neutral\" name={'general.bolt'} />\n )\n}\n\nconst useMessageFormStyles = () => {\n const theme = useTheme()\n const navigationTheme = useNavigationTheme()\n\n return StyleSheet.create({\n textInputContainer: {\n borderColor: theme.colors.fillColorNeutral050Base,\n borderTopWidth: 1,\n padding: 12,\n backgroundColor: navigationTheme.colors.card,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 12,\n },\n textInput: {\n borderRadius: 24,\n borderWidth: 1,\n padding: 12,\n paddingHorizontal: 20,\n borderColor: theme.colors.fillColorNeutral050Base,\n flex: 1,\n },\n textInputSend: {\n borderRadius: 24,\n height: 36,\n width: 36,\n backgroundColor: theme.colors.fillColorNeutral040,\n },\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"message_form.js","sourceRoot":"","sources":["../../../src/components/conversation/message_form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,IAAI,kBAAkB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAClG,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAa,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,UA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K;YACpB,GAAG,EAAE,EAAE;SACR;QACD,UAAU,EAAE;YACV,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,uBAAuB;YACrD,YAAY,EAAE,EAAE;YAChB,OAAO,EAAE,CAAC;YACV,iBAAiB,EAAE,EAAE;SACtB;QACD,aAAa,EAAE;YACb,YAAY,EAAE,EAAE;YAChB,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;SACV;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'\nimport React, { useContext, useEffect, useState } from 'react'\nimport { StyleSheet, TextInput, View, ViewProps } from 'react-native'\nimport { IconButton, Text } from '../../components'\nimport { useTheme } from '../../hooks'\nimport { ConversationResource } from '../../types'\nimport { useMessageCreate } from '../../hooks/use_message_create'\nimport { ConversationScreenProps } from '../../screens/conversation_screen'\nimport { ChatContext } from '../../contexts/chat_context'\n\nexport const MessageForm = {\n Root: MessageFormRoot,\n TextInput: MessageFormInput,\n SubmitButton: MessageFormSubmitBtn,\n AttachmentPicker: MessageFormAttachmentPicker,\n Commands: MessageFormCommands,\n}\n\ninterface MessagesFormRootProps extends ViewProps {\n conversation: ConversationResource\n}\n\nconst MessageFormContext = React.createContext({\n text: '',\n setText: (_text: string) => {},\n onSubmit: () => {},\n disabled: false,\n canGiphy: false,\n usingGiphy: false,\n setUsingGiphy: (_usingGiphy: boolean) => {},\n})\n\nfunction MessageFormRoot({ conversation, children }: MessagesFormRootProps) {\n const { giphyApiKey } = useContext(ChatContext)\n const canGiphy = !!giphyApiKey\n const styles = useMessageFormStyles()\n const [text, setText] = React.useState('')\n const [usingGiphy, setUsingGiphy] = useState(false)\n const navigation = useNavigation()\n const route = useRoute() as ConversationScreenProps['route']\n const { status, isPending, reset, mutate } = useMessageCreate({ conversationId: conversation.id })\n\n useEffect(() => {\n if (canGiphy && !usingGiphy && text.startsWith('/giphy ')) {\n setUsingGiphy(true)\n setText('')\n }\n }, [canGiphy, text, usingGiphy])\n\n useEffect(() => {\n switch (status) {\n case 'success':\n setText('')\n reset()\n break\n }\n }, [reset, status])\n\n useEffect(() => {\n if (route.params.clear_input) {\n setText('')\n setUsingGiphy(false)\n navigation.setParams({ ...route.params, clear_input: false })\n }\n }, [navigation, route.params])\n\n const canSubmit = (() => {\n if (isPending) return false\n if (text.length > 0) return true\n return false\n })()\n const disabled = !canSubmit\n\n const handleSubmit = () => {\n if (!canSubmit) return\n\n if (canGiphy && usingGiphy) {\n TextInput.State.blurTextInput(TextInput.State.currentlyFocusedInput())\n navigation.navigate('SendGiphy', {\n conversation_id: conversation.id,\n search_term: text,\n })\n } else {\n mutate({ text })\n }\n }\n\n return (\n <MessageFormContext.Provider\n value={{\n text,\n setText,\n onSubmit: handleSubmit,\n disabled,\n canGiphy,\n usingGiphy,\n setUsingGiphy,\n }}\n >\n <View style={styles.textInputContainer}>{children}</View>\n </MessageFormContext.Provider>\n )\n}\n\nfunction MessageFormInput() {\n const styles = useMessageFormStyles()\n const { text, setText, onSubmit, usingGiphy } = React.useContext(MessageFormContext)\n\n return (\n <View style={styles.textInput}>\n {usingGiphy ? (\n <View style={styles.giphyBadge}>\n <Text>/Giphy</Text>\n </View>\n ) : null}\n\n <TextInput\n aria-disabled={true}\n placeholder=\"Send a message\"\n onChangeText={setText}\n value={text}\n onSubmitEditing={onSubmit}\n />\n </View>\n )\n}\n\nfunction MessageFormSubmitBtn() {\n const styles = useMessageFormStyles()\n const { onSubmit, disabled, usingGiphy } = React.useContext(MessageFormContext)\n\n return (\n <IconButton\n disabled={disabled}\n accessibilityLabel={usingGiphy ? 'Search Giphy' : 'Send message'}\n size=\"md\"\n appearance=\"neutral\"\n style={styles.textInputSend}\n name={usingGiphy ? 'general.search' : 'general.upArrow'}\n onPress={onSubmit}\n />\n )\n}\n\nfunction MessageFormAttachmentPicker() {\n const { usingGiphy } = React.useContext(MessageFormContext)\n\n if (usingGiphy) {\n return null\n }\n\n return (\n <IconButton\n accessibilityLabel=\"Shazam\"\n size=\"md\"\n appearance=\"neutral\"\n name={'general.paperclip'}\n />\n )\n}\n\nfunction MessageFormCommands() {\n const { canGiphy, usingGiphy, setUsingGiphy } = React.useContext(MessageFormContext)\n\n if (!canGiphy) {\n return null\n }\n\n if (usingGiphy) {\n return (\n <IconButton\n accessibilityLabel=\"Exit Giphy Search\"\n size=\"md\"\n appearance=\"neutral\"\n name={'general.x'}\n onPress={() => setUsingGiphy(false)}\n />\n )\n }\n\n return (\n <IconButton\n accessibilityLabel=\"Search Giphy\"\n size=\"md\"\n appearance=\"neutral\"\n name={'general.bolt'}\n onPress={() => setUsingGiphy(true)}\n />\n )\n}\n\nconst useMessageFormStyles = () => {\n const theme = useTheme()\n const navigationTheme = useNavigationTheme()\n\n return StyleSheet.create({\n textInputContainer: {\n borderColor: theme.colors.fillColorNeutral050Base,\n borderTopWidth: 1,\n padding: 12,\n backgroundColor: navigationTheme.colors.card,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 12,\n },\n textInput: {\n borderRadius: 24,\n borderWidth: 1,\n padding: 12,\n paddingHorizontal: 20,\n borderColor: theme.colors.fillColorNeutral050Base,\n flex: 1,\n flexDirection: 'row',\n gap: 12,\n },\n giphyBadge: {\n backgroundColor: theme.colors.fillColorNeutral050Base,\n borderRadius: 24,\n padding: 8,\n paddingHorizontal: 12,\n },\n textInputSend: {\n borderRadius: 24,\n height: 36,\n width: 36,\n },\n })\n}\n"]}
|
|
@@ -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;A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AiB,CAAA;CAAE,qBAe5F;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACjC,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B;AAED,eAAO,MAAM,kBAAkB,yDAG5B,oBAAoB,KAAG,SAYzB,CAAA"}
|
|
@@ -9,9 +9,10 @@ export const ChatContext = createContext({
|
|
|
9
9
|
env: undefined,
|
|
10
10
|
onUnauthorizedResponse: () => { },
|
|
11
11
|
session: new Session(),
|
|
12
|
+
giphyApiKey: undefined,
|
|
12
13
|
});
|
|
13
14
|
export function ChatProvider({ children, value }) {
|
|
14
|
-
const { env, token, onUnauthorizedResponse } = value;
|
|
15
|
+
const { env, token, onUnauthorizedResponse, giphyApiKey } = value;
|
|
15
16
|
const theme = useCreateChatTheme(value.theme || {});
|
|
16
17
|
const session = useMemo(() => new Session({ token, env }), [env, token]);
|
|
17
18
|
const contextValue = {
|
|
@@ -20,6 +21,7 @@ export function ChatProvider({ children, value }) {
|
|
|
20
21
|
onUnauthorizedResponse,
|
|
21
22
|
session,
|
|
22
23
|
theme,
|
|
24
|
+
giphyApiKey,
|
|
23
25
|
};
|
|
24
26
|
return <ChatContext.Provider value={contextValue}>{children}</ChatContext.Provider>;
|
|
25
27
|
}
|
|
@@ -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,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACrD,OAAO,EAAmB,cAAc,EAAE,MAAM,cAAc,CAAA;AAE9D,OAAO,EAAoC,OAAO,EAAE,MAAM,UAAU,CAAA;AACpE,OAAO,EAAa,YAAY,EAAgB,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"chat_context.js","sourceRoot":"","s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C,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, PartialToken, ResponseError, Session } from '../utils'\nimport { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'\n\nexport type ChatContextValue = {\n token?: PartialToken\n onUnauthorizedResponse: (_response: ResponseError) => void\n theme: ChatTheme\n env?: ENV\n session: Session\n giphyApiKey?: string\n}\n\nexport interface ChatProviderProps extends Omit<ChatContextValue, 'client' | 'theme' | 'session'> {\n theme: CreateChatThemeProps\n}\n\nexport const ChatContext = createContext<ChatContextValue>({\n theme: defaultTheme('light'),\n token: undefined,\n env: undefined,\n onUnauthorizedResponse: () => {},\n session: new Session(),\n giphyApiKey: undefined,\n})\n\nexport function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {\n const { env, token, onUnauthorizedResponse, giphyApiKey } = value\n const theme = useCreateChatTheme(value.theme || {})\n const session = useMemo(() => new Session({ token, env }), [env, token])\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 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"]}
|
|
@@ -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,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC;YAC1B,UAAU,CAAC,EAAE,CAAC,CAAA;YACd,OAAM;QACR,CAAC;QAED,cAAc,CAAC,IAAI,CAAC,CAAA;QACpB,KAAK,CAAC,gDAAgD,WAAW,MAAM,IAAI,oBAAoB,CAAC;aAC7F,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,C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AAG,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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiResource, MessageResource } from '../types';
|
|
2
|
+
import { DenormalizedAttachmentResourceForCreate } from '../types/resources/denormalized_attachment_resource';
|
|
3
|
+
interface Props {
|
|
4
|
+
conversationId: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function useMessageCreate({ conversationId }: Props): import("@tanstack/react-query").UseMutationResult<ApiResource<MessageResource>, Error, {
|
|
7
|
+
text: string;
|
|
8
|
+
attachments?: DenormalizedAttachmentResourceForCreate[];
|
|
9
|
+
}, unknown>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=use_message_create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_message_create.d.ts","sourceRoot":"","sources":["../../src/hooks/use_message_create.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAGtE,OAAO,EAAE,uCAAuC,EAAE,MAAM,qDAAqD,CAAA;AAE7G,UAAU,KAAK;IACb,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,cAAc,EAAE,EAAE,KAAK;UAO9C,MAAM;kBACE,uCAAuC,EAAE;YAkC5D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { getMessagesQueryKey, getMessagesRequestArgs } from './use_conversation_messages';
|
|
3
|
+
import { useApiClient } from './use_api_client';
|
|
4
|
+
import { queryClient } from '../contexts/api_provider';
|
|
5
|
+
import { updateOrCreateRecordInPagesData } from '../utils';
|
|
6
|
+
export function useMessageCreate({ conversationId }) {
|
|
7
|
+
const apiClient = useApiClient();
|
|
8
|
+
const mutation = useMutation({
|
|
9
|
+
mutationFn: ({ text, attachments, }) => {
|
|
10
|
+
const requestParams = getMessagesRequestArgs({ conversation_id: conversationId });
|
|
11
|
+
const fieldsWithValueJoined = Object.fromEntries(Object.entries(requestParams.data.fields).map(([k, v]) => [k, v.join(',')]));
|
|
12
|
+
return apiClient.chat.post({
|
|
13
|
+
url: `/me/conversations/${conversationId}/messages`,
|
|
14
|
+
data: {
|
|
15
|
+
...requestParams.data,
|
|
16
|
+
data: {
|
|
17
|
+
type: 'Message',
|
|
18
|
+
attributes: { text, ...(attachments ? { attachments } : {}) },
|
|
19
|
+
},
|
|
20
|
+
fields: fieldsWithValueJoined,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
onSuccess: (result) => {
|
|
25
|
+
const updatedMessage = result.data;
|
|
26
|
+
const queryKey = getMessagesQueryKey({ conversation_id: conversationId });
|
|
27
|
+
queryClient.setQueryData(queryKey, data => updateOrCreateRecordInPagesData({
|
|
28
|
+
data,
|
|
29
|
+
record: updatedMessage,
|
|
30
|
+
}));
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return mutation;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=use_message_create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_message_create.js","sourceRoot":"","sources":["../../src/hooks/use_message_create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA;AAO1D,MAAM,UAAU,gBAAgB,CAAC,EAAE,cAAc,EAAS;IACxD,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,QAAQ,GAAG,WAAW,CAAC;QAC3B,UAAU,EAAE,CAAC,EACX,IAAI,EACJ,WAAW,GAIZ,EAAE,EAAE;YACH,MAAM,aAAa,GAAG,sBAAsB,CAAC,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC,CAAA;YACjF,MAAM,qBAAqB,GAAG,MAAM,CAAC,WAAW,CAC9C,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAC5E,CAAA;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAA+B;gBACvD,GAAG,EAAE,qBAAqB,cAAc,WAAW;gBACnD,IAAI,EAAE;oBACJ,GAAG,aAAa,CAAC,IAAI;oBACrB,IAAI,EAAE;wBACJ,IAAI,EAAE,SAAS;wBACf,UAAU,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;qBAC9D;oBACD,MAAM,EAAE,qBAAqB;iBAC9B;aACF,CAAC,CAAA;QACJ,CAAC;QACD,SAAS,EAAE,CAAC,MAAoC,EAAE,EAAE;YAClD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAA;YAElC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC,CAAA;YAEzE,WAAW,CAAC,YAAY,CAAY,QAAQ,EAAE,IAAI,CAAC,EAAE,CACnD,+BAA+B,CAAC;gBAC9B,IAAI;gBACJ,MAAM,EAAE,cAAc;aACvB,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["import { InfiniteData, useMutation } from '@tanstack/react-query'\nimport { getMessagesQueryKey, getMessagesRequestArgs } from './use_conversation_messages'\nimport { useApiClient } from './use_api_client'\nimport { ApiCollection, ApiResource, MessageResource } from '../types'\nimport { queryClient } from '../contexts/api_provider'\nimport { updateOrCreateRecordInPagesData } from '../utils'\nimport { DenormalizedAttachmentResourceForCreate } from '../types/resources/denormalized_attachment_resource'\n\ninterface Props {\n conversationId: number\n}\n\nexport function useMessageCreate({ conversationId }: Props) {\n const apiClient = useApiClient()\n const mutation = useMutation({\n mutationFn: ({\n text,\n attachments,\n }: {\n text: string\n attachments?: DenormalizedAttachmentResourceForCreate[]\n }) => {\n const requestParams = getMessagesRequestArgs({ conversation_id: conversationId })\n const fieldsWithValueJoined = Object.fromEntries(\n Object.entries(requestParams.data.fields).map(([k, v]) => [k, v.join(',')])\n )\n\n return apiClient.chat.post<ApiResource<MessageResource>>({\n url: `/me/conversations/${conversationId}/messages`,\n data: {\n ...requestParams.data,\n data: {\n type: 'Message',\n attributes: { text, ...(attachments ? { attachments } : {}) },\n },\n fields: fieldsWithValueJoined,\n },\n })\n },\n onSuccess: (result: ApiResource<MessageResource>) => {\n const updatedMessage = result.data\n type QueryData = InfiniteData<ApiCollection<MessageResource>>\n const queryKey = getMessagesQueryKey({ conversation_id: conversationId })\n\n queryClient.setQueryData<QueryData>(queryKey, data =>\n updateOrCreateRecordInPagesData({\n data,\n record: updatedMessage,\n })\n )\n },\n })\n\n return mutation\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { ConversationDetailsScreen } from '../screens/conversation_details_scree
|
|
|
5
5
|
import { ConversationScreen } from '../screens/conversation_screen';
|
|
6
6
|
import { ConversationsScreen } from '../screens/conversations/conversations_screen';
|
|
7
7
|
import { MessageActionsScreen } from '../screens/message_actions_screen';
|
|
8
|
+
import { SendGiphyScreen } from '../screens/send_giphy_screen';
|
|
8
9
|
import { NotFound } from '../screens/not_found';
|
|
9
10
|
import { ReactionsScreen } from '../screens/reactions_screen';
|
|
10
11
|
import { ScreenLayout } from './screenLayout';
|
|
@@ -184,6 +185,10 @@ export declare const ChatStack: import("@react-navigation/native").TypedNavigato
|
|
|
184
185
|
readonly presentation: "modal";
|
|
185
186
|
};
|
|
186
187
|
};
|
|
188
|
+
readonly SendGiphy: {
|
|
189
|
+
readonly screen: typeof SendGiphyScreen;
|
|
190
|
+
readonly options: import("@react-navigation/native-stack").NativeStackNavigationOptions;
|
|
191
|
+
};
|
|
187
192
|
readonly MessageActions: {
|
|
188
193
|
readonly screen: typeof MessageActionsScreen;
|
|
189
194
|
readonly options: import("@react-navigation/native-stack").NativeStackNavigationOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/navigation/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAEL,2BAA2B,EAC5B,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAA;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAA;AAOnF,OAAO,EACL,oBAAoB,EAErB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAA0B,MAAM,6BAA6B,CAAA;AAErF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAO7C,eAAO,MAAM,uBAAuB;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/navigation/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAEL,2BAA2B,EAC5B,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAA;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAA;AAOnF,OAAO,EACL,oBAAoB,EAErB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,eAAe,EAA0B,MAAM,8BAA8B,CAAA;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAA0B,MAAM,6BAA6B,CAAA;AAErF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAO7C,eAAO,MAAM,uBAAuB;;;;;;;;;uOAtBiC,mBACjE;;;;;;;;;;;;;;;;;;;uBAmJ08a,gBAAiB,KAAK;;;qCAnHv8a,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBtD,CAAA;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;uBA8Fw7a,gBAAiB,KAAK;;;qCApFv8a,2BAA2B;;;;;;;;;;;;uBAoFs5a,gBAAiB,KAAK;;;;;;;;;;;uBAAtB,gBAAiB,KAAK;;;;qCA9Cv8a,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mDA8Cu6a,KAAK;;;iDAnHv8a,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0GtD,CAAA;AAEF,KAAK,kBAAkB,GAAG,eAAe,CAAC,OAAO,SAAS,CAAC,CAAA;AAE3D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,eAAe,CAAC;QACxB,UAAU,aAAc,SAAQ,kBAAkB;SAAG;KACtD;CACF"}
|
|
@@ -9,6 +9,7 @@ import { ConversationCreateScreen } from '../screens/create/conversation_create_
|
|
|
9
9
|
import { ConversationFilterReceipientsScreenOptions, ConversationFilterRecipientsScreen, } from '../screens/create/conversation_filter_recipients_screen';
|
|
10
10
|
import { ConversationSelectRecipientsScreen } from '../screens/create/conversation_select_recipients_screen';
|
|
11
11
|
import { MessageActionsScreen, MessageActionsScreenOptions, } from '../screens/message_actions_screen';
|
|
12
|
+
import { SendGiphyScreen, SendGiphyScreenOptions } from '../screens/send_giphy_screen';
|
|
12
13
|
import { NotFound } from '../screens/not_found';
|
|
13
14
|
import { ReactionsScreen, ReactionsScreenOptions } from '../screens/reactions_screen';
|
|
14
15
|
import { HeaderRightButton } from './header';
|
|
@@ -92,6 +93,10 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
92
93
|
presentation: 'modal',
|
|
93
94
|
},
|
|
94
95
|
},
|
|
96
|
+
SendGiphy: {
|
|
97
|
+
screen: SendGiphyScreen,
|
|
98
|
+
options: SendGiphyScreenOptions,
|
|
99
|
+
},
|
|
95
100
|
MessageActions: {
|
|
96
101
|
screen: MessageActionsScreen,
|
|
97
102
|
// Something about sheetAllowedDetents declared inline breaks TS
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/navigation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EACL,0BAA0B,GAE3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAA;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAA;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,EACL,0CAA0C,EAC1C,kCAAkC,GACnC,MAAM,yDAAyD,CAAA;AAChE,OAAO,EAAE,kCAAkC,EAAE,MAAM,yDAAyD,CAAA;AAC5G,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,wCAAwC,CAAA;AA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C;SACH;QACD,MAAM,EAAE;YACN,MAAM,EAAE,uBAAuB;YAC/B,OAAO,EAAE;gBACP,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,OAAO;aACtB;SACF;QACD,cAAc,EAAE;YACd,MAAM,EAAE,oBAAoB;YAC5B,gEAAgE;YAChE,OAAO,EAAE,2BAA2B;SACrC;QACD,SAAS,EAAE;YACT,MAAM,EAAE,eAAe;YACvB,OAAO,EAAE,sBAAsB;SAChC;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE;gBACP,KAAK,EAAE,KAAK;aACb;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,GAAG;aACV;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import { HeaderBackButton } from '@react-navigation/elements'\nimport { StaticParamList } from '@react-navigation/native'\nimport {\n createNativeStackNavigator,\n NativeStackHeaderRightProps,\n} from '@react-navigation/native-stack'\nimport React from 'react'\nimport { Icon } from '../components'\nimport { ConversationDetailsScreen } from '../screens/conversation_details_screen'\nimport { ConversationScreen } from '../screens/conversation_screen'\nimport { ConversationsScreen } from '../screens/conversations/conversations_screen'\nimport { ConversationCreateScreen } from '../screens/create/conversation_create_screen'\nimport {\n ConversationFilterReceipientsScreenOptions,\n ConversationFilterRecipientsScreen,\n} from '../screens/create/conversation_filter_recipients_screen'\nimport { ConversationSelectRecipientsScreen } from '../screens/create/conversation_select_recipients_screen'\nimport {\n MessageActionsScreen,\n MessageActionsScreenOptions,\n} from '../screens/message_actions_screen'\nimport { NotFound } from '../screens/not_found'\nimport { ReactionsScreen, ReactionsScreenOptions } from '../screens/reactions_screen'\nimport { HeaderRightButton } from './header'\nimport { ScreenLayout } from './screenLayout'\nimport {\n ConversationFiltersScreen,\n ConversationFiltersScreenOptions,\n} from '../screens/conversation_filters_screen'\nimport { ConversationFiltersParams } from '../screens/conversation_filters/screen_props'\n\nexport const CreateConversationStack = createNativeStackNavigator({\n initialRouteName: 'ConversationSelectRecipients',\n screenOptions: {\n headerBackButtonDisplayMode: 'minimal',\n },\n screenLayout: ScreenLayout,\n screens: {\n ConversationSelectRecipients: {\n screen: ConversationSelectRecipientsScreen,\n options: ({ navigation }) => ({\n title: 'New conversation',\n headerRight: (props: NativeStackHeaderRightProps) => (\n <HeaderRightButton {...props} onPress={navigation.goBack}>\n Cancel\n </HeaderRightButton>\n ),\n }),\n },\n ConversationFilterRecipients: {\n screen: ConversationFilterRecipientsScreen,\n options: ConversationFilterReceipientsScreenOptions,\n },\n ConversationCreate: {\n screen: ConversationCreateScreen,\n options: {\n title: 'New conversation',\n headerLeft: () => null,\n },\n },\n },\n})\n\nexport const ChatStack = createNativeStackNavigator({\n screenOptions: {\n headerBackButtonDisplayMode: 'minimal',\n },\n screenLayout: ScreenLayout,\n screens: {\n Conversations: {\n screen: ConversationsScreen,\n options: ({ route, navigation }) => ({\n headerTitle: (route.params as { title?: string })?.title ?? 'Chat',\n headerRight: (props: NativeStackHeaderRightProps) => (\n <HeaderBackButton\n backImage={() => <Icon name=\"general.x\" size={18} color={props.tintColor} />}\n onPress={navigation.goBack}\n {...props}\n />\n ),\n }),\n },\n ConversationFilters: {\n screen: ConversationFiltersScreen,\n options: ConversationFiltersScreenOptions,\n },\n Conversation: {\n screen: ConversationScreen,\n options: ({ route, navigation }) => ({\n headerTitle: (route.params as { title?: string })?.title ?? 'Chat',\n headerLeft: props => (\n <HeaderBackButton\n displayMode=\"minimal\"\n onPress={() => {\n if ((route.params as ConversationFiltersParams)?.chat_group_graph_id) {\n // Ensure that conversations with a graph id pass them back to the conversation list\n navigation.popTo('Conversations', route.params)\n } else {\n navigation.goBack()\n }\n }}\n {...props}\n />\n ),\n }),\n },\n ConversationDetails: {\n screen: ConversationDetailsScreen,\n options: ({ navigation }) => ({\n presentation: 'modal',\n title: 'Conversation details',\n headerRight: (props: NativeStackHeaderRightProps) => (\n <HeaderRightButton {...props} onPress={navigation.goBack}>\n Done\n </HeaderRightButton>\n ),\n }),\n },\n Create: {\n screen: CreateConversationStack,\n options: {\n headerShown: false,\n presentation: 'modal',\n },\n },\n MessageActions: {\n screen: MessageActionsScreen,\n // Something about sheetAllowedDetents declared inline breaks TS\n options: MessageActionsScreenOptions,\n },\n Reactions: {\n screen: ReactionsScreen,\n options: ReactionsScreenOptions,\n },\n NotFound: {\n screen: NotFound,\n options: {\n title: '404',\n },\n linking: {\n path: '*',\n },\n },\n },\n})\n\ntype ChatStackParamList = StaticParamList<typeof ChatStack>\n\ndeclare global {\n namespace ReactNavigation {\n interface RootParamList extends ChatStackParamList {}\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/navigation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EACL,0BAA0B,GAE3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAA;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAA;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,EACL,0CAA0C,EAC1C,kCAAkC,GACnC,MAAM,yDAAyD,CAAA;AAChE,OAAO,EAAE,kCAAkC,EAAE,MAAM,yDAAyD,CAAA;AAC5G,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACrF,OAAO,EAAE,i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,EAAE,CAAC,CACnD,CAAC,iBAAiB,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CACvD;;UACF,EAAE,iBAAiB,CAAC,CACrB;aACF,CAAC;SACH;QACD,MAAM,EAAE;YACN,MAAM,EAAE,uBAAuB;YAC/B,OAAO,EAAE;gBACP,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,OAAO;aACtB;SACF;QACD,SAAS,EAAE;YACT,MAAM,EAAE,eAAe;YACvB,OAAO,EAAE,sBAAsB;SAChC;QACD,cAAc,EAAE;YACd,MAAM,EAAE,oBAAoB;YAC5B,gEAAgE;YAChE,OAAO,EAAE,2BAA2B;SACrC;QACD,SAAS,EAAE;YACT,MAAM,EAAE,eAAe;YACvB,OAAO,EAAE,sBAAsB;SAChC;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE;gBACP,KAAK,EAAE,KAAK;aACb;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,GAAG;aACV;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import { HeaderBackButton } from '@react-navigation/elements'\nimport { StaticParamList } from '@react-navigation/native'\nimport {\n createNativeStackNavigator,\n NativeStackHeaderRightProps,\n} from '@react-navigation/native-stack'\nimport React from 'react'\nimport { Icon } from '../components'\nimport { ConversationDetailsScreen } from '../screens/conversation_details_screen'\nimport { ConversationScreen } from '../screens/conversation_screen'\nimport { ConversationsScreen } from '../screens/conversations/conversations_screen'\nimport { ConversationCreateScreen } from '../screens/create/conversation_create_screen'\nimport {\n ConversationFilterReceipientsScreenOptions,\n ConversationFilterRecipientsScreen,\n} from '../screens/create/conversation_filter_recipients_screen'\nimport { ConversationSelectRecipientsScreen } from '../screens/create/conversation_select_recipients_screen'\nimport {\n MessageActionsScreen,\n MessageActionsScreenOptions,\n} from '../screens/message_actions_screen'\nimport { SendGiphyScreen, SendGiphyScreenOptions } from '../screens/send_giphy_screen'\nimport { NotFound } from '../screens/not_found'\nimport { ReactionsScreen, ReactionsScreenOptions } from '../screens/reactions_screen'\nimport { HeaderRightButton } from './header'\nimport { ScreenLayout } from './screenLayout'\nimport {\n ConversationFiltersScreen,\n ConversationFiltersScreenOptions,\n} from '../screens/conversation_filters_screen'\nimport { ConversationFiltersParams } from '../screens/conversation_filters/screen_props'\n\nexport const CreateConversationStack = createNativeStackNavigator({\n initialRouteName: 'ConversationSelectRecipients',\n screenOptions: {\n headerBackButtonDisplayMode: 'minimal',\n },\n screenLayout: ScreenLayout,\n screens: {\n ConversationSelectRecipients: {\n screen: ConversationSelectRecipientsScreen,\n options: ({ navigation }) => ({\n title: 'New conversation',\n headerRight: (props: NativeStackHeaderRightProps) => (\n <HeaderRightButton {...props} onPress={navigation.goBack}>\n Cancel\n </HeaderRightButton>\n ),\n }),\n },\n ConversationFilterRecipients: {\n screen: ConversationFilterRecipientsScreen,\n options: ConversationFilterReceipientsScreenOptions,\n },\n ConversationCreate: {\n screen: ConversationCreateScreen,\n options: {\n title: 'New conversation',\n headerLeft: () => null,\n },\n },\n },\n})\n\nexport const ChatStack = createNativeStackNavigator({\n screenOptions: {\n headerBackButtonDisplayMode: 'minimal',\n },\n screenLayout: ScreenLayout,\n screens: {\n Conversations: {\n screen: ConversationsScreen,\n options: ({ route, navigation }) => ({\n headerTitle: (route.params as { title?: string })?.title ?? 'Chat',\n headerRight: (props: NativeStackHeaderRightProps) => (\n <HeaderBackButton\n backImage={() => <Icon name=\"general.x\" size={18} color={props.tintColor} />}\n onPress={navigation.goBack}\n {...props}\n />\n ),\n }),\n },\n ConversationFilters: {\n screen: ConversationFiltersScreen,\n options: ConversationFiltersScreenOptions,\n },\n Conversation: {\n screen: ConversationScreen,\n options: ({ route, navigation }) => ({\n headerTitle: (route.params as { title?: string })?.title ?? 'Chat',\n headerLeft: props => (\n <HeaderBackButton\n displayMode=\"minimal\"\n onPress={() => {\n if ((route.params as ConversationFiltersParams)?.chat_group_graph_id) {\n // Ensure that conversations with a graph id pass them back to the conversation list\n navigation.popTo('Conversations', route.params)\n } else {\n navigation.goBack()\n }\n }}\n {...props}\n />\n ),\n }),\n },\n ConversationDetails: {\n screen: ConversationDetailsScreen,\n options: ({ navigation }) => ({\n presentation: 'modal',\n title: 'Conversation details',\n headerRight: (props: NativeStackHeaderRightProps) => (\n <HeaderRightButton {...props} onPress={navigation.goBack}>\n Done\n </HeaderRightButton>\n ),\n }),\n },\n Create: {\n screen: CreateConversationStack,\n options: {\n headerShown: false,\n presentation: 'modal',\n },\n },\n SendGiphy: {\n screen: SendGiphyScreen,\n options: SendGiphyScreenOptions,\n },\n MessageActions: {\n screen: MessageActionsScreen,\n // Something about sheetAllowedDetents declared inline breaks TS\n options: MessageActionsScreenOptions,\n },\n Reactions: {\n screen: ReactionsScreen,\n options: ReactionsScreenOptions,\n },\n NotFound: {\n screen: NotFound,\n options: {\n title: '404',\n },\n linking: {\n path: '*',\n },\n },\n },\n})\n\ntype ChatStackParamList = StaticParamList<typeof ChatStack>\n\ndeclare global {\n namespace ReactNavigation {\n interface RootParamList extends ChatStackParamList {}\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
type ConversationRouteProps = {
|
|
4
4
|
conversation_id: number;
|
|
5
5
|
chat_group_graph_id?: string;
|
|
6
|
+
clear_input?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export type ConversationScreenProps = StaticScreenProps<ConversationRouteProps>;
|
|
8
9
|
export declare function ConversationScreen({ route }: ConversationScreenProps): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation_screen.d.ts","sourceRoot":"","sources":["../../src/screens/conversation_screen.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAIlB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAiC,MAAM,OAAO,CAAA;AAUrD,KAAK,sBAAsB,GAAG;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"conversation_screen.d.ts","sourceRoot":"","sources":["../../src/screens/conversation_screen.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAIlB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAiC,MAAM,OAAO,CAAA;AAUrD,KAAK,sBAAsB,GAAG;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,CAAA;AAE/E,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,EAAE,uBAAuB,qBA0CpE"}
|
|
@@ -27,7 +27,7 @@ export function ConversationScreen({ route }) {
|
|
|
27
27
|
<FlatList inverted contentContainerStyle={styles.listContainer} refreshing={isRefetching} onRefresh={refetch} data={messages} keyExtractor={item => item.id} renderItem={({ item }) => <Message {...item} conversation_id={conversation_id}/>} onEndReached={() => fetchNextPage()}/>
|
|
28
28
|
<MessageForm.Root conversation={conversation}>
|
|
29
29
|
{/* <MessageForm.AttachmentPicker /> */}
|
|
30
|
-
|
|
30
|
+
<MessageForm.Commands />
|
|
31
31
|
<MessageForm.TextInput />
|
|
32
32
|
<MessageForm.SubmitButton />
|
|
33
33
|
</MessageForm.Root>
|