@openpeepshq/rn-components 0.17.0 → 0.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./src/index.ts",
@@ -142,8 +142,8 @@
142
142
  "timezones-list": "^3.1.0",
143
143
  "validator": "^13.15.23",
144
144
  "zustand": "^5.0.3",
145
+ "@openpeepshq/react": "^0.19.0",
145
146
  "@openpeepshq/common": "^0.12.0",
146
- "@openpeepshq/react": "^0.18.0",
147
147
  "@openpeepshq/fetch-client": "^0.2.1"
148
148
  },
149
149
  "devDependencies": {
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Regression tests for the waiting-room join toast on the native surface.
3
+ *
4
+ * The shared hook (useJamFooterControls) fires `showToast` when someone joins;
5
+ * the only code that turns that into a user-visible toast lives here in the
6
+ * native footer — `useThemedToastConfig` (which must expose an `info` entry
7
+ * built from the theme palette, else a missing/wrong `type` would render an
8
+ * unstyled default toast or nothing) and `useFooterControls().showToast`
9
+ * (which must route to `Toast.show({ type: 'info', ... })`).
10
+ *
11
+ * Only react-native, livekit, i18n and the heavy footer siblings are stubbed.
12
+ * `useThemedToastConfig` runs against the real `mapColors` so the expected hex
13
+ * values are the ones the app actually ships. `useJamFooterControls` is stubbed
14
+ * to echo back the args object, so `useFooterControls()` returns the real
15
+ * `showToast` closure the footer built — exactly the code under test — without
16
+ * loading the hook's full React dependency graph.
17
+ */
18
+
19
+ const React = require('react');
20
+ const ReactTestRenderer = require('react-test-renderer');
21
+
22
+ const { mapColors } = require('../../theme/defaults');
23
+
24
+ const toastShowMock = jest.fn();
25
+ let mockIsDark = false;
26
+
27
+ const tMock = (key: string, opts?: Record<string, unknown>) =>
28
+ key.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
29
+ String(opts?.[n] ?? '')
30
+ );
31
+
32
+ jest.mock('react-native', () => ({
33
+ View: (props: { style?: unknown; className?: string; children?: unknown }) =>
34
+ React.createElement(
35
+ 'View',
36
+ { style: props.style, className: props.className },
37
+ props.children
38
+ ),
39
+ Text: (props: { children?: unknown }) =>
40
+ React.createElement('Text', null, props.children),
41
+ Pressable: (props: { children?: unknown }) =>
42
+ React.createElement('Pressable', null, props.children),
43
+ Alert: { alert: jest.fn() },
44
+ StyleSheet: { create: (s: unknown) => s },
45
+ }));
46
+
47
+ jest.mock('react-native-toast-message', () => ({
48
+ __esModule: true,
49
+ default: { show: toastShowMock },
50
+ }));
51
+
52
+ jest.mock('@livekit/react-native', () => ({
53
+ useRoomContext: () => ({}),
54
+ useParticipants: () => [],
55
+ }));
56
+
57
+ jest.mock('react-i18next', () => ({
58
+ useTranslation: () => ({ t: tMock }),
59
+ }));
60
+
61
+ jest.mock('@openpeepshq/react', () => ({
62
+ // Echo back the args object so useFooterControls() returns the real
63
+ // showToast closure the footer built (the code under test).
64
+ useJamFooterControls: (args: unknown) => args,
65
+ }));
66
+
67
+ jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
68
+ useOpenPeepsTheme: () => ({
69
+ isDark: mockIsDark,
70
+ colors: mapColors(mockIsDark),
71
+ buttonRadius: '9999px',
72
+ refresh: () => {},
73
+ }),
74
+ }));
75
+
76
+ jest.mock('../../theme/useThemeOpacity', () => ({
77
+ useThemeOpacity: () => ({ background: () => ({}) }),
78
+ }));
79
+
80
+ jest.mock('./JamDeviceSelectors', () => ({
81
+ JamAudioOutputSelector: () => React.createElement('JamAudioOutputSelector'),
82
+ JamCameraSelector: () => React.createElement('JamCameraSelector'),
83
+ JamMicSelector: () => React.createElement('JamMicSelector'),
84
+ }));
85
+ jest.mock('./JamReactionMenu', () => ({
86
+ JamReactionMenu: () => React.createElement('JamReactionMenu'),
87
+ }));
88
+ jest.mock('./JamToolbarButton', () => ({
89
+ JamToolbarButton: ({ children }: { children?: unknown }) =>
90
+ React.createElement('JamToolbarButton', null, children),
91
+ toneIconClass: { default: '', active: '' },
92
+ }));
93
+ jest.mock('./LeaveCloseButton', () => ({
94
+ LeaveCloseButton: () => React.createElement('LeaveCloseButton'),
95
+ }));
96
+ jest.mock('../icons/index', () => ({
97
+ CircleEllipsisIcon: () => React.createElement('i'),
98
+ CircleStopIcon: () => React.createElement('i'),
99
+ DiscIcon: () => React.createElement('i'),
100
+ HandIcon: () => React.createElement('i'),
101
+ InfoIcon: () => React.createElement('i'),
102
+ LaughIcon: () => React.createElement('i'),
103
+ MessageSquareTextIcon: () => React.createElement('i'),
104
+ UsersRoundIcon: () => React.createElement('i'),
105
+ }));
106
+ jest.mock('../ui/themed-text', () => ({
107
+ ThemedText: (props: {
108
+ children?: unknown;
109
+ className?: string;
110
+ style?: unknown;
111
+ }) =>
112
+ React.createElement(
113
+ 'ThemedText',
114
+ {
115
+ className: props.className,
116
+ style: props.style,
117
+ },
118
+ props.children
119
+ ),
120
+ }));
121
+
122
+ const { useThemedToastConfig, useFooterControls } = require('./JamFooter');
123
+
124
+ /** Capture the value a hook returns by rendering a component that calls it. */
125
+ const captureHook = <T,>(fn: () => T): T => {
126
+ let value!: T;
127
+ const Capture = () => {
128
+ value = fn();
129
+ return null;
130
+ };
131
+ let tree!: ReactTestRenderer.ReactTestRenderer;
132
+ ReactTestRenderer.act(() => {
133
+ tree = ReactTestRenderer.create(
134
+ React.createElement(Capture as () => unknown)
135
+ );
136
+ });
137
+ ReactTestRenderer.act(() => {
138
+ tree.unmount();
139
+ });
140
+ return value;
141
+ };
142
+
143
+ /** Render a toast-layout element and return its root View's props. */
144
+ const renderToastBody = (
145
+ layout: (p: { text1?: string }) => unknown,
146
+ text1: string
147
+ ) => {
148
+ let tree!: ReactTestRenderer.ReactTestRenderer;
149
+ ReactTestRenderer.act(() => {
150
+ tree = ReactTestRenderer.create(React.createElement(layout, { text1 }));
151
+ });
152
+ // Read props while the tree is still mounted (instances go stale after
153
+ // unmount); do this outside the create-act, as the repo's existing
154
+ // react-test-renderer tests do.
155
+ const props = {
156
+ className: tree.root.findByType('View').props.className,
157
+ style: tree.root.findByType('View').props.style,
158
+ };
159
+ ReactTestRenderer.act(() => {
160
+ tree.unmount();
161
+ });
162
+ return props;
163
+ };
164
+
165
+ describe('useThemedToastConfig', () => {
166
+ it('exposes an info entry built from the theme tokens (light)', () => {
167
+ mockIsDark = false;
168
+ const config = captureHook(useThemedToastConfig);
169
+
170
+ expect(config.info).toBeDefined();
171
+ // Missing `info` from the config is the regression this pins: without it
172
+ // `Toast.show({ type: 'info' })` would fall back to an unstyled default.
173
+ const props = renderToastBody(
174
+ config.info as (p: { text1?: string }) => unknown,
175
+ '1 person joined the waiting room'
176
+ );
177
+
178
+ // Shipped light palette: info = card background + foreground text.
179
+ expect(props.style).toEqual([
180
+ expect.objectContaining({ borderWidth: 1 }),
181
+ { backgroundColor: '#ffffff', borderColor: '#0a0a0b' },
182
+ ]);
183
+ });
184
+
185
+ it('keeps success on the primary palette (distinct from info)', () => {
186
+ mockIsDark = false;
187
+ const config = captureHook(useThemedToastConfig);
188
+
189
+ const props = renderToastBody(
190
+ config.success as (p: { text1?: string }) => unknown,
191
+ 'recording saved'
192
+ );
193
+
194
+ // success = primary background + primary-foreground text (light).
195
+ expect(props.style).toEqual([
196
+ expect.objectContaining({ borderWidth: 1 }),
197
+ { backgroundColor: '#16161a', borderColor: '#fafafa' },
198
+ ]);
199
+ });
200
+
201
+ it('adapts the info palette to the dark theme', () => {
202
+ mockIsDark = true;
203
+ const config = captureHook(useThemedToastConfig);
204
+
205
+ const props = renderToastBody(
206
+ config.info as (p: { text1?: string }) => unknown,
207
+ 'someone joined'
208
+ );
209
+
210
+ // Shipped dark palette: card = #0a0a0f, foreground = #fafafa.
211
+ expect(props.style).toEqual([
212
+ expect.objectContaining({ borderWidth: 1 }),
213
+ { backgroundColor: '#0a0a0f', borderColor: '#fafafa' },
214
+ ]);
215
+ });
216
+
217
+ it('keeps error on the destructive palette (distinct from info)', () => {
218
+ mockIsDark = false;
219
+ const config = captureHook(useThemedToastConfig);
220
+
221
+ const props = renderToastBody(
222
+ config.error as (p: { text1?: string }) => unknown,
223
+ 'recording failed'
224
+ );
225
+
226
+ // error = destructive background + destructive-foreground text (light).
227
+ expect(props.style).toEqual([
228
+ expect.objectContaining({ borderWidth: 1 }),
229
+ { backgroundColor: '#ef4444', borderColor: '#fafafa' },
230
+ ]);
231
+ });
232
+ });
233
+
234
+ describe('useFooterControls().showToast (native)', () => {
235
+ it('routes a waiting-room join to Toast.show with type info', () => {
236
+ mockIsDark = false;
237
+ const result: { showToast: (text1: string) => void } =
238
+ captureHook(useFooterControls);
239
+
240
+ expect(typeof result.showToast).toBe('function');
241
+
242
+ toastShowMock.mockClear();
243
+ ReactTestRenderer.act(() => {
244
+ result.showToast('2 people joined the waiting room');
245
+ });
246
+
247
+ expect(toastShowMock).toHaveBeenCalledTimes(1);
248
+ expect(toastShowMock).toHaveBeenCalledWith({
249
+ type: 'info',
250
+ text1: '2 people joined the waiting room',
251
+ });
252
+ });
253
+ });
@@ -1,7 +1,10 @@
1
- import React, { useState } from 'react';
1
+ import React, { useCallback, useMemo, useState } from 'react';
2
2
  import { Alert, Pressable, View } from 'react-native';
3
3
  import { useParticipants, useRoomContext } from '@livekit/react-native';
4
- import Toast from 'react-native-toast-message';
4
+ import Toast, {
5
+ type ToastConfig,
6
+ type ToastConfigParams,
7
+ } from 'react-native-toast-message';
5
8
  import { useTranslation } from 'react-i18next';
6
9
  import { useJamFooterControls } from '@openpeepshq/react';
7
10
  import {
@@ -15,6 +18,7 @@ import {
15
18
  UsersRoundIcon,
16
19
  } from '../icons/index';
17
20
  import { ThemedText } from '../ui/themed-text';
21
+ import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
18
22
  import {
19
23
  JamAudioOutputSelector,
20
24
  JamCameraSelector,
@@ -26,6 +30,58 @@ import { JamToolbarButton, toneIconClass } from './JamToolbarButton';
26
30
  import { LeaveCloseButton } from './LeaveCloseButton';
27
31
  import { useThemeOpacity } from '../../theme/useThemeOpacity';
28
32
 
33
+ /** Themed toast body; the library default colors sit off the app palette. */
34
+ const TOAST_BODY = {
35
+ borderWidth: 1,
36
+ borderRadius: 8,
37
+ paddingHorizontal: 16,
38
+ paddingVertical: 10,
39
+ maxWidth: '90%' as const,
40
+ };
41
+
42
+ const ThemedToast = ({
43
+ text1,
44
+ bg,
45
+ fg,
46
+ }: {
47
+ text1?: string;
48
+ bg: string;
49
+ fg: string;
50
+ }) => (
51
+ <View style={[TOAST_BODY, { backgroundColor: bg, borderColor: fg }]}>
52
+ <ThemedText style={{ color: fg }} className="text-sm font-medium">
53
+ {text1}
54
+ </ThemedText>
55
+ </View>
56
+ );
57
+
58
+ /** Toast layouts mapped to theme tokens (success, error/destructive, info/primary). */
59
+ export const useThemedToastConfig = (): ToastConfig => {
60
+ const { colors } = useOpenPeepsTheme();
61
+ return useMemo(
62
+ () => ({
63
+ success: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
64
+ <ThemedToast
65
+ text1={text1}
66
+ bg={colors.primary}
67
+ fg={colors['primary-foreground']}
68
+ />
69
+ ),
70
+ error: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
71
+ <ThemedToast
72
+ text1={text1}
73
+ bg={colors.destructive}
74
+ fg={colors['destructive-foreground']}
75
+ />
76
+ ),
77
+ info: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
78
+ <ThemedToast text1={text1} bg={colors.card} fg={colors.foreground} />
79
+ ),
80
+ }),
81
+ [colors]
82
+ );
83
+ };
84
+
29
85
  export interface JamFooterProps {
30
86
  chatOpen: boolean;
31
87
  onToggleChat: () => void;
@@ -45,6 +101,13 @@ export const useFooterControls = () => {
45
101
  const room = useRoomContext();
46
102
  const participants = useParticipants();
47
103
 
104
+ // Stable identity: the footer controls hook lists showToast in an effect
105
+ // deps array, and an inline lambda would tear that effect down every render.
106
+ // Waiting-room joins are neutral info on native.
107
+ const showToast = useCallback((text1: string) => {
108
+ Toast.show({ type: 'info', text1 });
109
+ }, []);
110
+
48
111
  const confirmStopRecording = () =>
49
112
  new Promise<boolean>((resolve) => {
50
113
  Alert.alert('', t('jams.recording.stopConfirm'), [
@@ -67,6 +130,7 @@ export const useFooterControls = () => {
67
130
  confirmStopRecording,
68
131
  onSuccess: (text1) => Toast.show({ type: 'success', text1 }),
69
132
  onError: (text1) => Toast.show({ type: 'error', text1 }),
133
+ showToast,
70
134
  });
71
135
  };
72
136
 
@@ -7,6 +7,7 @@ import {
7
7
  useRoomContext,
8
8
  useTracks,
9
9
  } from '@livekit/react-native';
10
+ import Toast from 'react-native-toast-message';
10
11
  import { Track } from 'livekit-client';
11
12
  import { truncateText } from '@openpeepshq/common';
12
13
  import {
@@ -29,6 +30,7 @@ import {
29
30
  JamsBannerStack,
30
31
  } from './JamRoomIndicators';
31
32
  import { JamVideoLayout } from './JamVideoLayout';
33
+ import { useThemedToastConfig } from './JamFooter';
32
34
 
33
35
  type Drawer = 'chat' | 'people' | 'details' | null;
34
36
 
@@ -39,6 +41,7 @@ const JamParticipantConferenceInner = () => {
39
41
  const [drawer, setDrawer] = useState<Drawer>(null);
40
42
  const [settings, updateSettings] = useJamLocalSettings();
41
43
  const remoteParticipants = useRemoteParticipants();
44
+ const toastConfig = useThemedToastConfig();
42
45
 
43
46
  const tracks = useTracks(
44
47
  [
@@ -100,6 +103,7 @@ const JamParticipantConferenceInner = () => {
100
103
  <JamObserverBanner />
101
104
  <JamRecordingIndicator />
102
105
  </JamsBannerStack>
106
+ <Toast config={toastConfig} />
103
107
  <View className="relative min-h-0 w-full flex-1 overflow-hidden p-2">
104
108
  <View className="min-h-0 flex-1 overflow-hidden">
105
109
  <View className="shrink-0 flex-row items-center">