@planningcenter/chat-react-native 1.4.2-rc.1 → 1.5.0-rc.0
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/contexts/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +3 -14
- package/build/contexts/api_provider.js.map +1 -1
- package/build/screens/display.d.ts.map +1 -1
- package/build/screens/display.js +5 -4
- package/build/screens/display.js.map +1 -1
- package/build/utils/api.d.ts +9 -0
- package/build/utils/api.d.ts.map +1 -0
- package/build/utils/api.js +36 -0
- package/build/utils/api.js.map +1 -0
- package/build/utils/space.d.ts +3 -0
- package/build/utils/space.d.ts.map +1 -0
- package/build/utils/space.js +22 -0
- package/build/utils/space.js.map +1 -0
- package/package.json +7 -5
- package/src/__tests__/utils/space.tsx +60 -0
- package/src/contexts/api_provider.tsx +4 -17
- package/src/screens/display.tsx +5 -4
- package/src/utils/api.ts +47 -0
- package/src/utils/space.ts +39 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiC,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAA;AAqB/C,eAAO,MAAM,WAAW,aAMtB,CAAA;AAEF,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAkB,EAClB,KAAK,EACL,cAAc,GACf,EAAE,SAAS,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAAC,cAAc,EAAE,MAAM,IAAI,CAAA;CAAE,qBAU3E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
2
|
import React, { useEffect } from 'react';
|
|
3
|
+
import apiRequest from '../utils/api';
|
|
3
4
|
import { session } from '../utils/session';
|
|
4
5
|
let handleTokenExpired;
|
|
5
6
|
const defaultQueryFn = ({ queryKey }) => {
|
|
@@ -7,13 +8,8 @@ const defaultQueryFn = ({ queryKey }) => {
|
|
|
7
8
|
throw new Error('No token present');
|
|
8
9
|
}
|
|
9
10
|
const url = `${session.baseUrl}${queryKey[0]}`;
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
Authorization: `Bearer ${session.token?.access_token}`,
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
.then(validateResponse)
|
|
16
|
-
.then(response => response.json())
|
|
11
|
+
return apiRequest(url)
|
|
12
|
+
.then(r => r.json)
|
|
17
13
|
.catch(error => {
|
|
18
14
|
if (error.message === 'Token expired') {
|
|
19
15
|
handleTokenExpired();
|
|
@@ -37,11 +33,4 @@ export function ApiProvider({ children, env = 'production', token, onTokenExpire
|
|
|
37
33
|
}, [env, token]);
|
|
38
34
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
|
39
35
|
}
|
|
40
|
-
const validateResponse = (response) => {
|
|
41
|
-
const isExpired = response.status === 401;
|
|
42
|
-
if (isExpired) {
|
|
43
|
-
throw new Error('Token expired');
|
|
44
|
-
}
|
|
45
|
-
return response;
|
|
46
|
-
};
|
|
47
36
|
//# sourceMappingURL=api_provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AACA,OAAO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AC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IAEhB,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,CAAA;AACnF,CAAC","sourcesContent":["import { JSONAPIResponse } from '@planningcenter/chat-core'\nimport { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-query'\nimport React, { useEffect } from 'react'\nimport { ViewProps } from 'react-native'\nimport { OAuthToken } from '../types'\nimport apiRequest from '../utils/api'\nimport { ENV, session } from '../utils/session'\n\nlet handleTokenExpired: () => void\n\nconst defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {\n if (!session.token) {\n throw new Error('No token present')\n }\n\n const url = `${session.baseUrl}${queryKey[0]}`\n\n return apiRequest<JSONAPIResponse>(url)\n .then(r => r.json)\n .catch(error => {\n if (error.message === 'Token expired') {\n handleTokenExpired()\n }\n return null\n })\n}\n\nexport const queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n queryFn: defaultQueryFn,\n },\n },\n})\n\nexport function ApiProvider({\n children,\n env = 'production',\n token,\n onTokenExpired,\n}: ViewProps & { env?: ENV; token?: OAuthToken; onTokenExpired: () => void }) {\n session.env = env\n session.token = token\n handleTokenExpired = onTokenExpired\n\n useEffect(() => {\n queryClient.invalidateQueries()\n }, [env, token])\n\n return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../src/screens/display.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../src/screens/display.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,wBAAgB,aAAa,sBA2B5B"}
|
package/build/screens/display.js
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { ScrollView, StyleSheet, View } from 'react-native';
|
|
3
3
|
import { useTheme } from '../hooks';
|
|
4
4
|
import { Image, Spinner, Text } from '../components/display';
|
|
5
|
+
import { space } from '../utils/space';
|
|
5
6
|
export function DisplayScreen() {
|
|
6
7
|
const styles = useStyles();
|
|
7
8
|
return (<ScrollView contentContainerStyle={styles.container} style={styles.scrollView}>
|
|
@@ -28,18 +29,18 @@ const useStyles = () => {
|
|
|
28
29
|
const { colors } = useTheme();
|
|
29
30
|
return StyleSheet.create({
|
|
30
31
|
scrollView: { flex: 1, backgroundColor: colors.fillColorNeutral090 },
|
|
31
|
-
container: { gap:
|
|
32
|
+
container: { gap: space(2), padding: space(3) },
|
|
32
33
|
listItem: { color: colors.fillColorNeutral020 },
|
|
33
34
|
row: {
|
|
34
|
-
gap:
|
|
35
|
+
gap: space(2),
|
|
35
36
|
flexDirection: 'row',
|
|
36
37
|
alignItems: 'center',
|
|
37
38
|
justifyContent: 'center',
|
|
38
39
|
flexWrap: 'wrap',
|
|
39
40
|
},
|
|
40
|
-
column: { gap:
|
|
41
|
+
column: { gap: space(4) },
|
|
41
42
|
spinnerContainer: {
|
|
42
|
-
height:
|
|
43
|
+
height: space(2.5),
|
|
43
44
|
},
|
|
44
45
|
image: {
|
|
45
46
|
width: 100,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../src/screens/display.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../src/screens/display.tsx"],"names":[],"mappings":"AAAA,OAA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AA,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CACzC;UAAA,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,CACvC;UAAA,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,CACzC;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,IAAI,CACR;IAAA,EAAE,UAAU,CAAC,CACd,CAAA;AACH,CAAC;AAED,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE7B,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,mBAAmB,EAAE;QACpE,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QAC/C,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,mBAAmB,EAAE;QAC/C,GAAG,EAAE;YACH,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;YACb,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;YACxB,QAAQ,EAAE,MAAM;SACjB;QACD,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QACzB,gBAAgB,EAAE;YAChB,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC;SACnB;QACD,KAAK,EAAE;YACL,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;SACZ;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import React from 'react'\nimport { ScrollView, StyleSheet, View } from 'react-native'\nimport { useTheme } from '../hooks'\nimport { Image, Spinner, Text } from '../components/display'\nimport { space } from '../utils/space'\n\nexport function DisplayScreen() {\n const styles = useStyles()\n\n return (\n <ScrollView contentContainerStyle={styles.container} style={styles.scrollView}>\n <View style={styles.column}>\n <View style={[styles.row, styles.spinnerContainer]}>\n <Spinner size={24} />\n </View>\n <View style={styles.row}>\n <Image source={{ uri: 'https://broken.url' }} style={styles.image} />\n <Image\n source={{\n uri: 'https://picsum.photos/seed/picsum/200',\n }}\n style={styles.image}\n />\n </View>\n <View style={styles.row}>\n <Text>Plain text</Text>\n <Text variant=\"secondary\">Secondary</Text>\n <Text variant=\"tertiary\">Tertiary</Text>\n <Text variant=\"footnote\">Footnote</Text>\n </View>\n </View>\n </ScrollView>\n )\n}\n\nconst useStyles = () => {\n const { colors } = useTheme()\n\n return StyleSheet.create({\n scrollView: { flex: 1, backgroundColor: colors.fillColorNeutral090 },\n container: { gap: space(2), padding: space(3) },\n listItem: { color: colors.fillColorNeutral020 },\n row: {\n gap: space(2),\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n flexWrap: 'wrap',\n },\n column: { gap: space(4) },\n spinnerContainer: {\n height: space(2.5),\n },\n image: {\n width: 100,\n height: 100,\n },\n })\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,GAAG,OAAO,EAC5C,GAAG,EAAE,MAAM,EACX,EAAE,MAAc,EAAE,IAAW,EAAE;;;CAAK,GACnC,OAAO,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,CAuBvD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import DeviceInfo from 'react-native-device-info';
|
|
2
|
+
import { session } from './session';
|
|
3
|
+
const brand = DeviceInfo.getBrand();
|
|
4
|
+
const model = DeviceInfo.getModel();
|
|
5
|
+
const systemName = DeviceInfo.getSystemName();
|
|
6
|
+
const systemVersion = DeviceInfo.getSystemVersion();
|
|
7
|
+
const readableVersion = DeviceInfo.getReadableVersion();
|
|
8
|
+
const appName = DeviceInfo.getApplicationName();
|
|
9
|
+
export default function apiRequest(url, { method = 'GET', data = null } = {}) {
|
|
10
|
+
const options = {
|
|
11
|
+
headers: {
|
|
12
|
+
Accept: 'application/vnd.api+json',
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
'User-Agent': `${appName}/${readableVersion} (${brand}, ${model}, ${systemName}, ${systemVersion})`,
|
|
15
|
+
Authorization: `Bearer ${session.token?.access_token}`,
|
|
16
|
+
},
|
|
17
|
+
method,
|
|
18
|
+
};
|
|
19
|
+
if (data && method !== 'GET') {
|
|
20
|
+
options.body = JSON.stringify(data);
|
|
21
|
+
}
|
|
22
|
+
return fetch(url, options)
|
|
23
|
+
.then(validateResponse)
|
|
24
|
+
.then(response => response
|
|
25
|
+
.json()
|
|
26
|
+
.then(json => ({ json: json, ok: response.ok, response }))
|
|
27
|
+
.catch(() => ({ json: null, ok: response.ok, response })));
|
|
28
|
+
}
|
|
29
|
+
const validateResponse = (response) => {
|
|
30
|
+
const isExpired = response.status === 401;
|
|
31
|
+
if (isExpired) {
|
|
32
|
+
throw new Error('Token expired');
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAA;AACnC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAA;AACnC,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,EAAE,CAAA;AAC7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,CAAC,MAAM,KAAK,GAAG,CAAA;IAEzC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import DeviceInfo from 'react-native-device-info'\nimport { session } from './session'\n\nconst brand = DeviceInfo.getBrand()\nconst model = DeviceInfo.getModel()\nconst systemName = DeviceInfo.getSystemName()\nconst systemVersion = DeviceInfo.getSystemVersion()\nconst readableVersion = DeviceInfo.getReadableVersion()\nconst appName = DeviceInfo.getApplicationName()\n\nexport default function apiRequest<T = unknown>(\n url: string,\n { method = 'GET', data = null } = {}\n): Promise<{ json: T; ok: boolean; response: Response }> {\n const options: RequestInit = {\n headers: {\n Accept: 'application/vnd.api+json',\n 'Content-Type': 'application/json',\n 'User-Agent': `${appName}/${readableVersion} (${brand}, ${model}, ${systemName}, ${systemVersion})`,\n Authorization: `Bearer ${session.token?.access_token}`,\n },\n method,\n }\n\n if (data && method !== 'GET') {\n options.body = JSON.stringify(data)\n }\n\n return fetch(url, options)\n .then(validateResponse)\n .then(response =>\n response\n .json()\n .then(json => ({ json: json as T, ok: response.ok, response }))\n .catch(() => ({ json: null as T, ok: response.ok, response }))\n )\n}\n\nconst validateResponse = (response: Response) => {\n const isExpired = response.status === 401\n\n if (isExpired) {\n throw new Error('Token expired')\n }\n\n return response\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../src/utils/space.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GACrB,IAAI,GACJ,GAAG,GACH,CAAC,GACD,GAAG,GACH,CAAC,GACD,GAAG,GACH,CAAC,GACD,GAAG,GACH,CAAC,GACD,GAAG,GACH,CAAC,GACD,GAAG,GACH,CAAC,GACD,GAAG,GACH,CAAC,GACD,GAAG,CAAA;AAEP,wBAAgB,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAalD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tokens } from '../vendor/tapestry/tokens';
|
|
2
|
+
export function space(value) {
|
|
3
|
+
if (value === 0.25)
|
|
4
|
+
return tokens.spacingFourth;
|
|
5
|
+
if (value === 0.5)
|
|
6
|
+
return tokens.spacingHalf;
|
|
7
|
+
if (value < 1 || value > 7.5)
|
|
8
|
+
return handleInvalidSpace(value);
|
|
9
|
+
// Reject fractional values that are not 0 or 0.5
|
|
10
|
+
const wholeValue = Math.floor(value);
|
|
11
|
+
const fractionalValue = value % 1;
|
|
12
|
+
if (fractionalValue !== 0 && fractionalValue !== 0.5)
|
|
13
|
+
return handleInvalidSpace(value);
|
|
14
|
+
// Deliver a whole value or add a half spacing token to it
|
|
15
|
+
const remainderValue = fractionalValue === 0.5 ? tokens.spacingHalf : 0;
|
|
16
|
+
return tokens[`spacing${wholeValue}`] + remainderValue;
|
|
17
|
+
}
|
|
18
|
+
function handleInvalidSpace(value) {
|
|
19
|
+
console.warn(`Invalid space value: ${value} — Must be a whole or half number between 1–7.`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=space.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space.js","sourceRoot":"","sources":["../../src/utils/space.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAoBlD,MAAM,UAAU,KAAK,CAAC,KAAoB;IACxC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,aAAa,CAAA;IAC/C,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,MAAM,CAAC,WAAW,CAAA;IAC5C,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAE9D,iDAAiD;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACpC,MAAM,eAAe,GAAG,KAAK,GAAG,CAAC,CAAA;IACjC,IAAI,eAAe,KAAK,CAAC,IAAI,eAAe,KAAK,GAAG;QAAE,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAEtF,0DAA0D;IAC1D,MAAM,cAAc,GAAG,eAAe,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IACvE,OAAO,MAAM,CAAC,UAAU,UAAU,EAAE,CAAC,GAAG,cAAc,CAAA;AACxD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,CAAC,IAAI,CAAC,wBAAwB,KAAK,gDAAgD,CAAC,CAAA;IAC3F,OAAO,CAAC,CAAA;AACV,CAAC","sourcesContent":["import { tokens } from '../vendor/tapestry/tokens'\n\nexport type SpacingValues =\n | 0.25\n | 0.5\n | 1\n | 1.5\n | 2\n | 2.5\n | 3\n | 3.5\n | 4\n | 4.5\n | 5\n | 5.5\n | 6\n | 6.5\n | 7\n | 7.5\n\nexport function space(value: SpacingValues): number {\n if (value === 0.25) return tokens.spacingFourth\n if (value === 0.5) return tokens.spacingHalf\n if (value < 1 || value > 7.5) return handleInvalidSpace(value)\n\n // Reject fractional values that are not 0 or 0.5\n const wholeValue = Math.floor(value)\n const fractionalValue = value % 1\n if (fractionalValue !== 0 && fractionalValue !== 0.5) return handleInvalidSpace(value)\n\n // Deliver a whole value or add a half spacing token to it\n const remainderValue = fractionalValue === 0.5 ? tokens.spacingHalf : 0\n return tokens[`spacing${wholeValue}`] + remainderValue\n}\n\nfunction handleInvalidSpace(value: number) {\n console.warn(`Invalid space value: ${value} — Must be a whole or half number between 1–7.`)\n return 0\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0-rc.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepublishOnly": "expo-module prepublishOnly"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@planningcenter/chat-core": "^1.
|
|
20
|
+
"@planningcenter/chat-core": "^1.5.0-rc.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@react-navigation/elements": "*",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"@tanstack/react-query": "^5.0.0",
|
|
26
26
|
"lodash": "*",
|
|
27
27
|
"react": "*",
|
|
28
|
-
"react-native": "*"
|
|
28
|
+
"react-native": "*",
|
|
29
|
+
"react-native-device-info": "*"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@react-native/eslint-config": "^0.77.0",
|
|
@@ -36,7 +37,8 @@
|
|
|
36
37
|
"expo-module-scripts": "^4.0.3",
|
|
37
38
|
"lodash": "^4.17.21",
|
|
38
39
|
"prettier": "^3.4.2",
|
|
39
|
-
"react-native": "0.74.5"
|
|
40
|
+
"react-native": "0.74.5",
|
|
41
|
+
"react-native-device-info": "^14.0.4"
|
|
40
42
|
},
|
|
41
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "be69b3cd1b00a27c3aec4682a6c77040efb61a91"
|
|
42
44
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { space, SpacingValues } from '../../utils/space'
|
|
2
|
+
import { tokens } from '../../vendor/tapestry/tokens'
|
|
3
|
+
|
|
4
|
+
describe('space function', () => {
|
|
5
|
+
// Spy on console.warn to check for invalid inputs
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
jest.restoreAllMocks()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const validTokenValues: Record<SpacingValues, number> = {
|
|
15
|
+
0.25: tokens.spacingFourth,
|
|
16
|
+
0.5: tokens.spacingHalf,
|
|
17
|
+
1: tokens.spacing1,
|
|
18
|
+
1.5: tokens.spacing1 + tokens.spacingHalf,
|
|
19
|
+
2: tokens.spacing2,
|
|
20
|
+
2.5: tokens.spacing2 + tokens.spacingHalf,
|
|
21
|
+
3: tokens.spacing3,
|
|
22
|
+
3.5: tokens.spacing3 + tokens.spacingHalf,
|
|
23
|
+
4: tokens.spacing4,
|
|
24
|
+
4.5: tokens.spacing4 + tokens.spacingHalf,
|
|
25
|
+
5: tokens.spacing5,
|
|
26
|
+
5.5: tokens.spacing5 + tokens.spacingHalf,
|
|
27
|
+
6: tokens.spacing6,
|
|
28
|
+
6.5: tokens.spacing6 + tokens.spacingHalf,
|
|
29
|
+
7: tokens.spacing7,
|
|
30
|
+
7.5: tokens.spacing7 + tokens.spacingHalf,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
it('should return the correct token values for all valid SpacingValues', () => {
|
|
34
|
+
Object.entries(validTokenValues).forEach(([value, expected]) => {
|
|
35
|
+
expect(space(Number(value) as SpacingValues)).toBe(expected)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should warn and return 0 for an invalid value less than 1 (e.g., 0.8)', () => {
|
|
40
|
+
const result = space(0.8 as SpacingValues)
|
|
41
|
+
expect(result).toBe(0)
|
|
42
|
+
expect(console.warn).toHaveBeenCalledWith(warnText('0.8'))
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should warn and return 0 for an invalid fractional value (e.g., 1.8)', () => {
|
|
46
|
+
const result = space(1.8 as SpacingValues)
|
|
47
|
+
expect(result).toBe(0)
|
|
48
|
+
expect(console.warn).toHaveBeenCalledWith(warnText('1.8'))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should warn and return 0 for a value greater than 7.5 (e.g., 19)', () => {
|
|
52
|
+
const result = space(19 as SpacingValues)
|
|
53
|
+
expect(result).toBe(0)
|
|
54
|
+
expect(console.warn).toHaveBeenCalledWith(warnText('19'))
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
function warnText(value: string) {
|
|
59
|
+
return `Invalid space value: ${value} — Must be a whole or half number between 1–7.`
|
|
60
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { JSONAPIResponse } from '@planningcenter/chat-core'
|
|
1
2
|
import { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-query'
|
|
2
3
|
import React, { useEffect } from 'react'
|
|
3
4
|
import { ViewProps } from 'react-native'
|
|
4
5
|
import { OAuthToken } from '../types'
|
|
6
|
+
import apiRequest from '../utils/api'
|
|
5
7
|
import { ENV, session } from '../utils/session'
|
|
6
8
|
|
|
7
9
|
let handleTokenExpired: () => void
|
|
@@ -13,13 +15,8 @@ const defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {
|
|
|
13
15
|
|
|
14
16
|
const url = `${session.baseUrl}${queryKey[0]}`
|
|
15
17
|
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
Authorization: `Bearer ${session.token?.access_token}`,
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
.then(validateResponse)
|
|
22
|
-
.then(response => response.json())
|
|
18
|
+
return apiRequest<JSONAPIResponse>(url)
|
|
19
|
+
.then(r => r.json)
|
|
23
20
|
.catch(error => {
|
|
24
21
|
if (error.message === 'Token expired') {
|
|
25
22
|
handleTokenExpired()
|
|
@@ -52,13 +49,3 @@ export function ApiProvider({
|
|
|
52
49
|
|
|
53
50
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
54
51
|
}
|
|
55
|
-
|
|
56
|
-
const validateResponse = (response: Response) => {
|
|
57
|
-
const isExpired = response.status === 401
|
|
58
|
-
|
|
59
|
-
if (isExpired) {
|
|
60
|
-
throw new Error('Token expired')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return response
|
|
64
|
-
}
|
package/src/screens/display.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import { ScrollView, StyleSheet, View } from 'react-native'
|
|
3
3
|
import { useTheme } from '../hooks'
|
|
4
4
|
import { Image, Spinner, Text } from '../components/display'
|
|
5
|
+
import { space } from '../utils/space'
|
|
5
6
|
|
|
6
7
|
export function DisplayScreen() {
|
|
7
8
|
const styles = useStyles()
|
|
@@ -37,18 +38,18 @@ const useStyles = () => {
|
|
|
37
38
|
|
|
38
39
|
return StyleSheet.create({
|
|
39
40
|
scrollView: { flex: 1, backgroundColor: colors.fillColorNeutral090 },
|
|
40
|
-
container: { gap:
|
|
41
|
+
container: { gap: space(2), padding: space(3) },
|
|
41
42
|
listItem: { color: colors.fillColorNeutral020 },
|
|
42
43
|
row: {
|
|
43
|
-
gap:
|
|
44
|
+
gap: space(2),
|
|
44
45
|
flexDirection: 'row',
|
|
45
46
|
alignItems: 'center',
|
|
46
47
|
justifyContent: 'center',
|
|
47
48
|
flexWrap: 'wrap',
|
|
48
49
|
},
|
|
49
|
-
column: { gap:
|
|
50
|
+
column: { gap: space(4) },
|
|
50
51
|
spinnerContainer: {
|
|
51
|
-
height:
|
|
52
|
+
height: space(2.5),
|
|
52
53
|
},
|
|
53
54
|
image: {
|
|
54
55
|
width: 100,
|
package/src/utils/api.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import DeviceInfo from 'react-native-device-info'
|
|
2
|
+
import { session } from './session'
|
|
3
|
+
|
|
4
|
+
const brand = DeviceInfo.getBrand()
|
|
5
|
+
const model = DeviceInfo.getModel()
|
|
6
|
+
const systemName = DeviceInfo.getSystemName()
|
|
7
|
+
const systemVersion = DeviceInfo.getSystemVersion()
|
|
8
|
+
const readableVersion = DeviceInfo.getReadableVersion()
|
|
9
|
+
const appName = DeviceInfo.getApplicationName()
|
|
10
|
+
|
|
11
|
+
export default function apiRequest<T = unknown>(
|
|
12
|
+
url: string,
|
|
13
|
+
{ method = 'GET', data = null } = {}
|
|
14
|
+
): Promise<{ json: T; ok: boolean; response: Response }> {
|
|
15
|
+
const options: RequestInit = {
|
|
16
|
+
headers: {
|
|
17
|
+
Accept: 'application/vnd.api+json',
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'User-Agent': `${appName}/${readableVersion} (${brand}, ${model}, ${systemName}, ${systemVersion})`,
|
|
20
|
+
Authorization: `Bearer ${session.token?.access_token}`,
|
|
21
|
+
},
|
|
22
|
+
method,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (data && method !== 'GET') {
|
|
26
|
+
options.body = JSON.stringify(data)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return fetch(url, options)
|
|
30
|
+
.then(validateResponse)
|
|
31
|
+
.then(response =>
|
|
32
|
+
response
|
|
33
|
+
.json()
|
|
34
|
+
.then(json => ({ json: json as T, ok: response.ok, response }))
|
|
35
|
+
.catch(() => ({ json: null as T, ok: response.ok, response }))
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validateResponse = (response: Response) => {
|
|
40
|
+
const isExpired = response.status === 401
|
|
41
|
+
|
|
42
|
+
if (isExpired) {
|
|
43
|
+
throw new Error('Token expired')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return response
|
|
47
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { tokens } from '../vendor/tapestry/tokens'
|
|
2
|
+
|
|
3
|
+
export type SpacingValues =
|
|
4
|
+
| 0.25
|
|
5
|
+
| 0.5
|
|
6
|
+
| 1
|
|
7
|
+
| 1.5
|
|
8
|
+
| 2
|
|
9
|
+
| 2.5
|
|
10
|
+
| 3
|
|
11
|
+
| 3.5
|
|
12
|
+
| 4
|
|
13
|
+
| 4.5
|
|
14
|
+
| 5
|
|
15
|
+
| 5.5
|
|
16
|
+
| 6
|
|
17
|
+
| 6.5
|
|
18
|
+
| 7
|
|
19
|
+
| 7.5
|
|
20
|
+
|
|
21
|
+
export function space(value: SpacingValues): number {
|
|
22
|
+
if (value === 0.25) return tokens.spacingFourth
|
|
23
|
+
if (value === 0.5) return tokens.spacingHalf
|
|
24
|
+
if (value < 1 || value > 7.5) return handleInvalidSpace(value)
|
|
25
|
+
|
|
26
|
+
// Reject fractional values that are not 0 or 0.5
|
|
27
|
+
const wholeValue = Math.floor(value)
|
|
28
|
+
const fractionalValue = value % 1
|
|
29
|
+
if (fractionalValue !== 0 && fractionalValue !== 0.5) return handleInvalidSpace(value)
|
|
30
|
+
|
|
31
|
+
// Deliver a whole value or add a half spacing token to it
|
|
32
|
+
const remainderValue = fractionalValue === 0.5 ? tokens.spacingHalf : 0
|
|
33
|
+
return tokens[`spacing${wholeValue}`] + remainderValue
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function handleInvalidSpace(value: number) {
|
|
37
|
+
console.warn(`Invalid space value: ${value} — Must be a whole or half number between 1–7.`)
|
|
38
|
+
return 0
|
|
39
|
+
}
|