@planningcenter/chat-react-native 3.1.0-rc.0 → 3.1.0-rc.2
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.js +2 -2
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_reaction.d.ts +1 -1
- package/build/components/conversation/message_reaction.d.ts.map +1 -1
- package/build/components/conversation/message_reaction.js +4 -0
- package/build/components/conversation/message_reaction.js.map +1 -1
- package/build/components/display/badge.js +3 -0
- package/build/components/display/badge.js.map +1 -1
- package/build/components/display/index.d.ts +5 -4
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +5 -4
- package/build/components/display/index.js.map +1 -1
- package/build/components/display/person.d.ts +10 -0
- package/build/components/display/person.d.ts.map +1 -0
- package/build/components/display/person.js +67 -0
- package/build/components/display/person.js.map +1 -0
- package/build/hooks/use_conversation_jolt_events.js +2 -2
- package/build/hooks/use_conversation_jolt_events.js.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +2 -2
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts +1 -2
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +63 -9
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/screens/conversation_details_screen.js +2 -16
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/design_system_screen.d.ts.map +1 -1
- package/build/screens/design_system_screen.js +29 -2
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/utils/cache/page_mutations.d.ts +21 -2
- package/build/utils/cache/page_mutations.d.ts.map +1 -1
- package/build/utils/cache/page_mutations.js +19 -2
- package/build/utils/cache/page_mutations.js.map +1 -1
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.d.ts +12 -0
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.d.ts.map +1 -0
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.js +20 -0
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/utils/cache/page_mutations.ts +85 -3
- package/src/components/conversation/message_form.tsx +2 -2
- package/src/components/conversation/message_reaction.tsx +3 -0
- package/src/components/display/badge.tsx +3 -0
- package/src/components/display/index.ts +5 -4
- package/src/components/display/person.tsx +90 -0
- package/src/hooks/use_conversation_jolt_events.ts +2 -2
- package/src/hooks/use_conversation_messages.ts +5 -2
- package/src/hooks/use_conversation_messages_jolt_events.ts +75 -11
- package/src/screens/conversation_details_screen.tsx +3 -30
- package/src/screens/design_system_screen.tsx +37 -1
- package/src/utils/cache/page_mutations.ts +31 -3
- package/src/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.ts +36 -0
|
@@ -6,7 +6,7 @@ import { IconButton } from '../../components';
|
|
|
6
6
|
import { useTheme } from '../../hooks';
|
|
7
7
|
import { useApiClient } from '../../hooks/use_api_client';
|
|
8
8
|
import { getMessagesQueryKey, getMessagesRequestArgs } from '../../hooks/use_conversation_messages';
|
|
9
|
-
import {
|
|
9
|
+
import { updateOrCreateRecordInPagesData } from '../../utils';
|
|
10
10
|
export const MessageForm = {
|
|
11
11
|
Root: MessageFormRoot,
|
|
12
12
|
TextInput: MessageFormInput,
|
|
@@ -45,7 +45,7 @@ function MessageFormRoot({ conversation, children }) {
|
|
|
45
45
|
const updatedMessage = result.data;
|
|
46
46
|
const queryKey = getMessagesQueryKey({ conversation_id: conversation.id });
|
|
47
47
|
setText('');
|
|
48
|
-
queryClient.setQueryData(queryKey, data =>
|
|
48
|
+
queryClient.setQueryData(queryKey, data => updateOrCreateRecordInPagesData({
|
|
49
49
|
data,
|
|
50
50
|
record: updatedMessage,
|
|
51
51
|
}));
|
|
@@ -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,EAAgB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACjF,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAa,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAEnG,OAAO,EAAE,
|
|
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,EAAgB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACjF,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAa,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAEnG,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAA;AAE7D,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,eAAe;IACrB,SAAS,EAAE,gBAAgB;IAC3B,YAAY,EAAE,oBAAo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AAa,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({\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"]}
|
|
@@ -4,7 +4,7 @@ export declare const REACTION_EMOJIS: Record<ReactionCountResource['value'], str
|
|
|
4
4
|
export declare function MessageReaction({ reaction, onPress, }: {
|
|
5
5
|
reaction: ReactionCountResource;
|
|
6
6
|
onPress: (_reaction: ReactionCountResource) => void;
|
|
7
|
-
}): React.JSX.Element;
|
|
7
|
+
}): React.JSX.Element | null;
|
|
8
8
|
export declare const useReactionStyles: ({ mine }: {
|
|
9
9
|
mine: number;
|
|
10
10
|
}) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_reaction.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_reaction.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAEtE,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,CAM1E,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,OAAO,EAAE,CAAC,SAAS,EAAE,qBAAqB,KAAK,IAAI,CAAA;CACpD,
|
|
1
|
+
{"version":3,"file":"message_reaction.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/message_reaction.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAEtE,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,CAM1E,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,OAAO,EAAE,CAAC,SAAS,EAAE,qBAAqB,KAAK,IAAI,CAAA;CACpD,4BAgBA;AAED,eAAO,MAAM,iBAAiB,aAAc;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;CAoB3D,CAAA"}
|
|
@@ -13,6 +13,10 @@ export const REACTION_EMOJIS = {
|
|
|
13
13
|
};
|
|
14
14
|
export function MessageReaction({ reaction, onPress, }) {
|
|
15
15
|
const styles = useReactionStyles(reaction);
|
|
16
|
+
if (!reaction.count)
|
|
17
|
+
return null;
|
|
18
|
+
if (!REACTION_EMOJIS[reaction.value])
|
|
19
|
+
return null;
|
|
16
20
|
return (<PlatformPressable key={reaction.value} style={styles.reaction} onPress={() => onPress(reaction)}>
|
|
17
21
|
<Text style={styles.reactionEmoji}>{REACTION_EMOJIS[reaction.value]}</Text>
|
|
18
22
|
<Text style={styles.reactionText}>{reaction.count}</Text>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_reaction.js","sourceRoot":"","sources":["../../../src/components/conversation/message_reaction.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,aAAa,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,MAAM,CAAC,MAAM,eAAe,GA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AAE,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB;YAClE,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,uBAAuB;YACpE,YAAY,EAAE,EAAE;YAChB,eAAe,EAAE,CAAC;YAClB,iBAAiB,EAAE,EAAE;YACrB,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,CAAC;SACP;QACD,aAAa,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;QAC9C,YAAY,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,uBAAuB,EAAE;KACtE,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { PlatformPressable } from '@react-navigation/elements'\nimport colorFunction from 'color'\nimport React from 'react'\nimport { StyleSheet } from 'react-native'\nimport { Text } from '../../components/display'\nimport { useTheme } from '../../hooks'\nimport { ReactionCountResource } from '../../types/resources/reaction'\n\nexport const REACTION_EMOJIS: Record<ReactionCountResource['value'], string> = {\n thumbs_up: '👍',\n thumbs_down: '👎',\n pray: '🙏',\n laugh: '😂',\n heart: '❤️',\n}\n\nexport function MessageReaction({\n reaction,\n onPress,\n}: {\n reaction: ReactionCountResource\n onPress: (_reaction: ReactionCountResource) => void\n}) {\n const styles = useReactionStyles(reaction)\n\n return (\n <PlatformPressable\n key={reaction.value}\n style={styles.reaction}\n onPress={() => onPress(reaction)}\n >\n <Text style={styles.reactionEmoji}>{REACTION_EMOJIS[reaction.value]}</Text>\n <Text style={styles.reactionText}>{reaction.count}</Text>\n </PlatformPressable>\n )\n}\n\nexport const useReactionStyles = ({ mine }: { mine: number }) => {\n const { colors } = useTheme()\n const activeBorderColor = colorFunction(colors.interaction).alpha(0.8).string()\n const activeColor = colorFunction(colors.interaction).alpha(0.2).string()\n\n return StyleSheet.create({\n reaction: {\n borderWidth: 1,\n borderColor: mine ? activeBorderColor : colors.fillColorNeutral040,\n backgroundColor: mine ? activeColor : colors.fillColorNeutral050Base,\n borderRadius: 16,\n paddingVertical: 2,\n paddingHorizontal: 12,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 4,\n },\n reactionEmoji: { fontSize: 12, paddingTop: 0 },\n reactionText: { fontSize: 12, color: colors.textColorDefaultPrimary },\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"message_reaction.js","sourceRoot":"","sources":["../../../src/components/conversation/message_reaction.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,aAAa,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,MAAM,CAAC,MAAM,eAAe,GAAmD;IAC7E,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;CACZ,CAAA;AAED,MAAM,UAAU,eAAe,CAAC,EAC9B,QAAQ,EACR,OAAO,GAIR;IACC,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,CAAC,QAAQ,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IAChC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAEjD,OAAO,CACL,CAAC,iBAAiB,CAChB,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CACpB,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CACvB,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,OAA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AE,EAAE,KAAK,EAAE,MAAM,CAAC,uBAAuB,EAAE;KACtE,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { PlatformPressable } from '@react-navigation/elements'\nimport colorFunction from 'color'\nimport React from 'react'\nimport { StyleSheet } from 'react-native'\nimport { Text } from '../../components/display'\nimport { useTheme } from '../../hooks'\nimport { ReactionCountResource } from '../../types/resources/reaction'\n\nexport const REACTION_EMOJIS: Record<ReactionCountResource['value'], string> = {\n thumbs_up: '👍',\n thumbs_down: '👎',\n pray: '🙏',\n laugh: '😂',\n heart: '❤️',\n}\n\nexport function MessageReaction({\n reaction,\n onPress,\n}: {\n reaction: ReactionCountResource\n onPress: (_reaction: ReactionCountResource) => void\n}) {\n const styles = useReactionStyles(reaction)\n\n if (!reaction.count) return null\n if (!REACTION_EMOJIS[reaction.value]) return null\n\n return (\n <PlatformPressable\n key={reaction.value}\n style={styles.reaction}\n onPress={() => onPress(reaction)}\n >\n <Text style={styles.reactionEmoji}>{REACTION_EMOJIS[reaction.value]}</Text>\n <Text style={styles.reactionText}>{reaction.count}</Text>\n </PlatformPressable>\n )\n}\n\nexport const useReactionStyles = ({ mine }: { mine: number }) => {\n const { colors } = useTheme()\n const activeBorderColor = colorFunction(colors.interaction).alpha(0.8).string()\n const activeColor = colorFunction(colors.interaction).alpha(0.2).string()\n\n return StyleSheet.create({\n reaction: {\n borderWidth: 1,\n borderColor: mine ? activeBorderColor : colors.fillColorNeutral040,\n backgroundColor: mine ? activeColor : colors.fillColorNeutral050Base,\n borderRadius: 16,\n paddingVertical: 2,\n paddingHorizontal: 12,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 4,\n },\n reactionEmoji: { fontSize: 12, paddingTop: 0 },\n reactionText: { fontSize: 12, color: colors.textColorDefaultPrimary },\n })\n}\n"]}
|
|
@@ -92,6 +92,7 @@ const useStyles = ({ appearance = 'neutral', maxFontSizeMultiplier, variant = 'd
|
|
|
92
92
|
flexDirection: 'row',
|
|
93
93
|
alignItems: 'center',
|
|
94
94
|
justifyContent: 'center',
|
|
95
|
+
alignSelf: 'flex-start',
|
|
95
96
|
borderRadius: variantStylesMap[variant].borderRadius,
|
|
96
97
|
borderWidth: variantStylesMap[variant].borderWidth,
|
|
97
98
|
borderColor: statusColorMap[appearance].background,
|
|
@@ -116,12 +117,14 @@ const useStyles = ({ appearance = 'neutral', maxFontSizeMultiplier, variant = 'd
|
|
|
116
117
|
color: variantStylesMap[variant].textColor,
|
|
117
118
|
fontWeight: variantStylesMap[variant].fontWeight,
|
|
118
119
|
fontSize: badgeFontSize,
|
|
120
|
+
lineHeight: 15 * fontScale,
|
|
119
121
|
},
|
|
120
122
|
metaLabel: {
|
|
121
123
|
paddingHorizontal: variantStylesMap[variant].paddingHorizontal,
|
|
122
124
|
fontSize: badgeFontSize,
|
|
123
125
|
flexShrink: 1,
|
|
124
126
|
paddingLeft: variantStylesMap[variant].metaLabelPaddingLeft,
|
|
127
|
+
lineHeight: 15 * fontScale,
|
|
125
128
|
},
|
|
126
129
|
});
|
|
127
130
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badge.js","sourceRoot":"","sources":["../../../src/components/display/badge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,wBAAwB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAA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AE,IAAI,CACR;IAAA,EAAE,GAAG,CAAC,CACP,CAAA;AACH,CAAC","sourcesContent":["import React from 'react'\nimport { StyleSheet, View } from 'react-native'\nimport type { ViewStyle, TextStyle } from 'react-native'\nimport Svg, { Path, Defs, LinearGradient, Stop } from 'react-native-svg'\nimport { useFontScale, useTheme } from '../../hooks'\nimport { Icon } from './icon'\nimport { Text } from './text'\nimport { platformFontWeightMedium, space } from '../../utils'\nimport { tokens } from '../../vendor/tapestry/tokens'\nimport { useStatusColorAppearanceMap, type StatusAppearanceUnion } from './utils/status_colors'\n\n// =================================\n// ====== Constants ================\n// =================================\n\nconst VARIANTS = {\n default: 'default',\n meta: 'meta',\n metaSubtle: 'metaSubtle',\n} as const\n\ntype VariantUnion = (typeof VARIANTS)[keyof typeof VARIANTS]\n\ntype VariantStyles = Record<\n VariantUnion,\n {\n backgroundColor: string\n paddingHorizontal: number\n paddingVertical: number\n borderWidth: number\n borderRadius: number\n textColor: string\n gap: number\n metaLabelPaddingLeft: number\n fontWeight: TextStyle['fontWeight']\n }\n>\n\ntype ProductLogoName = 'Groups' | 'Services' | 'groups' | 'services'\n\nconst PRODUCT_LOGO_COMPONENT_MAP = {\n groups: GroupsLogo,\n services: ServicesIcon,\n} as const\n\n// =================================\n// ====== Component ================\n// =================================\n\ninterface BadgeProps {\n /**\n * Renders the main text.\n */\n label: string\n /**\n * Renders secondary meta text to the right of the label.\n */\n metaLabel?: string\n /**\n * Changes the status color for the badge and icon.\n */\n appearance?: StatusAppearanceUnion\n /**\n * Changes form of the logo to support a meta label and badge\n */\n variant?: VariantUnion\n /**\n * Adds a product logo to the left of the text.\n */\n productLogoName?: ProductLogoName\n /**\n * Shows an icon of the user choice to the left of the text.\n */\n iconName?: string\n /**\n * Styles badge wrapper.\n */\n style?: ViewStyle\n /**\n * Specifies the maximum size a font can reach when allowFontScaling is enabled.\n */\n maxFontSizeMultiplier?: number\n}\n\nexport function Badge({\n appearance = 'neutral',\n metaLabel,\n style,\n iconName,\n label,\n productLogoName,\n variant = 'default',\n maxFontSizeMultiplier,\n}: BadgeProps) {\n const styles = useStyles({ appearance, maxFontSizeMultiplier, variant })\n const { showBadgeLogo } = useTheme()\n\n const isMetaSubtle = variant === 'metaSubtle'\n const isMeta = variant === 'meta'\n const hasMetaLabel = Boolean(metaLabel)\n\n const showLogo = showBadgeLogo && productLogoName && isMeta\n const ProductLogoSvg = showLogo && PRODUCT_LOGO_COMPONENT_MAP[productLogoName?.toLowerCase()]\n const badgeLabel = isMetaSubtle && hasMetaLabel ? `${label}:` : label\n\n return (\n <View style={[styles.badgeWrapper, style]}>\n <View style={styles.badge}>\n {showLogo && ProductLogoSvg && <ProductLogoSvg logoSize={styles.logo.fontSize} />}\n {iconName && <Icon name={iconName} style={styles.icon} />}\n <Text variant=\"footnote\" style={styles.label}>\n {badgeLabel}\n </Text>\n </View>\n {hasMetaLabel && (\n <Text variant=\"footnote\" style={styles.metaLabel} numberOfLines={1}>\n {metaLabel}\n </Text>\n )}\n </View>\n )\n}\n\n// =================================\n// ====== Styles ===================\n// =================================\n\nconst useStyles = ({\n appearance = 'neutral',\n maxFontSizeMultiplier,\n variant = 'default',\n}: Partial<BadgeProps>) => {\n const { colors } = useTheme()\n const fontScale = useFontScale({ maxFontSizeMultiplier })\n\n const statusColorMap = useStatusColorAppearanceMap()\n\n const badgePaddingHorizontal = space(1) * fontScale\n const badgePaddingVertical = space(0.5) * fontScale\n const badgeGap = space(0.5) * fontScale\n const badgeFontSize = 12\n\n const variantStylesMap: VariantStyles = {\n default: {\n gap: badgeGap,\n backgroundColor: statusColorMap[appearance].background,\n metaLabelPaddingLeft: badgePaddingHorizontal,\n paddingHorizontal: badgePaddingHorizontal,\n paddingVertical: badgePaddingVertical,\n borderWidth: tokens.borderSizeDefault * fontScale,\n borderRadius: tokens.borderRadiusMd,\n textColor: statusColorMap[appearance].text,\n fontWeight: 'normal',\n },\n meta: {\n gap: badgeGap,\n backgroundColor: statusColorMap[appearance].background,\n metaLabelPaddingLeft: badgePaddingHorizontal,\n paddingHorizontal: badgePaddingHorizontal,\n paddingVertical: badgePaddingVertical,\n borderWidth: tokens.borderSizeDefault * fontScale,\n borderRadius: tokens.borderRadiusMd,\n textColor: statusColorMap[appearance].text,\n fontWeight: platformFontWeightMedium,\n },\n metaSubtle: {\n gap: badgeGap,\n backgroundColor: 'transparent',\n metaLabelPaddingLeft: badgeGap,\n paddingHorizontal: 0,\n paddingVertical: 0,\n borderWidth: 0,\n borderRadius: 0,\n textColor: colors.textColorDefaultSecondary,\n fontWeight: platformFontWeightMedium,\n },\n }\n\n return StyleSheet.create({\n badgeWrapper: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: variantStylesMap[variant].borderRadius,\n borderWidth: variantStylesMap[variant].borderWidth,\n borderColor: statusColorMap[appearance].background,\n },\n badge: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: variantStylesMap[variant].gap,\n paddingVertical: variantStylesMap[variant].paddingVertical,\n paddingHorizontal: variantStylesMap[variant].paddingHorizontal,\n backgroundColor: variantStylesMap[variant].backgroundColor,\n borderRadius: variantStylesMap[variant].borderRadius - 2,\n },\n icon: {\n color: statusColorMap[appearance].icon,\n fontSize: badgeFontSize,\n },\n logo: {\n fontSize: badgeFontSize * fontScale,\n },\n label: {\n color: variantStylesMap[variant].textColor,\n fontWeight: variantStylesMap[variant].fontWeight,\n fontSize: badgeFontSize,\n },\n metaLabel: {\n paddingHorizontal: variantStylesMap[variant].paddingHorizontal,\n fontSize: badgeFontSize,\n flexShrink: 1,\n paddingLeft: variantStylesMap[variant].metaLabelPaddingLeft,\n },\n })\n}\n\n// =================================\n// ====== Product Logos ============\n// =================================\n\ninterface ProductLogoProps {\n logoSize: number\n}\n\nfunction GroupsLogo({ logoSize }: ProductLogoProps) {\n return (\n <Svg width={logoSize} height={logoSize} viewBox=\"0 0 16 16\" fill=\"none\">\n <Path\n d=\"M9.06 6.14H6.94c-.152.36-.438.646-.797.798v2.12c.359.152.645.438.797.797h2.117c.152-.359.437-.645.796-.797V6.94a1.502 1.502 0 01-.793-.8zM8 0C1.6 0 0 1.595 0 8s1.6 8 8 8 8-1.595 8-8-1.595-8-8-8zm3.939 10.44a1.5 1.5 0 01-2.882.585H6.94a1.5 1.5 0 11-1.963-1.963v-2.12A1.501 1.501 0 116.94 4.98h2.12a1.5 1.5 0 111.963 1.968v2.11a1.501 1.501 0 01.916 1.383z\"\n fill=\"url(#paint0_linear_2632_26363)\"\n />\n <Defs>\n <LinearGradient\n id=\"paint0_linear_2632_26363\"\n x1={-5.6338}\n y1={5.6338}\n x2={5.6338}\n y2={16.9014}\n gradientUnits=\"userSpaceOnUse\"\n >\n <Stop stopColor=\"#FF962D\" />\n <Stop offset={1} stopColor=\"#FC7638\" />\n </LinearGradient>\n </Defs>\n </Svg>\n )\n}\n\nfunction ServicesIcon({ logoSize }: ProductLogoProps) {\n return (\n <Svg width={logoSize} height={logoSize} viewBox=\"0 0 16 16\" fill=\"none\">\n <Path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M.116 8c0-6.4 1.6-8 8-8s8 1.6 8 8-1.6 8-8 8-8-1.6-8-8zm4.123 3.464a.848.848 0 10.943-1.41.848.848 0 00-.943 1.41zm.001-2.76a.848.848 0 10.948-1.408.848.848 0 00-.948 1.407zm0-2.759a.849.849 0 10.948-1.408.849.849 0 00-.948 1.408zm8.1 5.34a.388.388 0 00.03-.149v-.755a.39.39 0 00-.39-.39H6.87a.39.39 0 00-.39.39v.755a.39.39 0 00.39.39h5.11a.39.39 0 00.36-.24zm0-2.758a.388.388 0 00.03-.149v-.757a.387.387 0 00-.39-.388H6.87a.388.388 0 00-.39.388v.757a.388.388 0 00.39.388h5.11a.388.388 0 00.36-.24zm0-2.76a.388.388 0 00.03-.148v-.754a.39.39 0 00-.39-.389H6.87a.39.39 0 00-.39.387v.756a.39.39 0 00.39.39h5.11a.389.389 0 00.36-.241z\"\n fill=\"url(#paint0_linear_2632_56586)\"\n />\n <Defs>\n <LinearGradient\n id=\"paint0_linear_2632_56586\"\n x1={-5.51759}\n y1={5.6338}\n x2={5.75001}\n y2={16.9014}\n gradientUnits=\"userSpaceOnUse\"\n >\n <Stop stopColor=\"#6BB23D\" />\n <Stop offset={1} stopColor=\"#659630\" />\n </LinearGradient>\n </Defs>\n </Svg>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"badge.js","sourceRoot":"","sources":["../../../src/components/display/badge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,wBAAwB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,2BAA2B,EAA8B,MAAM,uBAAuB,CAAA;AAE/F,oCAAoC;AACpC,oCAAoC;AACpC,oCAAoC;AAEpC,MAAM,QAAQ,GAAG;IACf,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,YAAY;CAChB,CAAA;AAqBV,MAAM,0BAA0B,GAAG;IACjC,MAAM,EAAE,UAAU;IAClB,QAAQ,EAAE,YAAY;CACd,CAAA;AAyCV,MAAM,UAAU,KAAK,CAAC,EACpB,UAAU,GAAG,SAAS,EACtB,SAAS,EACT,KAAK,EACL,QAAQ,EACR,KAAK,EACL,eAAe,EACf,OAAO,GAAG,SAAS,EACnB,qBAAqB,GACV;IACX,MAAM,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C,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,EACtC;QAAA,EAAE,cAAc,CAClB;MAAA,EAAE,IAAI,CACR;IAAA,EAAE,GAAG,CAAC,CACP,CAAA;AACH,CAAC;AAED,SAAS,YAAY,CAAC,EAAE,QAAQ,EAAoB;IAClD,OAAO,CACL,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CACrE;MAAA,CAAC,IAAI,CACH,QAAQ,CAAC,SAAS,CAClB,QAAQ,CAAC,SAAS,CAClB,CAAC,CAAC,unBAAunB,CACznB,IAAI,CAAC,gCAAgC,EAEvC;MAAA,CAAC,IAAI,CACH;QAAA,CAAC,cAAc,CACb,EAAE,CAAC,0BAA0B,CAC7B,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CACb,EAAE,CAAC,CAAC,MAAM,CAAC,CACX,EAAE,CAAC,CAAC,OAAO,CAAC,CACZ,EAAE,CAAC,CAAC,OAAO,CAAC,CACZ,aAAa,CAAC,gBAAgB,CAE9B;UAAA,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EACzB;UAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,EACtC;QAAA,EAAE,cAAc,CAClB;MAAA,EAAE,IAAI,CACR;IAAA,EAAE,GAAG,CAAC,CACP,CAAA;AACH,CAAC","sourcesContent":["import React from 'react'\nimport { StyleSheet, View } from 'react-native'\nimport type { ViewStyle, TextStyle } from 'react-native'\nimport Svg, { Path, Defs, LinearGradient, Stop } from 'react-native-svg'\nimport { useFontScale, useTheme } from '../../hooks'\nimport { Icon } from './icon'\nimport { Text } from './text'\nimport { platformFontWeightMedium, space } from '../../utils'\nimport { tokens } from '../../vendor/tapestry/tokens'\nimport { useStatusColorAppearanceMap, type StatusAppearanceUnion } from './utils/status_colors'\n\n// =================================\n// ====== Constants ================\n// =================================\n\nconst VARIANTS = {\n default: 'default',\n meta: 'meta',\n metaSubtle: 'metaSubtle',\n} as const\n\ntype VariantUnion = (typeof VARIANTS)[keyof typeof VARIANTS]\n\ntype VariantStyles = Record<\n VariantUnion,\n {\n backgroundColor: string\n paddingHorizontal: number\n paddingVertical: number\n borderWidth: number\n borderRadius: number\n textColor: string\n gap: number\n metaLabelPaddingLeft: number\n fontWeight: TextStyle['fontWeight']\n }\n>\n\ntype ProductLogoName = 'Groups' | 'Services' | 'groups' | 'services'\n\nconst PRODUCT_LOGO_COMPONENT_MAP = {\n groups: GroupsLogo,\n services: ServicesIcon,\n} as const\n\n// =================================\n// ====== Component ================\n// =================================\n\ninterface BadgeProps {\n /**\n * Renders the main text.\n */\n label: string\n /**\n * Renders secondary meta text to the right of the label.\n */\n metaLabel?: string\n /**\n * Changes the status color for the badge and icon.\n */\n appearance?: StatusAppearanceUnion\n /**\n * Changes form of the logo to support a meta label and badge\n */\n variant?: VariantUnion\n /**\n * Adds a product logo to the left of the text.\n */\n productLogoName?: ProductLogoName\n /**\n * Shows an icon of the user choice to the left of the text.\n */\n iconName?: string\n /**\n * Styles badge wrapper.\n */\n style?: ViewStyle\n /**\n * Specifies the maximum size a font can reach when allowFontScaling is enabled.\n */\n maxFontSizeMultiplier?: number\n}\n\nexport function Badge({\n appearance = 'neutral',\n metaLabel,\n style,\n iconName,\n label,\n productLogoName,\n variant = 'default',\n maxFontSizeMultiplier,\n}: BadgeProps) {\n const styles = useStyles({ appearance, maxFontSizeMultiplier, variant })\n const { showBadgeLogo } = useTheme()\n\n const isMetaSubtle = variant === 'metaSubtle'\n const isMeta = variant === 'meta'\n const hasMetaLabel = Boolean(metaLabel)\n\n const showLogo = showBadgeLogo && productLogoName && isMeta\n const ProductLogoSvg = showLogo && PRODUCT_LOGO_COMPONENT_MAP[productLogoName?.toLowerCase()]\n const badgeLabel = isMetaSubtle && hasMetaLabel ? `${label}:` : label\n\n return (\n <View style={[styles.badgeWrapper, style]}>\n <View style={styles.badge}>\n {showLogo && ProductLogoSvg && <ProductLogoSvg logoSize={styles.logo.fontSize} />}\n {iconName && <Icon name={iconName} style={styles.icon} />}\n <Text variant=\"footnote\" style={styles.label}>\n {badgeLabel}\n </Text>\n </View>\n {hasMetaLabel && (\n <Text variant=\"footnote\" style={styles.metaLabel} numberOfLines={1}>\n {metaLabel}\n </Text>\n )}\n </View>\n )\n}\n\n// =================================\n// ====== Styles ===================\n// =================================\n\nconst useStyles = ({\n appearance = 'neutral',\n maxFontSizeMultiplier,\n variant = 'default',\n}: Partial<BadgeProps>) => {\n const { colors } = useTheme()\n const fontScale = useFontScale({ maxFontSizeMultiplier })\n\n const statusColorMap = useStatusColorAppearanceMap()\n\n const badgePaddingHorizontal = space(1) * fontScale\n const badgePaddingVertical = space(0.5) * fontScale\n const badgeGap = space(0.5) * fontScale\n const badgeFontSize = 12\n\n const variantStylesMap: VariantStyles = {\n default: {\n gap: badgeGap,\n backgroundColor: statusColorMap[appearance].background,\n metaLabelPaddingLeft: badgePaddingHorizontal,\n paddingHorizontal: badgePaddingHorizontal,\n paddingVertical: badgePaddingVertical,\n borderWidth: tokens.borderSizeDefault * fontScale,\n borderRadius: tokens.borderRadiusMd,\n textColor: statusColorMap[appearance].text,\n fontWeight: 'normal',\n },\n meta: {\n gap: badgeGap,\n backgroundColor: statusColorMap[appearance].background,\n metaLabelPaddingLeft: badgePaddingHorizontal,\n paddingHorizontal: badgePaddingHorizontal,\n paddingVertical: badgePaddingVertical,\n borderWidth: tokens.borderSizeDefault * fontScale,\n borderRadius: tokens.borderRadiusMd,\n textColor: statusColorMap[appearance].text,\n fontWeight: platformFontWeightMedium,\n },\n metaSubtle: {\n gap: badgeGap,\n backgroundColor: 'transparent',\n metaLabelPaddingLeft: badgeGap,\n paddingHorizontal: 0,\n paddingVertical: 0,\n borderWidth: 0,\n borderRadius: 0,\n textColor: colors.textColorDefaultSecondary,\n fontWeight: platformFontWeightMedium,\n },\n }\n\n return StyleSheet.create({\n badgeWrapper: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n alignSelf: 'flex-start',\n borderRadius: variantStylesMap[variant].borderRadius,\n borderWidth: variantStylesMap[variant].borderWidth,\n borderColor: statusColorMap[appearance].background,\n },\n badge: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: variantStylesMap[variant].gap,\n paddingVertical: variantStylesMap[variant].paddingVertical,\n paddingHorizontal: variantStylesMap[variant].paddingHorizontal,\n backgroundColor: variantStylesMap[variant].backgroundColor,\n borderRadius: variantStylesMap[variant].borderRadius - 2,\n },\n icon: {\n color: statusColorMap[appearance].icon,\n fontSize: badgeFontSize,\n },\n logo: {\n fontSize: badgeFontSize * fontScale,\n },\n label: {\n color: variantStylesMap[variant].textColor,\n fontWeight: variantStylesMap[variant].fontWeight,\n fontSize: badgeFontSize,\n lineHeight: 15 * fontScale,\n },\n metaLabel: {\n paddingHorizontal: variantStylesMap[variant].paddingHorizontal,\n fontSize: badgeFontSize,\n flexShrink: 1,\n paddingLeft: variantStylesMap[variant].metaLabelPaddingLeft,\n lineHeight: 15 * fontScale,\n },\n })\n}\n\n// =================================\n// ====== Product Logos ============\n// =================================\n\ninterface ProductLogoProps {\n logoSize: number\n}\n\nfunction GroupsLogo({ logoSize }: ProductLogoProps) {\n return (\n <Svg width={logoSize} height={logoSize} viewBox=\"0 0 16 16\" fill=\"none\">\n <Path\n d=\"M9.06 6.14H6.94c-.152.36-.438.646-.797.798v2.12c.359.152.645.438.797.797h2.117c.152-.359.437-.645.796-.797V6.94a1.502 1.502 0 01-.793-.8zM8 0C1.6 0 0 1.595 0 8s1.6 8 8 8 8-1.595 8-8-1.595-8-8-8zm3.939 10.44a1.5 1.5 0 01-2.882.585H6.94a1.5 1.5 0 11-1.963-1.963v-2.12A1.501 1.501 0 116.94 4.98h2.12a1.5 1.5 0 111.963 1.968v2.11a1.501 1.501 0 01.916 1.383z\"\n fill=\"url(#paint0_linear_2632_26363)\"\n />\n <Defs>\n <LinearGradient\n id=\"paint0_linear_2632_26363\"\n x1={-5.6338}\n y1={5.6338}\n x2={5.6338}\n y2={16.9014}\n gradientUnits=\"userSpaceOnUse\"\n >\n <Stop stopColor=\"#FF962D\" />\n <Stop offset={1} stopColor=\"#FC7638\" />\n </LinearGradient>\n </Defs>\n </Svg>\n )\n}\n\nfunction ServicesIcon({ logoSize }: ProductLogoProps) {\n return (\n <Svg width={logoSize} height={logoSize} viewBox=\"0 0 16 16\" fill=\"none\">\n <Path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M.116 8c0-6.4 1.6-8 8-8s8 1.6 8 8-1.6 8-8 8-8-1.6-8-8zm4.123 3.464a.848.848 0 10.943-1.41.848.848 0 00-.943 1.41zm.001-2.76a.848.848 0 10.948-1.408.848.848 0 00-.948 1.407zm0-2.759a.849.849 0 10.948-1.408.849.849 0 00-.948 1.408zm8.1 5.34a.388.388 0 00.03-.149v-.755a.39.39 0 00-.39-.39H6.87a.39.39 0 00-.39.39v.755a.39.39 0 00.39.39h5.11a.39.39 0 00.36-.24zm0-2.758a.388.388 0 00.03-.149v-.757a.387.387 0 00-.39-.388H6.87a.388.388 0 00-.39.388v.757a.388.388 0 00.39.388h5.11a.388.388 0 00.36-.24zm0-2.76a.388.388 0 00.03-.148v-.754a.39.39 0 00-.39-.389H6.87a.39.39 0 00-.39.387v.756a.39.39 0 00.39.39h5.11a.389.389 0 00.36-.241z\"\n fill=\"url(#paint0_linear_2632_56586)\"\n />\n <Defs>\n <LinearGradient\n id=\"paint0_linear_2632_56586\"\n x1={-5.51759}\n y1={5.6338}\n x2={5.75001}\n y2={16.9014}\n gradientUnits=\"userSpaceOnUse\"\n >\n <Stop stopColor=\"#6BB23D\" />\n <Stop offset={1} stopColor=\"#659630\" />\n </LinearGradient>\n </Defs>\n </Svg>\n )\n}\n"]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
export * from './avatar';
|
|
2
1
|
export * from './avatar_group';
|
|
2
|
+
export * from './avatar';
|
|
3
3
|
export * from './badge';
|
|
4
|
-
export * from './banner';
|
|
5
4
|
export * from './banner_collapsible';
|
|
5
|
+
export * from './banner';
|
|
6
6
|
export * from './button';
|
|
7
7
|
export * from './heading';
|
|
8
|
-
export * from './icon';
|
|
9
8
|
export * from './icon_button';
|
|
9
|
+
export * from './icon';
|
|
10
10
|
export * from './image';
|
|
11
|
+
export * from './person';
|
|
11
12
|
export * from './spinner';
|
|
12
13
|
export * from './switch';
|
|
13
|
-
export * from './text';
|
|
14
14
|
export * from './text_button';
|
|
15
15
|
export * from './text_inline_button';
|
|
16
|
+
export * from './text';
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/display/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/display/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,sBAAsB,CAAA;AACpC,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,QAAQ,CAAA"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
export * from './avatar';
|
|
2
1
|
export * from './avatar_group';
|
|
2
|
+
export * from './avatar';
|
|
3
3
|
export * from './badge';
|
|
4
|
-
export * from './banner';
|
|
5
4
|
export * from './banner_collapsible';
|
|
5
|
+
export * from './banner';
|
|
6
6
|
export * from './button';
|
|
7
7
|
export * from './heading';
|
|
8
|
-
export * from './icon';
|
|
9
8
|
export * from './icon_button';
|
|
9
|
+
export * from './icon';
|
|
10
10
|
export * from './image';
|
|
11
|
+
export * from './person';
|
|
11
12
|
export * from './spinner';
|
|
12
13
|
export * from './switch';
|
|
13
|
-
export * from './text';
|
|
14
14
|
export * from './text_button';
|
|
15
15
|
export * from './text_inline_button';
|
|
16
|
+
export * from './text';
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/display/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/display/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,sBAAsB,CAAA;AACpC,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,QAAQ,CAAA","sourcesContent":["export * from './avatar_group'\nexport * from './avatar'\nexport * from './badge'\nexport * from './banner_collapsible'\nexport * from './banner'\nexport * from './button'\nexport * from './heading'\nexport * from './icon_button'\nexport * from './icon'\nexport * from './image'\nexport * from './person'\nexport * from './spinner'\nexport * from './switch'\nexport * from './text_button'\nexport * from './text_inline_button'\nexport * from './text'\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MemberResource } from '../../types';
|
|
3
|
+
interface PersonProps {
|
|
4
|
+
person: MemberResource;
|
|
5
|
+
}
|
|
6
|
+
export declare function Person({ person }: PersonProps): React.JSX.Element;
|
|
7
|
+
export declare function Adult({ person }: PersonProps): React.JSX.Element;
|
|
8
|
+
export declare function Child({ person }: PersonProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=person.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"person.d.ts","sourceRoot":"","sources":["../../../src/components/display/person.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAU5C,UAAU,WAAW;IACnB,MAAM,EAAE,cAAc,CAAA;CACvB;AAED,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,qBAE7C;AAED,wBAAgB,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,qBAc5C;AACD,wBAAgB,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,qBAoB5C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useTheme } from '../../hooks';
|
|
4
|
+
import { platformFontWeightMedium } from '../../utils/styles';
|
|
5
|
+
import { Avatar } from './avatar';
|
|
6
|
+
import { Text } from './text';
|
|
7
|
+
import { Badge } from './badge';
|
|
8
|
+
import { space } from '../../utils';
|
|
9
|
+
export function Person({ person }) {
|
|
10
|
+
return person.child ? <Child person={person}/> : <Adult person={person}/>;
|
|
11
|
+
}
|
|
12
|
+
export function Adult({ person }) {
|
|
13
|
+
const styles = useStyles();
|
|
14
|
+
return (<View style={styles.wrapper}>
|
|
15
|
+
<Avatar sourceUri={person.avatar}/>
|
|
16
|
+
<View style={styles.content}>
|
|
17
|
+
<Text style={styles.name}>{person.name}</Text>
|
|
18
|
+
<View style={styles.badges}>
|
|
19
|
+
{person.badges?.map((badge, index) => <Badge key={index} label={badge.title}/>)}
|
|
20
|
+
</View>
|
|
21
|
+
</View>
|
|
22
|
+
</View>);
|
|
23
|
+
}
|
|
24
|
+
export function Child({ person }) {
|
|
25
|
+
const styles = useStyles();
|
|
26
|
+
return (<View style={styles.wrapper}>
|
|
27
|
+
<View style={styles.childAvatar}>
|
|
28
|
+
<Avatar sourceUri={person.avatar}/>
|
|
29
|
+
</View>
|
|
30
|
+
<View style={styles.content}>
|
|
31
|
+
<Text style={[styles.name, styles.childName]}>{person.name}</Text>
|
|
32
|
+
<View style={styles.badges}>
|
|
33
|
+
<Badge label="Not eligible to chat" appearance="warning" iconName="general.shieldExclamation"/>
|
|
34
|
+
</View>
|
|
35
|
+
</View>
|
|
36
|
+
</View>);
|
|
37
|
+
}
|
|
38
|
+
// =================================
|
|
39
|
+
// ====== Styles ===================
|
|
40
|
+
// =================================
|
|
41
|
+
const useStyles = () => {
|
|
42
|
+
const { colors } = useTheme();
|
|
43
|
+
return StyleSheet.create({
|
|
44
|
+
wrapper: {
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
alignItems: 'center',
|
|
47
|
+
gap: space(1),
|
|
48
|
+
},
|
|
49
|
+
content: {
|
|
50
|
+
gap: space(0.25),
|
|
51
|
+
},
|
|
52
|
+
name: {
|
|
53
|
+
fontWeight: platformFontWeightMedium,
|
|
54
|
+
},
|
|
55
|
+
childName: {
|
|
56
|
+
color: colors.textColorDefaultSecondary,
|
|
57
|
+
},
|
|
58
|
+
childAvatar: {
|
|
59
|
+
opacity: 0.5,
|
|
60
|
+
},
|
|
61
|
+
badges: {
|
|
62
|
+
flexDirection: 'row',
|
|
63
|
+
gap: space(0.5),
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=person.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"person.js","sourceRoot":"","sources":["../../../src/components/display/person.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAA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P,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;SACd;QACD,OAAO,EAAE;YACP,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC;SACjB;QACD,IAAI,EAAE;YACJ,UAAU,EAAE,wBAAwB;SACrC;QACD,SAAS,EAAE;YACT,KAAK,EAAE,MAAM,CAAC,yBAAyB;SACxC;QACD,WAAW,EAAE;YACX,OAAO,EAAE,GAAG;SACb;QACD,MAAM,EAAE;YACN,aAAa,EAAE,KAAK;YACpB,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;SAChB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import React from 'react'\nimport { StyleSheet, View } from 'react-native'\nimport { useTheme } from '../../hooks'\nimport { platformFontWeightMedium } from '../../utils/styles'\nimport { MemberResource } from '../../types'\nimport { Avatar } from './avatar'\nimport { Text } from './text'\nimport { Badge } from './badge'\nimport { space } from '../../utils'\n\n// =================================\n// ====== Components ===============\n// =================================\n\ninterface PersonProps {\n person: MemberResource\n}\n\nexport function Person({ person }: PersonProps) {\n return person.child ? <Child person={person} /> : <Adult person={person} />\n}\n\nexport function Adult({ person }: PersonProps) {\n const styles = useStyles()\n\n return (\n <View style={styles.wrapper}>\n <Avatar sourceUri={person.avatar} />\n <View style={styles.content}>\n <Text style={styles.name}>{person.name}</Text>\n <View style={styles.badges}>\n {person.badges?.map((badge, index) => <Badge key={index} label={badge.title} />)}\n </View>\n </View>\n </View>\n )\n}\nexport function Child({ person }: PersonProps) {\n const styles = useStyles()\n\n return (\n <View style={styles.wrapper}>\n <View style={styles.childAvatar}>\n <Avatar sourceUri={person.avatar} />\n </View>\n <View style={styles.content}>\n <Text style={[styles.name, styles.childName]}>{person.name}</Text>\n <View style={styles.badges}>\n <Badge\n label=\"Not eligible to chat\"\n appearance=\"warning\"\n iconName=\"general.shieldExclamation\"\n />\n </View>\n </View>\n </View>\n )\n}\n\n// =================================\n// ====== Styles ===================\n// =================================\n\nconst useStyles = () => {\n const { colors } = useTheme()\n\n return StyleSheet.create({\n wrapper: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: space(1),\n },\n content: {\n gap: space(0.25),\n },\n name: {\n fontWeight: platformFontWeightMedium,\n },\n childName: {\n color: colors.textColorDefaultSecondary,\n },\n childAvatar: {\n opacity: 0.5,\n },\n badges: {\n flexDirection: 'row',\n gap: space(0.5),\n },\n })\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { deleteRecordInPagesData,
|
|
2
|
+
import { deleteRecordInPagesData, updateOrCreateRecordInPagesData } from '../utils';
|
|
3
3
|
import { useApiClient } from './use_api_client';
|
|
4
4
|
import { getConversationsRequestArgs } from './use_conversations';
|
|
5
5
|
import { useCurrentPerson } from './use_current_person';
|
|
@@ -25,7 +25,7 @@ export function useConversationsJoltEvents() {
|
|
|
25
25
|
};
|
|
26
26
|
const handleConversationUpdateOrCreate = async (e) => {
|
|
27
27
|
const conversation = await fetchConversation(e.data.data).catch(c => c);
|
|
28
|
-
queryClient.setQueryData(conversationQueryKey, prev =>
|
|
28
|
+
queryClient.setQueryData(conversationQueryKey, prev => updateOrCreateRecordInPagesData({
|
|
29
29
|
data: prev,
|
|
30
30
|
record: conversation,
|
|
31
31
|
processRecord: (record, current) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_jolt_events.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAE,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"use_conversation_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_jolt_events.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO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K,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAEvE,WAAW,CAAC,YAAY,CAAY,oBAAoB,EAAE,IAAI,CAAC,EAAE,CAC/D,+BAA+B,CAAC;YAC9B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,YAAY;YACpB,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;gBACjC,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAA;YAClC,CAAC;SACF,CAAC,CACH,CAAA;IACH,CAAC,CAAA;IAED,MAAM,yBAAyB,GAAG,CAAC,CAAyB,EAAE,EAAE;QAC9D,WAAW,CAAC,YAAY,CAAY,oBAAoB,EAAE,IAAI,CAAC,EAAE,CAC/D,uBAAuB,CAAC;YACtB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;SACpB,CAAC,CACH,CAAA;IACH,CAAC,CAAA;IAED,YAAY,CAAC,WAAW,EAAE,sBAAsB,EAAE,gCAAgC,CAAC,CAAA;IACnF,YAAY,CAAC,WAAW,EAAE,sBAAsB,EAAE,gCAAgC,CAAC,CAAA;IACnF,YAAY,CAAC,WAAW,EAAE,wBAAwB,EAAE,yBAAyB,CAAC,CAAA;AAChF,CAAC","sourcesContent":["import { CustomMessage } from '@planningcenter/jolt-client/dist/types/JoltConnection'\nimport { InfiniteData, useQueryClient } from '@tanstack/react-query'\nimport { ApiCollection, ApiResource, ConversationResource } from '../types'\nimport { deleteRecordInPagesData, updateOrCreateRecordInPagesData } from '../utils'\nimport { useApiClient } from './use_api_client'\nimport { getConversationsRequestArgs } from './use_conversations'\nimport { useCurrentPerson } from './use_current_person'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\nimport { getRequestQueryKey } from './use_suspense_api'\n\ntype QueryData = InfiniteData<ApiCollection<ConversationResource>>\ninterface JoltConversationsEvent extends CustomMessage {\n data: {\n data: ConversationResource\n }\n}\n\nexport function useConversationsJoltEvents() {\n const apiClient = useApiClient()\n const queryClient = useQueryClient()\n const currentPerson = useCurrentPerson()\n const joltChannel = useJoltChannel(`chat.people.${currentPerson.id}`)\n\n const conversationsRequestArgs = getConversationsRequestArgs()\n const conversationQueryKey = getRequestQueryKey(conversationsRequestArgs)\n\n const fetchConversation = async ({ id }: ConversationResource) => {\n const { data: argsData } = conversationsRequestArgs\n const { data } = await apiClient.chat.get<ApiResource<ConversationResource>>({\n url: `/me/conversations/${id}`,\n data: {\n fields: argsData.fields,\n include: argsData.include,\n },\n })\n\n return data\n }\n\n const handleConversationUpdateOrCreate = async (e: JoltConversationsEvent) => {\n const conversation = await fetchConversation(e.data.data).catch(c => c)\n\n queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>\n updateOrCreateRecordInPagesData({\n data: prev,\n record: conversation,\n processRecord: (record, current) => {\n return { ...current, ...record }\n },\n })\n )\n }\n\n const handleConversationDestroy = (e: JoltConversationsEvent) => {\n queryClient.setQueryData<QueryData>(conversationQueryKey, prev =>\n deleteRecordInPagesData({\n data: prev,\n record: e.data.data,\n })\n )\n }\n\n useJoltEvent(joltChannel, 'conversation.updated', handleConversationUpdateOrCreate)\n useJoltEvent(joltChannel, 'conversation.created', handleConversationUpdateOrCreate)\n useJoltEvent(joltChannel, 'conversation.destroyed', handleConversationDestroy)\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"
|
|
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;AAE1C,OAAO,EAEL,wBAAwB,EAEzB,MAAM,oBAAoB,CAAA;AAE3B,eAAO,MAAM,uBAAuB,wBACb;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,SACzC,wBAAwB;;;;;;CAiBhC,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,12 +1,12 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
1
2
|
import { useConversationMessagesJoltEvents } from './use_conversation_messages_jolt_events';
|
|
2
3
|
import { getRequestQueryKey, useSuspensePaginator, } from './use_suspense_api';
|
|
3
4
|
export const useConversationMessages = ({ conversation_id }, opts) => {
|
|
4
5
|
const { data, refetch, isRefetching, fetchNextPage } = useSuspensePaginator(getMessagesRequestArgs({ conversation_id }), opts);
|
|
5
6
|
const queryKey = getMessagesQueryKey({ conversation_id });
|
|
6
|
-
const messages = data.sort((a, b) => -a.id.localeCompare(b.id));
|
|
7
|
+
const messages = useMemo(() => data.filter(message => !message.deletedAt).sort((a, b) => -a.id.localeCompare(b.id)), [data]);
|
|
7
8
|
useConversationMessagesJoltEvents({
|
|
8
9
|
conversationId: conversation_id,
|
|
9
|
-
refetchMessages: refetch,
|
|
10
10
|
});
|
|
11
11
|
return { messages, refetch, isRefetching, fetchNextPage, queryKey };
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages.ts"],"names":[],"mappings":"
|
|
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,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAA;AAC3F,OAAO,EACL,kBAAkB,EAElB,oBAAoB,GACrB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAC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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 { useConversationMessagesJoltEvents } from './use_conversation_messages_jolt_events'\nimport {\n getRequestQueryKey,\n SuspensePaginatorOptions,\n useSuspensePaginator,\n} from './use_suspense_api'\n\nexport const useConversationMessages = (\n { conversation_id }: { conversation_id: string },\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 useConversationMessagesJoltEvents({\n conversationId: conversation_id,\n })\n\n return { messages, refetch, isRefetching, fetchNextPage, queryKey }\n}\n\nexport const getMessagesRequestArgs = ({ conversation_id }: { conversation_id: string }) => ({\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: string }) => {\n const requestArgs = getMessagesRequestArgs({ conversation_id })\n return getRequestQueryKey(requestArgs)\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
interface Props {
|
|
2
2
|
conversationId: string;
|
|
3
|
-
refetchMessages?: () => void;
|
|
4
3
|
}
|
|
5
|
-
export declare function useConversationMessagesJoltEvents({ conversationId
|
|
4
|
+
export declare function useConversationMessagesJoltEvents({ conversationId }: Props): void;
|
|
6
5
|
export {};
|
|
7
6
|
//# sourceMappingURL=use_conversation_messages_jolt_events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages_jolt_events.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use_conversation_messages_jolt_events.d.ts","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"AAgBA,UAAU,KAAK;IACb,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,iCAAiC,CAAC,EAAE,cAAc,EAAE,EAAE,KAAK,QA4F1E"}
|
|
@@ -1,36 +1,90 @@
|
|
|
1
1
|
import { useJoltChannel, useJoltEvent } from './use_jolt';
|
|
2
|
-
import { updateRecordInPagesData } from '../utils';
|
|
2
|
+
import { deleteRecordInPagesData, updateOrCreateRecordInPagesData, updateRecordInPagesData, } from '../utils';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useCurrentPerson } from './use_current_person';
|
|
5
5
|
import { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource';
|
|
6
6
|
import { getMessagesRequestArgs } from './use_conversation_messages';
|
|
7
7
|
import { getRequestQueryKey } from './use_suspense_api';
|
|
8
|
-
|
|
8
|
+
import { transformReactionEventDataToReactionCountResource } from '../utils/jolt/transform_reaction_event_data_to_reaction_count_resource';
|
|
9
|
+
export function useConversationMessagesJoltEvents({ conversationId }) {
|
|
9
10
|
const queryClient = useQueryClient();
|
|
10
11
|
const currentPerson = useCurrentPerson();
|
|
11
12
|
const joltChannel = useJoltChannel(`chat.conversations.${conversationId}`);
|
|
12
13
|
const messagesRequestArgs = getMessagesRequestArgs({ conversation_id: conversationId });
|
|
13
14
|
const messagesQueryKey = getRequestQueryKey(messagesRequestArgs);
|
|
14
|
-
const handleMessageJoltEvent = async () => {
|
|
15
|
-
refetchMessages?.();
|
|
16
|
-
};
|
|
17
15
|
const handleMessageUpdateOrCreate = async (e) => {
|
|
18
16
|
const { data } = e.data;
|
|
19
17
|
const message = transformMessageEventDataToMessageResource({
|
|
20
18
|
data,
|
|
21
19
|
currentPersonId: currentPerson.id,
|
|
22
20
|
});
|
|
21
|
+
queryClient.setQueryData(messagesQueryKey, prev => {
|
|
22
|
+
if (e.event === 'message.created') {
|
|
23
|
+
return updateOrCreateRecordInPagesData({
|
|
24
|
+
data: prev,
|
|
25
|
+
record: message,
|
|
26
|
+
processRecord: (record, current) => {
|
|
27
|
+
return { ...current, ...record };
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return updateRecordInPagesData({
|
|
33
|
+
data: prev,
|
|
34
|
+
record: message,
|
|
35
|
+
processRecord: (record, current) => {
|
|
36
|
+
return { ...current, ...record };
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const handleMessageDeleted = async (e) => {
|
|
43
|
+
const { data } = e.data;
|
|
44
|
+
const message = transformMessageEventDataToMessageResource({
|
|
45
|
+
data,
|
|
46
|
+
currentPersonId: currentPerson.id,
|
|
47
|
+
});
|
|
48
|
+
queryClient.setQueryData(messagesQueryKey, prev => deleteRecordInPagesData({ data: prev, record: message }));
|
|
49
|
+
};
|
|
50
|
+
const handleReactionJoltEvent = async (e) => {
|
|
51
|
+
const { data } = e.data;
|
|
52
|
+
const message = { id: data.message_sort_key };
|
|
23
53
|
queryClient.setQueryData(messagesQueryKey, prev => updateRecordInPagesData({
|
|
24
54
|
data: prev,
|
|
25
55
|
record: message,
|
|
26
|
-
processRecord: (record,
|
|
27
|
-
|
|
56
|
+
processRecord: (record, oldMessage) => {
|
|
57
|
+
const reactionCounts = oldMessage.reactionCounts || [];
|
|
58
|
+
let foundMatch = false;
|
|
59
|
+
let newReactionCounts = reactionCounts.map(reactionCount => {
|
|
60
|
+
if (reactionCount.value === data.value) {
|
|
61
|
+
foundMatch = true;
|
|
62
|
+
return transformReactionEventDataToReactionCountResource({
|
|
63
|
+
data,
|
|
64
|
+
oldData: reactionCount,
|
|
65
|
+
event: e.event,
|
|
66
|
+
currentPersonId: currentPerson.id,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return reactionCount;
|
|
70
|
+
});
|
|
71
|
+
if (!foundMatch) {
|
|
72
|
+
const newReactionCount = transformReactionEventDataToReactionCountResource({
|
|
73
|
+
data,
|
|
74
|
+
event: e.event,
|
|
75
|
+
currentPersonId: currentPerson.id,
|
|
76
|
+
});
|
|
77
|
+
if (newReactionCount?.count) {
|
|
78
|
+
newReactionCounts = [...newReactionCounts, newReactionCount];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { ...oldMessage, reactionCounts: newReactionCounts };
|
|
28
82
|
},
|
|
29
83
|
}));
|
|
30
84
|
};
|
|
31
85
|
useJoltEvent(joltChannel, 'message.created', handleMessageUpdateOrCreate);
|
|
32
86
|
useJoltEvent(joltChannel, 'message.updated', handleMessageUpdateOrCreate);
|
|
33
|
-
useJoltEvent(joltChannel, 'message.
|
|
34
|
-
useJoltEvent(joltChannel, 'reaction.*',
|
|
87
|
+
useJoltEvent(joltChannel, 'message.destroyed', handleMessageDeleted);
|
|
88
|
+
useJoltEvent(joltChannel, 'reaction.*', handleReactionJoltEvent);
|
|
35
89
|
}
|
|
36
90
|
//# sourceMappingURL=use_conversation_messages_jolt_events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_conversation_messages_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"use_conversation_messages_jolt_events.js","sourceRoot":"","sources":["../../src/hooks/use_conversation_messages_jolt_events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAA;AAC3H,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,EAAE,iDAAiD,EAAE,MAAM,wEAAwE,CAAA;AAM1I,MAAM,UAAU,iCAAiC,CAAC,EAAE,cAAc,EAAS;IACzE,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,WAAW,GAAG,cAAc,CAAC,sBAAsB,cAAc,EAAE,CAAC,CAAA;IAC1E,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC,CAAA;IACvF,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAEhE,MAAM,2BAA2B,GAAG,KAAK,EAAE,CAAsB,EAAE,EAAE;QACnE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAA;QACvB,MAAM,OAAO,GAAG,0CAA0C,CAAC;YACzD,IAAI;YACJ,eAAe,EAAE,aAAa,CAAC,EAAE;SAClC,CAAC,CAAA;QAEF,WAAW,CAAC,YAAY,CAAY,gBAAgB,EAAE,IAAI,CAAC,EAAE;YAC3D,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oB,CAAC,CAAA;IACpE,YAAY,CAAC,WAAW,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAA;AAClE,CAAC","sourcesContent":["import { ApiCollection, MessageResource } from '../types'\nimport { useJoltChannel, useJoltEvent } from './use_jolt'\nimport {\n deleteRecordInPagesData,\n updateOrCreateRecordInPagesData,\n updateRecordInPagesData,\n} from '../utils'\nimport { MessageCreatedEvent, MessageDeletedEvent } from '../types/jolt_events/message_events'\nimport { InfiniteData, useQueryClient } from '@tanstack/react-query'\nimport { useCurrentPerson } from './use_current_person'\nimport { transformMessageEventDataToMessageResource } from '../utils/jolt/transform_message_event_data_to_message_resource'\nimport { getMessagesRequestArgs } from './use_conversation_messages'\nimport { getRequestQueryKey } from './use_suspense_api'\nimport { JoltReactionEvent } from '../types/jolt_events'\nimport { transformReactionEventDataToReactionCountResource } from '../utils/jolt/transform_reaction_event_data_to_reaction_count_resource'\n\ninterface Props {\n conversationId: string\n}\n\nexport function useConversationMessagesJoltEvents({ conversationId }: Props) {\n const queryClient = useQueryClient()\n const currentPerson = useCurrentPerson()\n const joltChannel = useJoltChannel(`chat.conversations.${conversationId}`)\n const messagesRequestArgs = getMessagesRequestArgs({ conversation_id: conversationId })\n const messagesQueryKey = getRequestQueryKey(messagesRequestArgs)\n\n const handleMessageUpdateOrCreate = async (e: MessageCreatedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n queryClient.setQueryData<QueryData>(messagesQueryKey, prev => {\n if (e.event === 'message.created') {\n return updateOrCreateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, current) => {\n return { ...current, ...record }\n },\n })\n } else {\n return updateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, current) => {\n return { ...current, ...record }\n },\n })\n }\n })\n }\n\n const handleMessageDeleted = async (e: MessageDeletedEvent) => {\n const { data } = e.data\n const message = transformMessageEventDataToMessageResource({\n data,\n currentPersonId: currentPerson.id,\n })\n\n queryClient.setQueryData<QueryData>(messagesQueryKey, prev =>\n deleteRecordInPagesData({ data: prev, record: message })\n )\n }\n\n const handleReactionJoltEvent = async (e: JoltReactionEvent) => {\n const { data } = e.data\n const message = { id: data.message_sort_key } as MessageResource\n queryClient.setQueryData<QueryData>(messagesQueryKey, prev =>\n updateRecordInPagesData({\n data: prev,\n record: message,\n processRecord: (record, oldMessage) => {\n const reactionCounts = oldMessage.reactionCounts || []\n let foundMatch = false\n let newReactionCounts = reactionCounts.map(reactionCount => {\n if (reactionCount.value === data.value) {\n foundMatch = true\n return transformReactionEventDataToReactionCountResource({\n data,\n oldData: reactionCount,\n event: e.event,\n currentPersonId: currentPerson.id,\n })\n }\n return reactionCount\n })\n\n if (!foundMatch) {\n const newReactionCount = transformReactionEventDataToReactionCountResource({\n data,\n event: e.event,\n currentPersonId: currentPerson.id,\n })\n\n if (newReactionCount?.count) {\n newReactionCounts = [...newReactionCounts, newReactionCount]\n }\n }\n\n return { ...oldMessage, reactionCounts: newReactionCounts }\n },\n })\n )\n }\n\n useJoltEvent(joltChannel, 'message.created', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.updated', handleMessageUpdateOrCreate)\n useJoltEvent(joltChannel, 'message.destroyed', handleMessageDeleted)\n useJoltEvent(joltChannel, 'reaction.*', handleReactionJoltEvent)\n}\n\ntype QueryData = InfiniteData<ApiCollection<MessageResource>>\n"]}
|