@openpeepshq/rn-components 0.13.3 → 0.14.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.
Files changed (36) hide show
  1. package/README.md +2 -0
  2. package/package.json +4 -3
  3. package/src/components/buttonOverflow.test.tsx +455 -0
  4. package/src/components/groups/GroupCard.tsx +26 -23
  5. package/src/components/groups/JoinGroupButton.tsx +7 -2
  6. package/src/components/jams/JamCapacityGate.tsx +9 -1
  7. package/src/components/jams/JamDeviceSelectors.tsx +2 -2
  8. package/src/components/jams/JamFooter.tsx +26 -22
  9. package/src/components/jams/JamLobby.tsx +5 -3
  10. package/src/components/jams/JamParticipantConference.tsx +6 -1
  11. package/src/components/jams/JamPeopleDrawer.tsx +19 -3
  12. package/src/components/jams/JamRequestJoin.tsx +30 -3
  13. package/src/components/jams/JamRoomIndicators.test.tsx +80 -4
  14. package/src/components/jams/JamRoomIndicators.tsx +34 -1
  15. package/src/components/jams/JamVideoCall.tsx +5 -5
  16. package/src/components/jams/LeaveCloseButton.tsx +5 -1
  17. package/src/components/post/pieces/FeedPostStats.tsx +15 -11
  18. package/src/components/post/pieces/PollContent.tsx +1 -1
  19. package/src/components/post/pieces/PostMenu.test.tsx +333 -0
  20. package/src/components/post/pieces/PostMenu.tsx +19 -15
  21. package/src/components/post/post-form/ReplyModal.tsx +1 -1
  22. package/src/components/post/types/Event.tsx +6 -2
  23. package/src/components/profile/Avatar.tsx +4 -1
  24. package/src/components/profile/ProfileWithActionCard.tsx +14 -6
  25. package/src/components/resources/ResourceLibrary.tsx +0 -1
  26. package/src/hooks/use-controlled-sheet.test.tsx +140 -0
  27. package/src/hooks/use-controlled-sheet.ts +25 -2
  28. package/src/lib/post.ts +0 -128
  29. package/src/pages/Explore.tsx +1 -3
  30. package/src/pages/conversations/Info.tsx +1 -1
  31. package/src/pages/conversations/New.tsx +1 -1
  32. package/src/pages/posts/Edit.tsx +1 -1
  33. package/src/pages/posts/New.carryover.test.tsx +245 -0
  34. package/src/pages/posts/New.tsx +19 -3
  35. package/src/pages/posts/Reply.tsx +19 -4
  36. package/src/stores/useLocalPostStore.ts +7 -4
@@ -216,31 +216,35 @@ export const JamFooter = ({
216
216
  />
217
217
  ) : null}
218
218
 
219
- <JamMicSelector />
220
- <JamCameraSelector />
221
- <JamAudioOutputSelector
222
- speakerDeviceId={speakerDeviceId}
223
- speakerEnabled={speakerEnabled}
224
- onSpeakerChange={onSpeakerChange}
225
- onToggleSpeaker={onToggleSpeaker}
226
- />
219
+ <View className="flex min-w-0 flex-1 flex-row items-center gap-x-2 overflow-hidden">
220
+ <JamMicSelector />
221
+ <JamCameraSelector />
222
+ <JamAudioOutputSelector
223
+ speakerDeviceId={speakerDeviceId}
224
+ speakerEnabled={speakerEnabled}
225
+ onSpeakerChange={onSpeakerChange}
226
+ onToggleSpeaker={onToggleSpeaker}
227
+ />
228
+ </View>
227
229
 
228
- <JamToolbarButton
229
- title={t('jams.reactions.sendTitle')}
230
- tone={reactionTone}
231
- action={() => setReactionMenuOpen((open) => !open)}
232
- >
233
- <LaughIcon size={20} className={toneIconClass[reactionTone]} />
234
- </JamToolbarButton>
230
+ <View className="flex shrink-0 flex-row items-center gap-x-2">
231
+ <JamToolbarButton
232
+ title={t('jams.reactions.sendTitle')}
233
+ tone={reactionTone}
234
+ action={() => setReactionMenuOpen((open) => !open)}
235
+ >
236
+ <LaughIcon size={20} className={toneIconClass[reactionTone]} />
237
+ </JamToolbarButton>
235
238
 
236
- <JamToolbarButton
237
- title={t('jams.drawer.jamControls')}
238
- action={() => setMobileMenuOpen((open) => !open)}
239
- >
240
- <CircleEllipsisIcon size={20} className="text-foreground" />
241
- </JamToolbarButton>
239
+ <JamToolbarButton
240
+ title={t('jams.drawer.jamControls')}
241
+ action={() => setMobileMenuOpen((open) => !open)}
242
+ >
243
+ <CircleEllipsisIcon size={20} className="text-foreground" />
244
+ </JamToolbarButton>
242
245
 
243
- <LeaveCloseButton />
246
+ <LeaveCloseButton />
247
+ </View>
244
248
  </View>
245
249
  );
246
250
  };
@@ -133,12 +133,14 @@ export const JamLobby = ({ onJoin }: JamLobbyProps) => {
133
133
  permissionDeniedRef.current = true;
134
134
  }
135
135
  setError(
136
- denied ? t('jams.mic.lobbyProbeFailed') : t('jams.mic.enableFailed')
136
+ denied
137
+ ? t('jams.device.mic.lobbyProbeFailed')
138
+ : t('jams.device.mic.enableFailed')
137
139
  );
138
140
  if (firstDenial) {
139
141
  Alert.alert(
140
- t('jams.mic.permissionTitle'),
141
- t('jams.mic.permissionMessage'),
142
+ t('jams.device.mic.permissionTitle'),
143
+ t('jams.device.mic.permissionMessage'),
142
144
  [
143
145
  { text: t('common.actions.cancel'), style: 'cancel' },
144
146
  {
@@ -22,7 +22,11 @@ import { JamDetailsDrawer } from './JamDetailsDrawer';
22
22
  import { JamDesktopFooter } from './JamDesktopFooter';
23
23
  import { JamFooter, type JamFooterProps } from './JamFooter';
24
24
  import { JamPeopleDrawer } from './JamPeopleDrawer';
25
- import { JamNetworkQuality, JamRecordingIndicator } from './JamRoomIndicators';
25
+ import {
26
+ JamNetworkQuality,
27
+ JamObserverIndicator,
28
+ JamRecordingIndicator,
29
+ } from './JamRoomIndicators';
26
30
  import { JamVideoLayout } from './JamVideoLayout';
27
31
 
28
32
  type Drawer = 'chat' | 'people' | 'details' | null;
@@ -92,6 +96,7 @@ const JamParticipantConferenceInner = () => {
92
96
  <View className="relative flex-1 overflow-hidden bg-background">
93
97
  <JamNetworkQuality />
94
98
  <JamRecordingIndicator />
99
+ <JamObserverIndicator />
95
100
  <View className="relative min-h-0 w-full flex-1 overflow-hidden p-2">
96
101
  <View className="min-h-0 flex-1 overflow-hidden">
97
102
  <View className="shrink-0 flex-row items-center">
@@ -3,7 +3,8 @@ import { ScrollView, View } from 'react-native';
3
3
  import { useParticipants, useRoomContext } from '@livekit/react-native';
4
4
  import type { Participant } from 'livekit-client';
5
5
  import { useTranslation } from 'react-i18next';
6
- import { profileName } from '@openpeepshq/common/lib';
6
+ import { profileName, waitingRoomEntryName } from '@openpeepshq/common/lib';
7
+ import type { JamWaitingProfile } from '@openpeepshq/common';
7
8
  import { parseParticipantMetadata, useJamPeople } from '@openpeepshq/react';
8
9
  import {
9
10
  AudioLinesIcon,
@@ -158,9 +159,9 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
158
159
  className="flex-row items-center justify-between gap-2"
159
160
  >
160
161
  <View className="min-w-0 flex-1 flex-row items-center gap-2">
161
- <ProfileAvatar profile={profile} className="size-8" />
162
+ <WaitingRoomAvatar profile={profile} />
162
163
  <ThemedText numberOfLines={1} className="shrink text-sm">
163
- {profileName(profile)}
164
+ {waitingRoomEntryName(profile)}
164
165
  </ThemedText>
165
166
  </View>
166
167
  <Button
@@ -181,3 +182,18 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
181
182
  </JamDrawer>
182
183
  );
183
184
  };
185
+
186
+ /**
187
+ * Waiting-room entries carry only a display name (no avatar/handle), so the
188
+ * initials fallback renders a stable, honest placeholder.
189
+ */
190
+ function WaitingRoomAvatar({ profile }: { profile: JamWaitingProfile }) {
191
+ // Initials-avatar input: only the name matters, so narrow instead of
192
+ // widening a queue entry to a full Profile.
193
+ return (
194
+ <ProfileAvatar
195
+ profile={{ displayName: waitingRoomEntryName(profile) }}
196
+ className="size-8"
197
+ />
198
+ );
199
+ }
@@ -1,10 +1,12 @@
1
- import React, { useState } from 'react';
1
+ import React, { useCallback, useState } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import {
5
+ apiErrorMessage,
5
6
  type JamJoinParams,
6
7
  useJoinWaitingRoomToken,
7
8
  } from '@openpeepshq/react';
9
+ import type { SseError } from '@openpeepshq/fetch-client';
8
10
  import { Button } from '../ui/button';
9
11
  import { ThemedText } from '../ui/themed-text';
10
12
 
@@ -17,8 +19,33 @@ const JamWaitingRoomListener = ({
17
19
  }: {
18
20
  onJoin: JamRequestJoinProps['onJoin'];
19
21
  }) => {
20
- useJoinWaitingRoomToken(onJoin);
21
- return null;
22
+ const { t } = useTranslation();
23
+ const [error, setError] = useState<string | null>(null);
24
+
25
+ // The error state is not terminal: when the token is delivered (a fresh
26
+ // stream after a reconnection or a moderator admission), the stale error
27
+ // must not sit behind the recovered stream.
28
+ const joinAndClearError = useCallback(
29
+ (params: JamJoinParams) => {
30
+ setError(null);
31
+ onJoin(params);
32
+ },
33
+ [onJoin]
34
+ );
35
+
36
+ useJoinWaitingRoomToken(joinAndClearError, (e?: SseError) => {
37
+ // Reuse the shared key→message mapping (`errorKey ?? key`, translate
38
+ // `error.*` keys). The SSE path passes an empty fallback so a keyless,
39
+ // message-less error renders nothing rather than a generic "Error".
40
+ const message = apiErrorMessage(e, t, '');
41
+ setError(message.length > 0 ? message : null);
42
+ });
43
+
44
+ return error ? (
45
+ <ThemedText className="text-center text-sm text-destructive">
46
+ {error}
47
+ </ThemedText>
48
+ ) : null;
22
49
  };
23
50
 
24
51
  export const JamRequestJoin = ({ onJoin }: JamRequestJoinProps) => {
@@ -24,6 +24,8 @@ const { mapColors } = require('../../theme/defaults');
24
24
  const mockViewProps: Array<{ style?: unknown; className?: string }> = [];
25
25
  let mockQuality = 1; // livekit-client ConnectionQuality.Good
26
26
  let mockIsDark = false;
27
+ let mockSessions = 0;
28
+ let mockSafeAreaTop = 36; // a typical status-bar inset
27
29
 
28
30
  jest.mock('react-native', () => {
29
31
  const View = (props: {
@@ -51,20 +53,39 @@ jest.mock('livekit-client', () => ({
51
53
 
52
54
  jest.mock('react-i18next', () => ({
53
55
  useTranslation: () => ({
54
- t: (key: string, opts?: Record<string, unknown>) =>
55
- key.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
56
+ // Plural branches mirror `jams.observers.present` in en.json, so the
57
+ // rendered text pins both the key/count usage and the plural choice.
58
+ t: (key: string, opts?: Record<string, unknown>) => {
59
+ if (key === 'jams.observers.present') {
60
+ const count = Number(opts?.count ?? 0);
61
+ const text =
62
+ count === 1
63
+ ? '{{count}} external session is connected to this jam'
64
+ : '{{count}} external sessions are connected to this jam';
65
+ return text.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
66
+ String(opts?.[n] ?? '')
67
+ );
68
+ }
69
+ return key.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
56
70
  String(opts?.[n] ?? '')
57
- ),
71
+ );
72
+ },
58
73
  }),
59
74
  }));
60
75
 
61
76
  jest.mock('@openpeepshq/react', () => ({
62
77
  useJamRecordingState: () => ({ isRecording: false }),
63
78
  useJamRecordingElapsed: () => null,
79
+ useJamExternalSessions: () => mockSessions,
80
+ }));
81
+
82
+ jest.mock('react-native-safe-area-context', () => ({
83
+ useSafeAreaInsets: () => ({ top: mockSafeAreaTop, bottom: 0 }),
64
84
  }));
65
85
 
66
86
  jest.mock('../icons/index', () => ({
67
87
  CircleIcon: () => React.createElement('CircleIcon'),
88
+ EyeOnIcon: () => React.createElement('EyeOnIcon'),
68
89
  XIcon: () => React.createElement('XIcon'),
69
90
  }));
70
91
 
@@ -92,7 +113,10 @@ jest.mock('./useParticipantConnection', () => ({
92
113
  useConnectionQuality: () => mockQuality,
93
114
  }));
94
115
 
95
- const { JamNetworkQuality } = require('./JamRoomIndicators');
116
+ const {
117
+ JamNetworkQuality,
118
+ JamObserverIndicator,
119
+ } = require('./JamRoomIndicators');
96
120
 
97
121
  const renderQuality = (quality: number, isDark: boolean) => {
98
122
  mockViewProps.length = 0;
@@ -105,6 +129,21 @@ const renderQuality = (quality: number, isDark: boolean) => {
105
129
  return { tree, banner: mockViewProps[mockViewProps.length - 1] };
106
130
  };
107
131
 
132
+ const renderObserverPill = (sessions: number, safeAreaTop: number) => {
133
+ mockViewProps.length = 0;
134
+ mockSessions = sessions;
135
+ mockSafeAreaTop = safeAreaTop;
136
+ let tree!: ReactTestRenderer.ReactTestRenderer;
137
+ ReactTestRenderer.act(() => {
138
+ tree = ReactTestRenderer.create(React.createElement(JamObserverIndicator));
139
+ });
140
+ const texts = tree.root.findAllByType('ThemedText');
141
+ return {
142
+ pill: mockViewProps[mockViewProps.length - 1],
143
+ renderedText: texts.length ? texts[0].children.join('') : null,
144
+ };
145
+ };
146
+
108
147
  describe('JamNetworkQuality banner background', () => {
109
148
  it('renders an opaque inline background (light theme) when the connection is poor', () => {
110
149
  const { banner } = renderQuality(2, false); // ConnectionQuality.Poor
@@ -141,3 +180,40 @@ describe('JamNetworkQuality banner background', () => {
141
180
  expect(mockViewProps).toHaveLength(0);
142
181
  });
143
182
  });
183
+
184
+ describe('JamObserverIndicator pill', () => {
185
+ it('renders nothing when no external sessions are connected', () => {
186
+ const { pill, renderedText } = renderObserverPill(0, 36);
187
+ expect(pill).toBeUndefined();
188
+ expect(renderedText).toBeNull();
189
+ });
190
+
191
+ it('renders the singular copy with the inline primary background and a safe-area-aware top when one session is connected', () => {
192
+ mockIsDark = false;
193
+ const { pill, renderedText } = renderObserverPill(1, 36);
194
+
195
+ expect(renderedText).toBe('1 external session is connected to this jam');
196
+ expect(pill).toBeDefined();
197
+ // The pill background is the real primary color at 0.9 opacity (inline
198
+ // rgba, not a NativeWind `/90` class) and clears the safe-area top
199
+ // inset plus a 16px margin; pinned against the shipped light primary
200
+ // (#16161a).
201
+ expect(pill!.style).toEqual([
202
+ { top: 52, right: 16 },
203
+ { backgroundColor: 'rgba(22, 22, 26, 0.9)' },
204
+ ]);
205
+ // Positioning lives in the inline style; the magic `top-14` class must
206
+ // not come back.
207
+ expect(pill!.className).not.toContain('top-14');
208
+ });
209
+
210
+ it('renders the plural copy when two sessions are connected', () => {
211
+ const { renderedText } = renderObserverPill(2, 0);
212
+ expect(renderedText).toBe('2 external sessions are connected to this jam');
213
+ });
214
+
215
+ it('adapts the top offset to the device safe-area inset', () => {
216
+ const { pill } = renderObserverPill(1, 59); // large status-bar inset
217
+ expect((pill!.style as Array<{ top?: number }>)[0].top).toBe(59 + 16);
218
+ });
219
+ });
@@ -1,13 +1,15 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Pressable, Text, View } from 'react-native';
3
3
  import { useLocalParticipant } from '@livekit/react-native';
4
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
4
5
  import { ConnectionQuality } from 'livekit-client';
5
6
  import { useTranslation } from 'react-i18next';
6
7
  import {
7
8
  useJamRecordingElapsed,
8
9
  useJamRecordingState,
10
+ useJamExternalSessions,
9
11
  } from '@openpeepshq/react';
10
- import { CircleIcon, XIcon } from '../icons/index';
12
+ import { CircleIcon, EyeOnIcon, XIcon } from '../icons/index';
11
13
  import { ThemedText } from '../ui/themed-text';
12
14
  import { useThemeOpacity } from '../../theme/useThemeOpacity';
13
15
  import { useConnectionQuality } from './useParticipantConnection';
@@ -41,6 +43,37 @@ export const JamRecordingIndicator = () => {
41
43
  );
42
44
  };
43
45
 
46
+ /**
47
+ * Eye pill shown to participants while hidden external sessions are
48
+ * connected, top-right. The jam screen has no top header, so the pill clears
49
+ * the safe-area top inset (notch/status bar) plus 16px of margin; toasts
50
+ * (rendered by the host app at the safe-area inset) then win the corner, as
51
+ * the transparency signal is lower priority than user feedback.
52
+ */
53
+ export const JamObserverIndicator = () => {
54
+ const { t } = useTranslation();
55
+ const { background } = useThemeOpacity();
56
+ const insets = useSafeAreaInsets();
57
+ const sessions = useJamExternalSessions();
58
+
59
+ if (sessions <= 0) return null;
60
+
61
+ // NativeWind v4 can't apply `/N` opacity to CSS-variable colors (e.g.
62
+ // `bg-primary/90`), so the pill background uses an inline rgba style.
63
+ return (
64
+ <View
65
+ pointerEvents="none"
66
+ style={[{ top: insets.top + 16, right: 16 }, background('primary', 0.9)]}
67
+ className="z-50 flex-row items-center gap-2 rounded-full px-3 py-1"
68
+ >
69
+ <EyeOnIcon size={16} className="text-primary-foreground" />
70
+ <ThemedText className="text-sm font-medium text-primary-foreground">
71
+ {t('jams.observers.present', { count: sessions })}
72
+ </ThemedText>
73
+ </View>
74
+ );
75
+ };
76
+
44
77
  /** Dismissable banner shown when the local connection quality degrades. */
45
78
  export const JamNetworkQuality = () => {
46
79
  const { t } = useTranslation();
@@ -107,8 +107,8 @@ export const JamVideoCall = ({
107
107
  const showMicPermissionAlert = useCallback(() => {
108
108
  showMicPermissionAlertModule(() =>
109
109
  Alert.alert(
110
- t('jams.mic.permissionTitle'),
111
- t('jams.mic.permissionMessage'),
110
+ t('jams.device.mic.permissionTitle'),
111
+ t('jams.device.mic.permissionMessage'),
112
112
  [
113
113
  { text: t('common.actions.cancel'), style: 'cancel' },
114
114
  { text: t('media.permissions.openSettings'), onPress: openSettings },
@@ -136,7 +136,7 @@ export const JamVideoCall = ({
136
136
  return;
137
137
  }
138
138
  console.warn('[jams:mic] mic permission denied', error);
139
- showMicToast(t('jams.mic.lobbyProbeFailed'));
139
+ showMicToast(t('jams.device.mic.lobbyProbeFailed'));
140
140
  showMicPermissionAlert();
141
141
  },
142
142
  [t, showMicPermissionAlert]
@@ -153,8 +153,8 @@ export const JamVideoCall = ({
153
153
  console.warn('[jams:mic] media device failure', kind, failure);
154
154
  showMicToast(
155
155
  failure === MediaDeviceFailure.PermissionDenied
156
- ? t('jams.mic.lobbyProbeFailed')
157
- : t('jams.mic.enableFailed')
156
+ ? t('jams.device.mic.lobbyProbeFailed')
157
+ : t('jams.device.mic.enableFailed')
158
158
  );
159
159
  if (failure === MediaDeviceFailure.PermissionDenied) {
160
160
  showMicPermissionAlert();
@@ -51,8 +51,12 @@ export const LeaveCloseButton = () => {
51
51
  accessibilityLabel={t('jams.exit.confirm')}
52
52
  disabled={busy}
53
53
  onPress={handleClick}
54
+ className="shrink-0"
54
55
  >
55
- <ThemedText className="text-sm text-destructive-foreground">
56
+ <ThemedText
57
+ className="text-sm text-destructive-foreground"
58
+ numberOfLines={1}
59
+ >
56
60
  {t('jams.exit.confirm')}
57
61
  </ThemedText>
58
62
  </Button>
@@ -59,17 +59,21 @@ export const FeedPostStats = ({ post }: FeedPostStatsProps) => {
59
59
  </View>
60
60
  </View>
61
61
 
62
- <ReactionsModal
63
- reactions={post.reactions ?? []}
64
- open={modal === 'reactions'}
65
- onClose={() => setModal(null)}
66
- />
67
- <RepostModal
68
- reposts={post.reposts ?? []}
69
- repostCount={post.repostCount ?? 0}
70
- open={modal === 'reposts'}
71
- onClose={() => setModal(null)}
72
- />
62
+ {modal === 'reactions' && (
63
+ <ReactionsModal
64
+ open
65
+ reactions={post.reactions ?? []}
66
+ onClose={() => setModal(null)}
67
+ />
68
+ )}
69
+ {modal === 'reposts' && (
70
+ <RepostModal
71
+ open
72
+ reposts={post.reposts ?? []}
73
+ repostCount={post.repostCount ?? 0}
74
+ onClose={() => setModal(null)}
75
+ />
76
+ )}
73
77
  </>
74
78
  );
75
79
  };
@@ -72,7 +72,7 @@ export const PollContent = ({ post }: Props) => {
72
72
  } else {
73
73
  Toast.show({
74
74
  type: 'error',
75
- text1: t('posts.poll.selectOption'),
75
+ text1: t('posts.vote.selectOption'),
76
76
  });
77
77
  }
78
78
  };