@planningcenter/chat-react-native 2.2.2-rc.1 → 2.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/conversations.d.ts.map +1 -1
- package/build/components/conversations.js +4 -0
- package/build/components/conversations.js.map +1 -1
- package/build/components/display/action_button.d.ts +8 -0
- package/build/components/display/action_button.d.ts.map +1 -0
- package/build/components/display/action_button.js +44 -0
- package/build/components/display/action_button.js.map +1 -0
- package/build/contexts/api_provider.js +2 -2
- package/build/contexts/api_provider.js.map +1 -1
- package/build/hooks/index.d.ts +2 -0
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use_api.d.ts +383 -0
- package/build/hooks/use_api.d.ts.map +1 -0
- package/build/hooks/use_api.js +40 -0
- package/build/hooks/use_api.js.map +1 -0
- package/build/hooks/use_api_client.d.ts +5 -3
- package/build/hooks/use_api_client.d.ts.map +1 -1
- package/build/hooks/use_api_client.js +1 -1
- package/build/hooks/use_api_client.js.map +1 -1
- package/build/hooks/use_chat_permissions.d.ts +172 -0
- package/build/hooks/use_chat_permissions.d.ts.map +1 -0
- package/build/hooks/use_chat_permissions.js +17 -0
- package/build/hooks/use_chat_permissions.js.map +1 -0
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +6 -5
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_suspense_api.d.ts +13 -4
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +1 -0
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/index.d.ts +3 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -2
- package/build/index.js.map +1 -1
- package/build/navigation/index.d.ts +123 -2
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +40 -4
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/screenLayout.d.ts.map +1 -1
- package/build/navigation/screenLayout.js +3 -6
- package/build/navigation/screenLayout.js.map +1 -1
- package/build/screens/create/conversation_create_screen.d.ts +9 -0
- package/build/screens/create/conversation_create_screen.d.ts.map +1 -0
- package/build/screens/create/conversation_create_screen.js +123 -0
- package/build/screens/create/conversation_create_screen.js.map +1 -0
- package/build/screens/create/conversation_filter_recipients_screen.d.ts +8 -0
- package/build/screens/create/conversation_filter_recipients_screen.d.ts.map +1 -0
- package/build/screens/create/conversation_filter_recipients_screen.js +52 -0
- package/build/screens/create/conversation_filter_recipients_screen.js.map +1 -0
- package/build/screens/create/conversation_select_recipients_screen.d.ts +8 -0
- package/build/screens/create/conversation_select_recipients_screen.d.ts.map +1 -0
- package/build/screens/create/conversation_select_recipients_screen.js +105 -0
- package/build/screens/create/conversation_select_recipients_screen.js.map +1 -0
- package/build/types/resources/app_grant.d.ts +6 -0
- package/build/types/resources/app_grant.d.ts.map +1 -0
- package/build/types/resources/app_grant.js +2 -0
- package/build/types/resources/app_grant.js.map +1 -0
- package/build/types/resources/groups/groups_group_resource.d.ts +12 -0
- package/build/types/resources/groups/groups_group_resource.d.ts.map +1 -0
- package/build/types/resources/groups/groups_group_resource.js +2 -0
- package/build/types/resources/groups/groups_group_resource.js.map +1 -0
- package/build/types/resources/groups/index.d.ts +2 -0
- package/build/types/resources/groups/index.d.ts.map +1 -0
- package/build/types/resources/groups/index.js +2 -0
- package/build/types/resources/groups/index.js.map +1 -0
- package/build/types/resources/index.d.ts +2 -0
- package/build/types/resources/index.d.ts.map +1 -1
- package/build/types/resources/index.js +2 -0
- package/build/types/resources/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/conversations.tsx +8 -0
- package/src/components/display/action_button.tsx +62 -0
- package/src/contexts/api_provider.tsx +2 -2
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use_api.ts +80 -0
- package/src/hooks/use_api_client.ts +13 -15
- package/src/hooks/use_chat_permissions.ts +20 -0
- package/src/hooks/use_conversation.ts +6 -5
- package/src/hooks/use_suspense_api.ts +16 -4
- package/src/index.tsx +3 -2
- package/src/navigation/index.tsx +46 -7
- package/src/navigation/screenLayout.tsx +3 -6
- package/src/screens/create/conversation_create_screen.tsx +148 -0
- package/src/screens/create/conversation_filter_recipients_screen.tsx +79 -0
- package/src/screens/create/conversation_select_recipients_screen.tsx +136 -0
- package/src/types/resources/app_grant.ts +6 -0
- package/src/types/resources/groups/groups_group_resource.ts +12 -0
- package/src/types/resources/groups/index.ts +1 -0
- package/src/types/resources/index.ts +2 -0
- package/build/contexts/index.d.ts +0 -3
- package/build/contexts/index.d.ts.map +0 -1
- package/build/contexts/index.js +0 -3
- package/build/contexts/index.js.map +0 -1
- package/src/contexts/index.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../src/components/conversations.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../src/components/conversations.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB,eAAO,MAAM,aAAa,yBA0EzB,CAAA"}
|
|
@@ -7,9 +7,12 @@ import { useConversationsJoltEvents } from '../hooks/use_conversation_jolt_event
|
|
|
7
7
|
import { useConversations } from '../hooks/use_conversations';
|
|
8
8
|
import { formatDatePreview } from '../utils/date';
|
|
9
9
|
import { AvatarGroup, Badge, Heading, Text, TextButton } from './display';
|
|
10
|
+
import { ActionButton } from './display/action_button';
|
|
11
|
+
import { useCanCreateConversations } from '../hooks/use_chat_permissions';
|
|
10
12
|
export const Conversations = () => {
|
|
11
13
|
const styles = useStyles();
|
|
12
14
|
const { conversations, fetchNextPage, refetch, isRefetching } = useConversations();
|
|
15
|
+
const canCreateConversations = useCanCreateConversations();
|
|
13
16
|
// TODO: Filter using the API
|
|
14
17
|
const nonEmptyConversations = conversations.filter(c => c.lastMessageTextPreview) || [];
|
|
15
18
|
const navigation = useNavigation();
|
|
@@ -41,6 +44,7 @@ export const Conversations = () => {
|
|
|
41
44
|
<UnreadCountBadge count={item.unreadCount}/>
|
|
42
45
|
</View>
|
|
43
46
|
</Pressable>)} onEndReached={() => fetchNextPage()}/>
|
|
47
|
+
<ActionButton visible={canCreateConversations} title="New conversation" onPress={() => navigation.navigate('Create')}/>
|
|
44
48
|
</View>);
|
|
45
49
|
};
|
|
46
50
|
const UnreadCountBadge = ({ count }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/components/conversations.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAA;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEzE,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAE1B,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,gBAAgB,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/components/conversations.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA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AAS,EAAE,CAAC;YACZ,UAAU,EAAE,YAAY;SACzB;QACD,gBAAgB,EAAE;YAChB,SAAS,EAAE,UAAU;YACrB,eAAe,EAAE,MAAM,CAAC,WAAW;YACnC,eAAe,EAAE,CAAC;YAClB,iBAAiB,EAAE,EAAE;YACrB,YAAY,EAAE,EAAE;YAChB,KAAK,EAAE,OAAO;SACf;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport { FlashList } from '@shopify/flash-list'\nimport React from 'react'\nimport { Pressable, StyleSheet, View } from 'react-native'\nimport { useTheme } from '../hooks'\nimport { useConversationsJoltEvents } from '../hooks/use_conversation_jolt_events'\nimport { useConversations } from '../hooks/use_conversations'\nimport { formatDatePreview } from '../utils/date'\nimport { AvatarGroup, Badge, Heading, Text, TextButton } from './display'\nimport { ActionButton } from './display/action_button'\nimport { useCanCreateConversations } from '../hooks/use_chat_permissions'\n\nexport const Conversations = () => {\n const styles = useStyles()\n\n const { conversations, fetchNextPage, refetch, isRefetching } = useConversations()\n const canCreateConversations = useCanCreateConversations()\n\n // TODO: Filter using the API\n const nonEmptyConversations = conversations.filter(c => c.lastMessageTextPreview) || []\n const navigation = useNavigation()\n\n useConversationsJoltEvents()\n\n return (\n <View style={styles.container}>\n <FlashList\n data={nonEmptyConversations}\n estimatedItemSize={97}\n contentContainerStyle={styles.contentContainer}\n onRefresh={refetch}\n refreshing={isRefetching}\n ListHeaderComponent={\n <View style={styles.header}>\n <Heading numberOfLines={1} variant=\"h2\">\n Conversations\n </Heading>\n <TextButton>Mark all read</TextButton>\n </View>\n }\n ListEmptyComponent={<Text>No conversations found</Text>}\n renderItem={({ item }) => (\n <Pressable\n style={styles.conversation}\n onPress={() =>\n navigation.navigate('Conversation', {\n conversation_id: item.id,\n chat_group_graph_id: item.id,\n })\n }\n >\n <AvatarGroup size=\"lg\" sourceUris={item.previewAvatarUrls || []} />\n <View style={styles.conversationBody}>\n <Heading numberOfLines={1} variant=\"h3\" style={styles.conversationTitle}>\n {item.title}\n </Heading>\n <Text style={styles.listItem} numberOfLines={2}>\n {item.lastMessageAuthorName}: {item.lastMessageTextPreview}\n </Text>\n <View style={styles.conversationBadges}>\n {item.badges?.map(badge => (\n <Badge\n key={badge.text}\n variant=\"meta\"\n productLogoName={badge.appName}\n label={badge.pcoResourceType}\n metaLabel={badge.text || ''}\n />\n ))}\n </View>\n </View>\n <View style={styles.conversationExtra}>\n <Text variant=\"secondary\">{formatDatePreview(item.lastMessageCreatedAt)}</Text>\n <UnreadCountBadge count={item.unreadCount} />\n </View>\n </Pressable>\n )}\n onEndReached={() => fetchNextPage()}\n />\n <ActionButton\n visible={canCreateConversations}\n title=\"New conversation\"\n onPress={() => navigation.navigate('Create')}\n />\n </View>\n )\n}\n\nconst UnreadCountBadge = ({ count }: { count: number }) => {\n const styles = useStyles()\n const displayCount = count > 99 ? '99+' : count\n\n if (count === 0) return null\n\n return (\n <Text variant=\"tertiary\" style={styles.unreadCountBadge}>\n {displayCount}\n </Text>\n )\n}\n\nconst useStyles = () => {\n const { colors } = useTheme()\n\n return StyleSheet.create({\n header: {\n flexDirection: 'row',\n justifyContent: 'space-between',\n paddingTop: 8,\n paddingBottom: 8,\n paddingHorizontal: 16,\n },\n container: { flex: 1 },\n contentContainer: { paddingVertical: 16 },\n listItem: { color: colors.fillColorNeutral020 },\n conversation: {\n flexDirection: 'row',\n gap: 8,\n borderBottomWidth: 1,\n borderBottomColor: colors.fillColorNeutral060,\n paddingTop: 4,\n paddingBottom: 12,\n paddingHorizontal: 16,\n },\n conversationTitle: {},\n conversationBody: {\n flex: 1,\n rowGap: 2,\n },\n conversationExtra: {\n rowGap: 2,\n },\n conversationBadges: {\n marginTop: 4,\n alignItems: 'flex-start',\n },\n unreadCountBadge: {\n alignSelf: 'flex-end',\n backgroundColor: colors.interaction,\n paddingVertical: 0,\n paddingHorizontal: 10,\n borderRadius: 24,\n color: 'white',\n },\n })\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const ActionButton: ({ visible, onPress, title, infoText, }: {
|
|
3
|
+
visible?: boolean;
|
|
4
|
+
onPress: () => void;
|
|
5
|
+
title: string;
|
|
6
|
+
infoText?: string;
|
|
7
|
+
}) => React.JSX.Element | null;
|
|
8
|
+
//# sourceMappingURL=action_button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action_button.d.ts","sourceRoot":"","sources":["../../../src/components/display/action_button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAQvC,eAAO,MAAM,YAAY,2CAKtB;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,6BAuBA,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Animated, LayoutAnimation, StyleSheet } from 'react-native';
|
|
3
|
+
import { Button } from './button';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import { useTheme } from '../../hooks';
|
|
7
|
+
import { Text } from './text';
|
|
8
|
+
export const ActionButton = ({ visible = true, onPress, title, infoText, }) => {
|
|
9
|
+
const styles = useStyles();
|
|
10
|
+
const [show, setShow] = useState(visible);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (show === visible)
|
|
13
|
+
return;
|
|
14
|
+
setShow(visible);
|
|
15
|
+
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
16
|
+
}, [show, visible]);
|
|
17
|
+
if (!visible)
|
|
18
|
+
return null;
|
|
19
|
+
return (<Animated.View style={styles.container}>
|
|
20
|
+
{Boolean(infoText) && (<Text style={styles.infoText} variant="tertiary">
|
|
21
|
+
{infoText}
|
|
22
|
+
</Text>)}
|
|
23
|
+
<Button variant="fill" size="lg" onPress={onPress} title={title}/>
|
|
24
|
+
</Animated.View>);
|
|
25
|
+
};
|
|
26
|
+
const useStyles = () => {
|
|
27
|
+
const { bottom } = useSafeAreaInsets();
|
|
28
|
+
const { colors } = useTheme();
|
|
29
|
+
return StyleSheet.create({
|
|
30
|
+
container: {
|
|
31
|
+
paddingVertical: 16,
|
|
32
|
+
paddingHorizontal: 24,
|
|
33
|
+
paddingBottom: bottom,
|
|
34
|
+
borderTopWidth: 1,
|
|
35
|
+
borderTopColor: colors.fillColorNeutral060,
|
|
36
|
+
gap: 16,
|
|
37
|
+
},
|
|
38
|
+
infoText: {
|
|
39
|
+
textAlign: 'center',
|
|
40
|
+
color: colors.textColorDefaultSecondary,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=action_button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action_button.js","sourceRoot":"","sources":["../../../src/components/display/action_button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,OAAO,GAAG,IAAI,EACd,OAAO,EACP,KAAK,EACL,QAAQ,GAMT,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MA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;SACR;QACD,QAAQ,EAAE;YACR,SAAS,EAAE,QAAQ;YACnB,KAAK,EAAE,MAAM,CAAC,yBAAyB;SACxC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import React, { useState } from 'react'\nimport { Animated, LayoutAnimation, StyleSheet } from 'react-native'\nimport { Button } from './button'\nimport { useEffect } from 'react'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { useTheme } from '../../hooks'\nimport { Text } from './text'\n\nexport const ActionButton = ({\n visible = true,\n onPress,\n title,\n infoText,\n}: {\n visible?: boolean\n onPress: () => void\n title: string\n infoText?: string\n}) => {\n const styles = useStyles()\n const [show, setShow] = useState(visible)\n\n useEffect(() => {\n if (show === visible) return\n\n setShow(visible)\n LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)\n }, [show, visible])\n\n if (!visible) return null\n\n return (\n <Animated.View style={styles.container}>\n {Boolean(infoText) && (\n <Text style={styles.infoText} variant=\"tertiary\">\n {infoText}\n </Text>\n )}\n <Button variant=\"fill\" size=\"lg\" onPress={onPress} title={title} />\n </Animated.View>\n )\n}\n\nconst useStyles = () => {\n const { bottom } = useSafeAreaInsets()\n const { colors } = useTheme()\n\n return StyleSheet.create({\n container: {\n paddingVertical: 16,\n paddingHorizontal: 24,\n paddingBottom: bottom,\n borderTopWidth: 1,\n borderTopColor: colors.fillColorNeutral060,\n gap: 16,\n },\n infoText: {\n textAlign: 'center',\n color: colors.textColorDefaultSecondary,\n },\n })\n}\n"]}
|
|
@@ -7,8 +7,8 @@ const defaultQueryFn = ({ queryKey }) => {
|
|
|
7
7
|
if (!apiClient) {
|
|
8
8
|
throw new Error('No token present');
|
|
9
9
|
}
|
|
10
|
-
const [url, data, headers] = queryKey;
|
|
11
|
-
return apiClient.
|
|
10
|
+
const [url, data, headers, app = 'chat'] = queryKey;
|
|
11
|
+
return apiClient[app].get({ url, data, headers });
|
|
12
12
|
};
|
|
13
13
|
export const queryClient = new QueryClient({
|
|
14
14
|
defaultOptions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE5D,OAAO,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAA;AAE9D,OAAO,EAAa,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEjE,IAAI,SAAgC,CAAA;AAEpC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAA0B,EAAE,EAAE;IAC9D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,QAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE5D,OAAO,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAA;AAE9D,OAAO,EAAa,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEjE,IAAI,SAAgC,CAAA;AAEpC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAA0B,EAAE,EAAE;IAC9D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,GAAG,MAAM,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MAAM,GAAG,GAAG,MAAM,CAAI,KAAK,CAAC,CAAA;IAE5B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAA;IACrB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC","sourcesContent":["import { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-query'\nimport React, { useContext, useEffect, useRef } from 'react'\nimport { ViewProps } from 'react-native'\nimport { ChatContext, ChatContextValue } from './chat_context'\nimport { RequestQueryKey } from '../hooks'\nimport { ApiClient, useApiClient } from '../hooks/use_api_client'\n\nlet apiClient: ApiClient | undefined\n\nconst defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {\n if (!apiClient) {\n throw new Error('No token present')\n }\n\n const [url, data, headers, app = 'chat'] = queryKey as RequestQueryKey\n\n return apiClient[app].get({ url, data, headers })\n}\n\nexport const queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n queryFn: defaultQueryFn,\n retry: 3,\n },\n },\n})\n\nexport function ApiProvider({ children }: ViewProps) {\n const { token, env } = useContext(ChatContext)\n const sessionChanged = useSessionChanged({ token, env })\n\n apiClient = useApiClient()\n\n useEffect(() => {\n if (!sessionChanged) return\n\n queryClient.clear()\n }, [sessionChanged])\n\n return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>\n}\n\nfunction useSessionChanged(value: Pick<ChatContextValue, 'token' | 'env'>): boolean {\n const { token: newToken, env: newEnv } = value\n const { token: prevToken, env: prevEnv } = usePrevious<typeof value>(value)\n\n return Boolean(prevToken && newToken !== prevToken) || Boolean(prevEnv && newEnv !== prevEnv)\n}\n\nfunction usePrevious<T>(value) {\n const ref = useRef<T>(value)\n\n useEffect(() => {\n ref.current = value\n }, [value])\n\n return ref.current\n}\n"]}
|
package/build/hooks/index.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ export * from './use_suspense_api';
|
|
|
4
4
|
export * from './use_current_person';
|
|
5
5
|
export * from './use_font_scale';
|
|
6
6
|
export * from './use_create_android_ripple_color';
|
|
7
|
+
export * from './use_chat_permissions';
|
|
8
|
+
export * from './use_api_client';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA"}
|
package/build/hooks/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export * from './use_suspense_api';
|
|
|
4
4
|
export * from './use_current_person';
|
|
5
5
|
export * from './use_font_scale';
|
|
6
6
|
export * from './use_create_android_ripple_color';
|
|
7
|
+
export * from './use_chat_permissions';
|
|
8
|
+
export * from './use_api_client';
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA","sourcesContent":["export * from './use_async_storage'\nexport * from './use_theme'\nexport * from './use_suspense_api'\nexport * from './use_current_person'\nexport * from './use_font_scale'\nexport * from './use_create_android_ripple_color'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './use_async_storage'\nexport * from './use_theme'\nexport * from './use_suspense_api'\nexport * from './use_current_person'\nexport * from './use_font_scale'\nexport * from './use_create_android_ripple_color'\nexport * from './use_chat_permissions'\nexport * from './use_api_client'\n"]}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { AnyUseSuspenseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query';
|
|
2
|
+
import { ApiCollection, ApiResource, ResourceObject } from '../types';
|
|
3
|
+
import { GetRequest } from '../utils/client/types';
|
|
4
|
+
interface SuspenseGetOptions extends GetRequest {
|
|
5
|
+
app?: 'chat' | 'groups';
|
|
6
|
+
}
|
|
7
|
+
export declare const useApiGet: <T extends ResourceObject | ResourceObject[]>(args: SuspenseGetOptions) => {
|
|
8
|
+
error: Response;
|
|
9
|
+
isError: true;
|
|
10
|
+
isPending: false;
|
|
11
|
+
isLoading: false;
|
|
12
|
+
isLoadingError: false;
|
|
13
|
+
isRefetchError: true;
|
|
14
|
+
isSuccess: false;
|
|
15
|
+
isPlaceholderData: false;
|
|
16
|
+
status: "error";
|
|
17
|
+
dataUpdatedAt: number;
|
|
18
|
+
errorUpdatedAt: number;
|
|
19
|
+
failureCount: number;
|
|
20
|
+
failureReason: Response | null;
|
|
21
|
+
errorUpdateCount: number;
|
|
22
|
+
isFetched: boolean;
|
|
23
|
+
isFetchedAfterMount: boolean;
|
|
24
|
+
isFetching: boolean;
|
|
25
|
+
isInitialLoading: boolean;
|
|
26
|
+
isPaused: boolean;
|
|
27
|
+
isRefetching: boolean;
|
|
28
|
+
isStale: boolean;
|
|
29
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, Response>>;
|
|
30
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
31
|
+
promise: Promise<ApiResource<T>>;
|
|
32
|
+
data?: T | undefined;
|
|
33
|
+
links?: Record<string, string> | undefined;
|
|
34
|
+
meta?: Record<string, unknown> | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
error: null;
|
|
37
|
+
isError: false;
|
|
38
|
+
isPending: false;
|
|
39
|
+
isLoading: false;
|
|
40
|
+
isLoadingError: false;
|
|
41
|
+
isRefetchError: false;
|
|
42
|
+
isSuccess: true;
|
|
43
|
+
isPlaceholderData: false;
|
|
44
|
+
status: "success";
|
|
45
|
+
dataUpdatedAt: number;
|
|
46
|
+
errorUpdatedAt: number;
|
|
47
|
+
failureCount: number;
|
|
48
|
+
failureReason: Response | null;
|
|
49
|
+
errorUpdateCount: number;
|
|
50
|
+
isFetched: boolean;
|
|
51
|
+
isFetchedAfterMount: boolean;
|
|
52
|
+
isFetching: boolean;
|
|
53
|
+
isInitialLoading: boolean;
|
|
54
|
+
isPaused: boolean;
|
|
55
|
+
isRefetching: boolean;
|
|
56
|
+
isStale: boolean;
|
|
57
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, Response>>;
|
|
58
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
59
|
+
promise: Promise<ApiResource<T>>;
|
|
60
|
+
data?: T | undefined;
|
|
61
|
+
links?: Record<string, string> | undefined;
|
|
62
|
+
meta?: Record<string, unknown> | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
error: Response;
|
|
65
|
+
isError: true;
|
|
66
|
+
isPending: false;
|
|
67
|
+
isLoading: false;
|
|
68
|
+
isLoadingError: true;
|
|
69
|
+
isRefetchError: false;
|
|
70
|
+
isSuccess: false;
|
|
71
|
+
isPlaceholderData: false;
|
|
72
|
+
status: "error";
|
|
73
|
+
dataUpdatedAt: number;
|
|
74
|
+
errorUpdatedAt: number;
|
|
75
|
+
failureCount: number;
|
|
76
|
+
failureReason: Response | null;
|
|
77
|
+
errorUpdateCount: number;
|
|
78
|
+
isFetched: boolean;
|
|
79
|
+
isFetchedAfterMount: boolean;
|
|
80
|
+
isFetching: boolean;
|
|
81
|
+
isInitialLoading: boolean;
|
|
82
|
+
isPaused: boolean;
|
|
83
|
+
isRefetching: boolean;
|
|
84
|
+
isStale: boolean;
|
|
85
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, Response>>;
|
|
86
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
87
|
+
promise: Promise<ApiResource<T>>;
|
|
88
|
+
data?: T | undefined;
|
|
89
|
+
links?: Record<string, string> | undefined;
|
|
90
|
+
meta?: Record<string, unknown> | undefined;
|
|
91
|
+
} | {
|
|
92
|
+
error: null;
|
|
93
|
+
isError: false;
|
|
94
|
+
isPending: true;
|
|
95
|
+
isLoading: true;
|
|
96
|
+
isLoadingError: false;
|
|
97
|
+
isRefetchError: false;
|
|
98
|
+
isSuccess: false;
|
|
99
|
+
isPlaceholderData: false;
|
|
100
|
+
status: "pending";
|
|
101
|
+
dataUpdatedAt: number;
|
|
102
|
+
errorUpdatedAt: number;
|
|
103
|
+
failureCount: number;
|
|
104
|
+
failureReason: Response | null;
|
|
105
|
+
errorUpdateCount: number;
|
|
106
|
+
isFetched: boolean;
|
|
107
|
+
isFetchedAfterMount: boolean;
|
|
108
|
+
isFetching: boolean;
|
|
109
|
+
isInitialLoading: boolean;
|
|
110
|
+
isPaused: boolean;
|
|
111
|
+
isRefetching: boolean;
|
|
112
|
+
isStale: boolean;
|
|
113
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, Response>>;
|
|
114
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
115
|
+
promise: Promise<ApiResource<T>>;
|
|
116
|
+
data?: T | undefined;
|
|
117
|
+
links?: Record<string, string> | undefined;
|
|
118
|
+
meta?: Record<string, unknown> | undefined;
|
|
119
|
+
} | {
|
|
120
|
+
error: null;
|
|
121
|
+
isError: false;
|
|
122
|
+
isPending: true;
|
|
123
|
+
isLoadingError: false;
|
|
124
|
+
isRefetchError: false;
|
|
125
|
+
isSuccess: false;
|
|
126
|
+
isPlaceholderData: false;
|
|
127
|
+
status: "pending";
|
|
128
|
+
dataUpdatedAt: number;
|
|
129
|
+
errorUpdatedAt: number;
|
|
130
|
+
failureCount: number;
|
|
131
|
+
failureReason: Response | null;
|
|
132
|
+
errorUpdateCount: number;
|
|
133
|
+
isFetched: boolean;
|
|
134
|
+
isFetchedAfterMount: boolean;
|
|
135
|
+
isFetching: boolean;
|
|
136
|
+
isLoading: boolean;
|
|
137
|
+
isInitialLoading: boolean;
|
|
138
|
+
isPaused: boolean;
|
|
139
|
+
isRefetching: boolean;
|
|
140
|
+
isStale: boolean;
|
|
141
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, Response>>;
|
|
142
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
143
|
+
promise: Promise<ApiResource<T>>;
|
|
144
|
+
data?: T | undefined;
|
|
145
|
+
links?: Record<string, string> | undefined;
|
|
146
|
+
meta?: Record<string, unknown> | undefined;
|
|
147
|
+
} | {
|
|
148
|
+
isError: false;
|
|
149
|
+
error: null;
|
|
150
|
+
isPending: false;
|
|
151
|
+
isLoading: false;
|
|
152
|
+
isLoadingError: false;
|
|
153
|
+
isRefetchError: false;
|
|
154
|
+
isSuccess: true;
|
|
155
|
+
isPlaceholderData: true;
|
|
156
|
+
status: "success";
|
|
157
|
+
dataUpdatedAt: number;
|
|
158
|
+
errorUpdatedAt: number;
|
|
159
|
+
failureCount: number;
|
|
160
|
+
failureReason: Response | null;
|
|
161
|
+
errorUpdateCount: number;
|
|
162
|
+
isFetched: boolean;
|
|
163
|
+
isFetchedAfterMount: boolean;
|
|
164
|
+
isFetching: boolean;
|
|
165
|
+
isInitialLoading: boolean;
|
|
166
|
+
isPaused: boolean;
|
|
167
|
+
isRefetching: boolean;
|
|
168
|
+
isStale: boolean;
|
|
169
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, Response>>;
|
|
170
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
171
|
+
promise: Promise<ApiResource<T>>;
|
|
172
|
+
data?: T | undefined;
|
|
173
|
+
links?: Record<string, string> | undefined;
|
|
174
|
+
meta?: Record<string, unknown> | undefined;
|
|
175
|
+
};
|
|
176
|
+
export type SuspensePaginatorOptions = Omit<AnyUseSuspenseInfiniteQueryOptions, 'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'>;
|
|
177
|
+
export declare const useApiPaginator: <T extends ResourceObject>(args: SuspenseGetOptions, opts?: SuspensePaginatorOptions) => {
|
|
178
|
+
data: T[];
|
|
179
|
+
error: Response;
|
|
180
|
+
isError: true;
|
|
181
|
+
isPending: false;
|
|
182
|
+
isLoading: false;
|
|
183
|
+
isLoadingError: false;
|
|
184
|
+
isRefetchError: true;
|
|
185
|
+
isSuccess: false;
|
|
186
|
+
isPlaceholderData: false;
|
|
187
|
+
status: "error";
|
|
188
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
189
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
190
|
+
hasNextPage: boolean;
|
|
191
|
+
hasPreviousPage: boolean;
|
|
192
|
+
isFetchNextPageError: boolean;
|
|
193
|
+
isFetchingNextPage: boolean;
|
|
194
|
+
isFetchPreviousPageError: boolean;
|
|
195
|
+
isFetchingPreviousPage: boolean;
|
|
196
|
+
dataUpdatedAt: number;
|
|
197
|
+
errorUpdatedAt: number;
|
|
198
|
+
failureCount: number;
|
|
199
|
+
failureReason: Response | null;
|
|
200
|
+
errorUpdateCount: number;
|
|
201
|
+
isFetched: boolean;
|
|
202
|
+
isFetchedAfterMount: boolean;
|
|
203
|
+
isFetching: boolean;
|
|
204
|
+
isInitialLoading: boolean;
|
|
205
|
+
isPaused: boolean;
|
|
206
|
+
isRefetching: boolean;
|
|
207
|
+
isStale: boolean;
|
|
208
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
209
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
210
|
+
promise: Promise<InfiniteData<ApiCollection<T>, unknown>>;
|
|
211
|
+
} | {
|
|
212
|
+
data: T[];
|
|
213
|
+
error: null;
|
|
214
|
+
isError: false;
|
|
215
|
+
isPending: false;
|
|
216
|
+
isLoading: false;
|
|
217
|
+
isLoadingError: false;
|
|
218
|
+
isRefetchError: false;
|
|
219
|
+
isFetchNextPageError: false;
|
|
220
|
+
isFetchPreviousPageError: false;
|
|
221
|
+
isSuccess: true;
|
|
222
|
+
isPlaceholderData: false;
|
|
223
|
+
status: "success";
|
|
224
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
225
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
226
|
+
hasNextPage: boolean;
|
|
227
|
+
hasPreviousPage: boolean;
|
|
228
|
+
isFetchingNextPage: boolean;
|
|
229
|
+
isFetchingPreviousPage: boolean;
|
|
230
|
+
dataUpdatedAt: number;
|
|
231
|
+
errorUpdatedAt: number;
|
|
232
|
+
failureCount: number;
|
|
233
|
+
failureReason: Response | null;
|
|
234
|
+
errorUpdateCount: number;
|
|
235
|
+
isFetched: boolean;
|
|
236
|
+
isFetchedAfterMount: boolean;
|
|
237
|
+
isFetching: boolean;
|
|
238
|
+
isInitialLoading: boolean;
|
|
239
|
+
isPaused: boolean;
|
|
240
|
+
isRefetching: boolean;
|
|
241
|
+
isStale: boolean;
|
|
242
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
243
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
244
|
+
promise: Promise<InfiniteData<ApiCollection<T>, unknown>>;
|
|
245
|
+
} | {
|
|
246
|
+
data: T[];
|
|
247
|
+
error: Response;
|
|
248
|
+
isError: true;
|
|
249
|
+
isPending: false;
|
|
250
|
+
isLoading: false;
|
|
251
|
+
isLoadingError: true;
|
|
252
|
+
isRefetchError: false;
|
|
253
|
+
isFetchNextPageError: false;
|
|
254
|
+
isFetchPreviousPageError: false;
|
|
255
|
+
isSuccess: false;
|
|
256
|
+
isPlaceholderData: false;
|
|
257
|
+
status: "error";
|
|
258
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
259
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
260
|
+
hasNextPage: boolean;
|
|
261
|
+
hasPreviousPage: boolean;
|
|
262
|
+
isFetchingNextPage: boolean;
|
|
263
|
+
isFetchingPreviousPage: boolean;
|
|
264
|
+
dataUpdatedAt: number;
|
|
265
|
+
errorUpdatedAt: number;
|
|
266
|
+
failureCount: number;
|
|
267
|
+
failureReason: Response | null;
|
|
268
|
+
errorUpdateCount: number;
|
|
269
|
+
isFetched: boolean;
|
|
270
|
+
isFetchedAfterMount: boolean;
|
|
271
|
+
isFetching: boolean;
|
|
272
|
+
isInitialLoading: boolean;
|
|
273
|
+
isPaused: boolean;
|
|
274
|
+
isRefetching: boolean;
|
|
275
|
+
isStale: boolean;
|
|
276
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
277
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
278
|
+
promise: Promise<InfiniteData<ApiCollection<T>, unknown>>;
|
|
279
|
+
} | {
|
|
280
|
+
data: T[];
|
|
281
|
+
error: null;
|
|
282
|
+
isError: false;
|
|
283
|
+
isPending: true;
|
|
284
|
+
isLoading: true;
|
|
285
|
+
isLoadingError: false;
|
|
286
|
+
isRefetchError: false;
|
|
287
|
+
isFetchNextPageError: false;
|
|
288
|
+
isFetchPreviousPageError: false;
|
|
289
|
+
isSuccess: false;
|
|
290
|
+
isPlaceholderData: false;
|
|
291
|
+
status: "pending";
|
|
292
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
293
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
294
|
+
hasNextPage: boolean;
|
|
295
|
+
hasPreviousPage: boolean;
|
|
296
|
+
isFetchingNextPage: boolean;
|
|
297
|
+
isFetchingPreviousPage: boolean;
|
|
298
|
+
dataUpdatedAt: number;
|
|
299
|
+
errorUpdatedAt: number;
|
|
300
|
+
failureCount: number;
|
|
301
|
+
failureReason: Response | null;
|
|
302
|
+
errorUpdateCount: number;
|
|
303
|
+
isFetched: boolean;
|
|
304
|
+
isFetchedAfterMount: boolean;
|
|
305
|
+
isFetching: boolean;
|
|
306
|
+
isInitialLoading: boolean;
|
|
307
|
+
isPaused: boolean;
|
|
308
|
+
isRefetching: boolean;
|
|
309
|
+
isStale: boolean;
|
|
310
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
311
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
312
|
+
promise: Promise<InfiniteData<ApiCollection<T>, unknown>>;
|
|
313
|
+
} | {
|
|
314
|
+
data: T[];
|
|
315
|
+
error: null;
|
|
316
|
+
isError: false;
|
|
317
|
+
isPending: true;
|
|
318
|
+
isLoadingError: false;
|
|
319
|
+
isRefetchError: false;
|
|
320
|
+
isFetchNextPageError: false;
|
|
321
|
+
isFetchPreviousPageError: false;
|
|
322
|
+
isSuccess: false;
|
|
323
|
+
isPlaceholderData: false;
|
|
324
|
+
status: "pending";
|
|
325
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
326
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
327
|
+
hasNextPage: boolean;
|
|
328
|
+
hasPreviousPage: boolean;
|
|
329
|
+
isFetchingNextPage: boolean;
|
|
330
|
+
isFetchingPreviousPage: boolean;
|
|
331
|
+
dataUpdatedAt: number;
|
|
332
|
+
errorUpdatedAt: number;
|
|
333
|
+
failureCount: number;
|
|
334
|
+
failureReason: Response | null;
|
|
335
|
+
errorUpdateCount: number;
|
|
336
|
+
isFetched: boolean;
|
|
337
|
+
isFetchedAfterMount: boolean;
|
|
338
|
+
isFetching: boolean;
|
|
339
|
+
isLoading: boolean;
|
|
340
|
+
isInitialLoading: boolean;
|
|
341
|
+
isPaused: boolean;
|
|
342
|
+
isRefetching: boolean;
|
|
343
|
+
isStale: boolean;
|
|
344
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
345
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
346
|
+
promise: Promise<InfiniteData<ApiCollection<T>, unknown>>;
|
|
347
|
+
} | {
|
|
348
|
+
data: T[];
|
|
349
|
+
isError: false;
|
|
350
|
+
error: null;
|
|
351
|
+
isPending: false;
|
|
352
|
+
isLoading: false;
|
|
353
|
+
isLoadingError: false;
|
|
354
|
+
isRefetchError: false;
|
|
355
|
+
isSuccess: true;
|
|
356
|
+
isPlaceholderData: true;
|
|
357
|
+
isFetchNextPageError: false;
|
|
358
|
+
isFetchPreviousPageError: false;
|
|
359
|
+
status: "success";
|
|
360
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
361
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
362
|
+
hasNextPage: boolean;
|
|
363
|
+
hasPreviousPage: boolean;
|
|
364
|
+
isFetchingNextPage: boolean;
|
|
365
|
+
isFetchingPreviousPage: boolean;
|
|
366
|
+
dataUpdatedAt: number;
|
|
367
|
+
errorUpdatedAt: number;
|
|
368
|
+
failureCount: number;
|
|
369
|
+
failureReason: Response | null;
|
|
370
|
+
errorUpdateCount: number;
|
|
371
|
+
isFetched: boolean;
|
|
372
|
+
isFetchedAfterMount: boolean;
|
|
373
|
+
isFetching: boolean;
|
|
374
|
+
isInitialLoading: boolean;
|
|
375
|
+
isPaused: boolean;
|
|
376
|
+
isRefetching: boolean;
|
|
377
|
+
isStale: boolean;
|
|
378
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ApiCollection<T>, unknown>, Response>>;
|
|
379
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
380
|
+
promise: Promise<InfiniteData<ApiCollection<T>, unknown>>;
|
|
381
|
+
};
|
|
382
|
+
export {};
|
|
383
|
+
//# sourceMappingURL=use_api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_api.d.ts","sourceRoot":"","sources":["../../src/hooks/use_api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,YAAY,EAGb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,UAAU,EAAe,MAAM,uBAAuB,CAAA;AAI/D,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;CACxB;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,EAAE,QAC7D,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASzB,CAAA;AAOD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,kCAAkC,EAClC,kBAAkB,GAAG,kBAAkB,GAAG,SAAS,GAAG,UAAU,CACjE,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,cAAc,QAChD,kBAAkB,SACjB,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwChC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useInfiniteQuery, useQuery, } from '@tanstack/react-query';
|
|
2
|
+
import { useApiClient } from './use_api_client';
|
|
3
|
+
import { getRequestQueryKey } from './use_suspense_api';
|
|
4
|
+
export const useApiGet = (args) => {
|
|
5
|
+
const { data, ...query } = useQuery({
|
|
6
|
+
queryKey: getRequestQueryKey(args),
|
|
7
|
+
});
|
|
8
|
+
return { ...data, ...query };
|
|
9
|
+
};
|
|
10
|
+
export const useApiPaginator = (args, opts) => {
|
|
11
|
+
const apiClient = useApiClient();
|
|
12
|
+
const query = useInfiniteQuery({
|
|
13
|
+
queryKey: getRequestQueryKey(args),
|
|
14
|
+
queryFn: ({ pageParam }) => {
|
|
15
|
+
const pageParmWhere = pageParam?.where || {};
|
|
16
|
+
const argsWhere = args.data.where || {};
|
|
17
|
+
const where = { ...argsWhere, ...pageParmWhere };
|
|
18
|
+
const offset = pageParam?.offset || args.data.offset;
|
|
19
|
+
const data = { ...args.data, where, offset };
|
|
20
|
+
return apiClient.chat.get({
|
|
21
|
+
url: args.url,
|
|
22
|
+
data,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
initialPageParam: {},
|
|
26
|
+
getNextPageParam: lastPage => {
|
|
27
|
+
const next = lastPage.meta?.next || {};
|
|
28
|
+
const { offset, idLt } = next;
|
|
29
|
+
if (idLt)
|
|
30
|
+
return { where: { id_lt: idLt } };
|
|
31
|
+
if (offset)
|
|
32
|
+
return { offset: Number(offset) };
|
|
33
|
+
return undefined;
|
|
34
|
+
},
|
|
35
|
+
...(opts || {}),
|
|
36
|
+
});
|
|
37
|
+
const data = query.data?.pages.flatMap(page => page.data) || [];
|
|
38
|
+
return { ...query, data };
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=use_api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_api.js","sourceRoot":"","sources":["../../src/hooks/use_api.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAChB,QAAQ,GACT,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAMvD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,IAAwB,EACxB,EAAE;IAGF,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG,QAAQ,CAAqB;QACtD,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACnC,CAAC,CAAA;IAEF,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAA;AAC9B,CAAC,CAAA;AAYD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,IAAwB,EACxB,IAA+B,EAC/B,EAAE;IACF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,KAAK,GAAG,gBAAgB,CAM5B;QACA,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;QAClC,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;YACzB,MAAM,aAAa,GAAG,SAAS,EAAE,KAAK,IAAI,EAAE,CAAA;YAC5C,MAAM,S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, ApiResource, ResourceObject } from '../types'\nimport { GetRequest, RequestData } from '../utils/client/types'\nimport { useApiClient } from './use_api_client'\nimport { getRequestQueryKey } from './use_suspense_api'\n\ninterface SuspenseGetOptions extends GetRequest {\n app?: 'chat' | 'groups'\n}\n\nexport const useApiGet = <T extends ResourceObject | ResourceObject[]>(\n args: SuspenseGetOptions\n) => {\n type Resource = ApiResource<T>\n\n const { data, ...query } = useQuery<Resource, Response>({\n queryKey: getRequestQueryKey(args),\n })\n\n return { ...data, ...query }\n}\n\ntype NextMeta = Partial<{\n offset: string\n idLt: string\n}>\n\nexport type SuspensePaginatorOptions = Omit<\n AnyUseSuspenseInfiniteQueryOptions,\n 'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'\n>\n\nexport const useApiPaginator = <T extends ResourceObject>(\n args: SuspenseGetOptions,\n opts?: SuspensePaginatorOptions\n) => {\n const apiClient = useApiClient()\n const query = useInfiniteQuery<\n ApiCollection<T>,\n Response,\n InfiniteData<ApiCollection<T>>,\n any,\n Partial<RequestData> | undefined\n >({\n queryKey: getRequestQueryKey(args),\n queryFn: ({ pageParam }) => {\n const pageParmWhere = pageParam?.where || {}\n const argsWhere = args.data.where || {}\n const where = { ...argsWhere, ...pageParmWhere }\n\n const offset = pageParam?.offset || args.data.offset\n const data = { ...args.data, where, offset }\n\n return apiClient.chat.get({\n url: args.url,\n data,\n })\n },\n initialPageParam: {} as Partial<RequestData>,\n getNextPageParam: lastPage => {\n const next: NextMeta = lastPage.meta?.next || {}\n const { offset, idLt } = next\n\n if (idLt) return { where: { id_lt: idLt } }\n if (offset) return { offset: Number(offset) }\n\n return undefined\n },\n ...(opts || {}),\n })\n\n const data: T[] = query.data?.pages.flatMap(page => page.data) || []\n\n return { ...query, data }\n}\n"]}
|