@openpeepshq/rn-components 0.13.3 → 0.14.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/README.md +2 -0
- package/package.json +3 -3
- package/src/components/jams/JamDeviceSelectors.tsx +2 -2
- package/src/components/jams/JamLobby.tsx +5 -3
- package/src/components/jams/JamParticipantConference.tsx +6 -1
- package/src/components/jams/JamRoomIndicators.test.tsx +80 -4
- package/src/components/jams/JamRoomIndicators.tsx +34 -1
- package/src/components/jams/JamVideoCall.tsx +5 -5
- package/src/components/post/pieces/FeedPostStats.tsx +15 -11
- package/src/components/post/pieces/PollContent.tsx +1 -1
- package/src/components/post/pieces/PostMenu.test.tsx +333 -0
- package/src/components/post/pieces/PostMenu.tsx +19 -15
- package/src/components/post/post-form/ReplyModal.tsx +1 -1
- package/src/components/resources/ResourceLibrary.tsx +0 -1
- package/src/hooks/use-controlled-sheet.test.tsx +140 -0
- package/src/hooks/use-controlled-sheet.ts +25 -2
- package/src/pages/Explore.tsx +1 -3
- package/src/pages/conversations/Info.tsx +1 -1
- package/src/pages/conversations/New.tsx +1 -1
- package/src/pages/posts/Edit.tsx +1 -1
- package/src/pages/posts/New.tsx +1 -1
- package/src/pages/posts/Reply.tsx +2 -2
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ pnpm add @openpeepshq/rn-components
|
|
|
14
14
|
|
|
15
15
|
Wrap your app with **`OpenpeepsProvider`** from `@openpeepshq/rn-components` (and a credentials store + `baseUrl`) so `useOpenpeeps()` and theme code work. This re-exports the web provider from `@openpeepshq/react` with React Native `AppState` foreground handling wired in — do not import `OpenpeepsProvider` from `@openpeepshq/react` in native apps.
|
|
16
16
|
|
|
17
|
+
Also mount **`BottomSheetModalProvider`** from `@gorhom/bottom-sheet` **once at the app root** (e.g. inside your root navigator). Every sheet in this package (`BaseSheet`-based modals) is a gorhom `BottomSheetModal` and silently fails to present without it.
|
|
18
|
+
|
|
17
19
|
Configure **NativeWind** / Tailwind in the app (include this package in Tailwind `content`), load `src/global.css` from your entry, and supply **`react-native-config`** (or compatible env) for `BASE_URL` and related keys.
|
|
18
20
|
|
|
19
21
|
Wrap Metro with **`withOpenPeepsMetro`** (outside `withNativeWind`) so css-interop observables defer on React 19 and `react-native-sound` 0.11.x can `require()` RN 0.80+ `resolveAssetSource`. Hosts should not patch `react-native-css-interop` or `react-native-sound`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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/common": "^0.
|
|
146
|
-
"@openpeepshq/react": "^0.
|
|
145
|
+
"@openpeepshq/common": "^0.9.0",
|
|
146
|
+
"@openpeepshq/react": "^0.15.0"
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
149
|
"@babel/core": "^7.26.7",
|
|
@@ -195,8 +195,8 @@ export const JamMicSelector = () => {
|
|
|
195
195
|
MediaDeviceFailure.PermissionDenied;
|
|
196
196
|
showMicToast(
|
|
197
197
|
denied
|
|
198
|
-
? t('jams.mic.lobbyProbeFailed')
|
|
199
|
-
: t('jams.mic.enableFailed')
|
|
198
|
+
? t('jams.device.mic.lobbyProbeFailed')
|
|
199
|
+
: t('jams.device.mic.enableFailed')
|
|
200
200
|
);
|
|
201
201
|
})
|
|
202
202
|
}
|
|
@@ -133,12 +133,14 @@ export const JamLobby = ({ onJoin }: JamLobbyProps) => {
|
|
|
133
133
|
permissionDeniedRef.current = true;
|
|
134
134
|
}
|
|
135
135
|
setError(
|
|
136
|
-
denied
|
|
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 {
|
|
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">
|
|
@@ -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
|
-
|
|
55
|
-
|
|
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 {
|
|
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();
|
|
@@ -59,17 +59,21 @@ export const FeedPostStats = ({ post }: FeedPostStatsProps) => {
|
|
|
59
59
|
</View>
|
|
60
60
|
</View>
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
};
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostMenu mount-gated reaction/repost sheets (issue #2109 round 2).
|
|
3
|
+
*
|
|
4
|
+
* These pin the call-site contract after the mount-gating rework: both sheet
|
|
5
|
+
* call sites (Reactions, Reposts) render their modal only while their `open`
|
|
6
|
+
* prop is true, and `open` is a required prop on the modal components. This
|
|
7
|
+
* file's regression guard is that PostMenu never mounts a sheet while its
|
|
8
|
+
* state is closed, so a closed modal can never race its own `present()` on
|
|
9
|
+
* mount.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors FullEvent.test.tsx: every external import is mocked (node jest env,
|
|
12
|
+
* no native modules); the decision tree under test is the modal mount logic.
|
|
13
|
+
*/
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
16
|
+
import Toast from 'react-native-toast-message';
|
|
17
|
+
|
|
18
|
+
// --- shared mutable state read by the module mocks (mock* = hoisting-safe) --
|
|
19
|
+
let mockProfile: { id: string; displayName?: string; handle?: string } | null =
|
|
20
|
+
{ id: 'u-1', displayName: 'Me', handle: 'me', following: [] };
|
|
21
|
+
const mockClient = {
|
|
22
|
+
posts: { deletePost: jest.fn(), pinPost: jest.fn() },
|
|
23
|
+
profiles: { followProfile: jest.fn() },
|
|
24
|
+
};
|
|
25
|
+
// ReactionsModal/RepostModal record their mount + open props for assertions.
|
|
26
|
+
const mountedReactions: { open: boolean | undefined; onClose?: () => void }[] =
|
|
27
|
+
[];
|
|
28
|
+
const mountedReposts: { open: boolean | undefined; onClose?: () => void }[] =
|
|
29
|
+
[];
|
|
30
|
+
|
|
31
|
+
// --- react-native: host elements render as plain host tags ----------------
|
|
32
|
+
// Each factory uses `require('react')` (not a top-level `import React`) because
|
|
33
|
+
// jest.mock factories run during hoisted import resolution, before top-level
|
|
34
|
+
// bindings exist — the same convention FullEvent.test.tsx documents.
|
|
35
|
+
jest.mock('react-native', () => {
|
|
36
|
+
const React = require('react');
|
|
37
|
+
const make = (tag: string) => (props: { children?: ReactNode }) =>
|
|
38
|
+
React.createElement(tag, props, props.children);
|
|
39
|
+
return {
|
|
40
|
+
View: make('View'),
|
|
41
|
+
Pressable: make('Pressable'),
|
|
42
|
+
TouchableOpacity: make('TouchableOpacity'),
|
|
43
|
+
ActivityIndicator: () => null,
|
|
44
|
+
Share: { share: jest.fn() },
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// --- i18n: resolve keys to their defaultValue -----------------------------
|
|
49
|
+
jest.mock('react-i18next', () => ({
|
|
50
|
+
useTranslation: () => ({
|
|
51
|
+
t: (_key: string, opts?: { defaultValue?: string }) =>
|
|
52
|
+
opts?.defaultValue ?? _key,
|
|
53
|
+
}),
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
// --- openpeeps context -----------------------------------------------------
|
|
57
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
58
|
+
useOpenpeeps: () => ({
|
|
59
|
+
currentProfile: mockProfile,
|
|
60
|
+
openpeepsApi: {
|
|
61
|
+
useCurrentProfile: () => ({ data: mockProfile, refetch: jest.fn() }),
|
|
62
|
+
useServerInfo: () => ({
|
|
63
|
+
data: { feature_flags: { groups: true, events: true } },
|
|
64
|
+
}),
|
|
65
|
+
useCurrentProfileBookmarkedIds: () => ({ data: [], refetch: jest.fn() }),
|
|
66
|
+
bookmarkPostAction: () => jest.fn(),
|
|
67
|
+
unbookmarkPostAction: () => jest.fn(),
|
|
68
|
+
deletePostAction: () => jest.fn(),
|
|
69
|
+
updateGroupAction: () => jest.fn(),
|
|
70
|
+
pinPostOnProfileAction: () => jest.fn(),
|
|
71
|
+
followProfileAction: () => jest.fn().mockResolvedValue({ success: true }),
|
|
72
|
+
unfollowProfileAction: () =>
|
|
73
|
+
jest.fn().mockResolvedValue({ success: true }),
|
|
74
|
+
admin: { pinPostGloballyAction: () => jest.fn() },
|
|
75
|
+
},
|
|
76
|
+
client: mockClient,
|
|
77
|
+
}),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
// --- local modules ---------------------------------------------------------
|
|
81
|
+
jest.mock('../../../hooks/use-controlled-sheet', () => ({
|
|
82
|
+
useControlledSheet: () => ({ current: {} }),
|
|
83
|
+
}));
|
|
84
|
+
jest.mock('../../../lib/utils', () => ({
|
|
85
|
+
profileName: (p?: { displayName?: string; handle?: string }) =>
|
|
86
|
+
p?.displayName ?? p?.handle ?? '',
|
|
87
|
+
handleInternalURLNavigation: jest.fn(),
|
|
88
|
+
}));
|
|
89
|
+
jest.mock('../../../components/navigation/helpers', () => ({
|
|
90
|
+
buildGoto: () => jest.fn(),
|
|
91
|
+
}));
|
|
92
|
+
jest.mock('@react-navigation/native', () => ({
|
|
93
|
+
useNavigation: () => ({ navigate: jest.fn() }),
|
|
94
|
+
}));
|
|
95
|
+
jest.mock('@react-navigation/native-stack', () => ({}));
|
|
96
|
+
jest.mock('react-native-toast-message', () => ({
|
|
97
|
+
__esModule: true,
|
|
98
|
+
default: { show: jest.fn() },
|
|
99
|
+
}));
|
|
100
|
+
jest.mock('@gorhom/bottom-sheet', () => ({
|
|
101
|
+
BottomSheetModal: () => null,
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
// --- ui primitives ---------------------------------------------------------
|
|
105
|
+
// PostMenu imports its UI primitives from the `../../ui` barrel (mocked
|
|
106
|
+
// below); direct-path mocks for the individual modules are unreachable
|
|
107
|
+
// because jest resolves `jest.mock` by exact module path, so they are not
|
|
108
|
+
// kept here.
|
|
109
|
+
|
|
110
|
+
// Delete/confirm flow renders nothing under test.
|
|
111
|
+
jest.mock('./modals/DeletePostModal', () => ({
|
|
112
|
+
DeletePostModal: () => null,
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
// Current main's PostMenu also mounts the edit-history sheet; it is out of
|
|
116
|
+
// scope here, and its real module graph reaches ESM-only react-native-config,
|
|
117
|
+
// which Jest's CommonJS runtime cannot parse. Stub it out for the test.
|
|
118
|
+
jest.mock('./modals/PostEditHistoryModal', () => ({
|
|
119
|
+
PostEditHistoryModal: () => null,
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
// The two modals under test: record mount + open prop.
|
|
123
|
+
jest.mock('./modals/ReactionsModal', () => ({
|
|
124
|
+
ReactionsModal: (props: { open?: boolean; onClose?: () => void }) => {
|
|
125
|
+
mountedReactions.push({ open: props.open, onClose: props.onClose });
|
|
126
|
+
return null;
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
jest.mock('./modals/RepostModal', () => ({
|
|
130
|
+
RepostModal: (props: { open?: boolean; onClose?: () => void }) => {
|
|
131
|
+
mountedReposts.push({ open: props.open, onClose: props.onClose });
|
|
132
|
+
return null;
|
|
133
|
+
},
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
jest.mock('../../icons/index', () => ({
|
|
137
|
+
PencilIcon: () => null,
|
|
138
|
+
Trash2Icon: () => null,
|
|
139
|
+
FlagIcon: () => null,
|
|
140
|
+
UserXIcon: () => null,
|
|
141
|
+
UsersPlusIcon: () => null,
|
|
142
|
+
PinIcon: () => null,
|
|
143
|
+
BookmarkPlusIcon: () => null,
|
|
144
|
+
BookmarkMinusIcon: () => null,
|
|
145
|
+
Repeat2Icon: () => null,
|
|
146
|
+
HeartIcon: () => null,
|
|
147
|
+
MessageCircleIcon: () => null,
|
|
148
|
+
MoreVerticalIcon: () => null,
|
|
149
|
+
LogOutIcon: () => null,
|
|
150
|
+
MessageSquareReplyIcon: () => null,
|
|
151
|
+
SaveIcon: () => null,
|
|
152
|
+
RadioIcon: () => null,
|
|
153
|
+
TriangleAlertIcon: () => null,
|
|
154
|
+
FileTextIcon: () => null,
|
|
155
|
+
BellOffIcon: () => null,
|
|
156
|
+
BellPlusIcon: () => null,
|
|
157
|
+
BadgeCheckIcon: () => null,
|
|
158
|
+
ShareIcon: () => null,
|
|
159
|
+
DownloadIcon: () => null,
|
|
160
|
+
MapPinIcon: () => null,
|
|
161
|
+
LinkIcon: () => null,
|
|
162
|
+
Link2Icon: () => null,
|
|
163
|
+
PhoneCallIcon: () => null,
|
|
164
|
+
SendIcon: () => null,
|
|
165
|
+
MessageSquareLockIcon: () => null,
|
|
166
|
+
MessageSquarePlusIcon: () => null,
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
jest.mock('../../ui/index', () => {
|
|
170
|
+
const React = require('react');
|
|
171
|
+
return {
|
|
172
|
+
// The full barrel drags in avatar/dropdown natives; expose only the menu
|
|
173
|
+
// surface PostMenu uses, backed by the same mock fakes as the direct mocks.
|
|
174
|
+
PopupMenu: (props: { children?: ReactNode }) =>
|
|
175
|
+
React.createElement('View', props, props.children),
|
|
176
|
+
PopupMenuButton: (props: {
|
|
177
|
+
text?: string;
|
|
178
|
+
action?: unknown;
|
|
179
|
+
onPress?: () => void;
|
|
180
|
+
}) =>
|
|
181
|
+
React.createElement('View', {
|
|
182
|
+
testID: `menu-${props.text}`,
|
|
183
|
+
onPress: typeof props.action === 'function' ? props.action : undefined,
|
|
184
|
+
}),
|
|
185
|
+
PopupSeparator: () => null,
|
|
186
|
+
Avatar: () => null,
|
|
187
|
+
Badge: () => null,
|
|
188
|
+
Button: () => null,
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
193
|
+
checkGroupCapabilities: () => ({}),
|
|
194
|
+
checkRoleCapabilities: () => ({}),
|
|
195
|
+
}));
|
|
196
|
+
jest.mock('@openpeepshq/common/lib', () => ({
|
|
197
|
+
checkRoleCapabilities: () => ({}),
|
|
198
|
+
// Current main's PostMenu gates the edit-history action on this; the edit
|
|
199
|
+
// history is out of scope for these tests, so it stays hidden.
|
|
200
|
+
postHasEditHistory: () => false,
|
|
201
|
+
}));
|
|
202
|
+
jest.mock('@openpeepshq/common/types', () => ({}), { virtual: true });
|
|
203
|
+
|
|
204
|
+
jest.mock('../../profile/ReportProfileOrPostModal', () => ({
|
|
205
|
+
ReportProfileOrPostModal: () => null,
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
jest.mock('../post-form/EditPostModalContext', () => ({
|
|
209
|
+
useEditPostModal: () => ({ openEditPost: jest.fn() }),
|
|
210
|
+
}));
|
|
211
|
+
|
|
212
|
+
import { PostMenu } from './PostMenu';
|
|
213
|
+
|
|
214
|
+
// A "Join Jam" button is the host View that carries the label AND forwards
|
|
215
|
+
// onPress (only Button does). Search deepest-first so the button itself — not
|
|
216
|
+
// an ancestor container that merely contains the label — is returned.
|
|
217
|
+
type TreeNode = {
|
|
218
|
+
type?: string;
|
|
219
|
+
props?: Record<string, unknown> | null;
|
|
220
|
+
children?: (TreeNode | string | null)[];
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
function findByTestID(json: unknown, testID: string): TreeNode | undefined {
|
|
224
|
+
if (json === null || typeof json !== 'object') return undefined;
|
|
225
|
+
const node = json as TreeNode;
|
|
226
|
+
if (node.props?.testID === testID) return node;
|
|
227
|
+
for (const c of node.children || []) {
|
|
228
|
+
if (typeof c !== 'string' && c !== null) {
|
|
229
|
+
const found = findByTestID(c, testID);
|
|
230
|
+
if (found) return found;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const BASE_POST = {
|
|
237
|
+
id: 'post-1',
|
|
238
|
+
profile: { id: 'owner-1', displayName: 'Owner' },
|
|
239
|
+
visibility: 'public',
|
|
240
|
+
repostCount: 2,
|
|
241
|
+
reactionCount: 3,
|
|
242
|
+
data: { type: 'note', content: 'hello' },
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
function render(): ReactTestRenderer.ReactTestRenderer {
|
|
246
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
247
|
+
ReactTestRenderer.act(() => {
|
|
248
|
+
tree = ReactTestRenderer.create(
|
|
249
|
+
<PostMenu post={BASE_POST as never} deleteCallback={jest.fn()} />
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
return tree;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
beforeEach(() => {
|
|
256
|
+
mockProfile = { id: 'u-1', displayName: 'Me', handle: 'me', following: [] };
|
|
257
|
+
mountedReactions.length = 0;
|
|
258
|
+
mountedReposts.length = 0;
|
|
259
|
+
(Toast.show as jest.Mock).mockClear();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('1. closed state: no modal mounted, sheet does not present on mount', () => {
|
|
263
|
+
const tree = render();
|
|
264
|
+
expect(mountedReactions).toHaveLength(0);
|
|
265
|
+
expect(mountedReposts).toHaveLength(0);
|
|
266
|
+
tree.unmount();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('2. reposts menu action mounts RepostModal with open=true', () => {
|
|
270
|
+
const tree = render();
|
|
271
|
+
const repostsItem = findByTestID(tree.toJSON(), 'menu-Reposts');
|
|
272
|
+
expect(typeof repostsItem?.props?.onPress).toBe('function');
|
|
273
|
+
ReactTestRenderer.act(() => {
|
|
274
|
+
(repostsItem?.props?.onPress as () => void)();
|
|
275
|
+
});
|
|
276
|
+
expect(mountedReposts).toHaveLength(1);
|
|
277
|
+
expect(mountedReposts[0].open).toBe(true);
|
|
278
|
+
tree.unmount();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('3. reactions menu action mounts ReactionsModal with open=true', () => {
|
|
282
|
+
const tree = render();
|
|
283
|
+
const reactionsItem = findByTestID(tree.toJSON(), 'menu-Reactions');
|
|
284
|
+
expect(typeof reactionsItem?.props?.onPress).toBe('function');
|
|
285
|
+
ReactTestRenderer.act(() => {
|
|
286
|
+
(reactionsItem?.props?.onPress as () => void)();
|
|
287
|
+
});
|
|
288
|
+
expect(mountedReactions).toHaveLength(1);
|
|
289
|
+
expect(mountedReactions[0].open).toBe(true);
|
|
290
|
+
tree.unmount();
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('4. closing the modal via onClose fully unmounts it (no remount with open=false)', () => {
|
|
294
|
+
const tree = render();
|
|
295
|
+
const repostsItem = findByTestID(tree.toJSON(), 'menu-Reposts');
|
|
296
|
+
ReactTestRenderer.act(() => {
|
|
297
|
+
(repostsItem?.props?.onPress as () => void)();
|
|
298
|
+
});
|
|
299
|
+
expect(mountedReposts).toHaveLength(1);
|
|
300
|
+
// onClose flips state closed -> conditional unmount
|
|
301
|
+
// (no {open:false} remount).
|
|
302
|
+
ReactTestRenderer.act(() => {
|
|
303
|
+
mountedReposts[0].onClose?.();
|
|
304
|
+
});
|
|
305
|
+
expect(mountedReposts).toHaveLength(1); // no remount with open=false
|
|
306
|
+
tree.unmount();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('5. follow/unfollow toasts render the shared profile.follow.* keys (#2110)', async () => {
|
|
310
|
+
const tree = render();
|
|
311
|
+
const followItem = findByTestID(tree.toJSON(), 'menu-Follow');
|
|
312
|
+
expect(typeof followItem?.props?.onPress).toBe('function');
|
|
313
|
+
await ReactTestRenderer.act(async () => {
|
|
314
|
+
await (followItem?.props?.onPress as () => Promise<void>)();
|
|
315
|
+
});
|
|
316
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
317
|
+
expect.objectContaining({ text1: 'profile.follow.followedSuccess' })
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
// Flip to following so the menu exposes Unfollow, then assert its toast.
|
|
321
|
+
mockProfile = { ...mockProfile, following: [{ id: BASE_POST.profile.id }] };
|
|
322
|
+
const tree2 = render();
|
|
323
|
+
const unfollowItem = findByTestID(tree2.toJSON(), 'menu-Unfollow');
|
|
324
|
+
expect(typeof unfollowItem?.props?.onPress).toBe('function');
|
|
325
|
+
await ReactTestRenderer.act(async () => {
|
|
326
|
+
await (unfollowItem?.props?.onPress as () => Promise<void>)();
|
|
327
|
+
});
|
|
328
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
329
|
+
expect.objectContaining({ text1: 'profile.follow.unfollowedSuccess' })
|
|
330
|
+
);
|
|
331
|
+
tree.unmount();
|
|
332
|
+
tree2.unmount();
|
|
333
|
+
});
|
|
@@ -54,7 +54,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
54
54
|
const [isBookmarkActionPending, setIsBookmarkActionPending] =
|
|
55
55
|
React.useState(false);
|
|
56
56
|
const [isFollowing, setIsFollowing] = React.useState(false);
|
|
57
|
-
const [
|
|
57
|
+
const [repostModalOpen, setRepostModalOpen] = React.useState(false);
|
|
58
58
|
const [reactionsModalOpen, setReactionsModalOpen] = React.useState(false);
|
|
59
59
|
const [historyModalOpen, setHistoryModalOpen] = React.useState(false);
|
|
60
60
|
|
|
@@ -139,7 +139,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
139
139
|
setIsFollowing(true);
|
|
140
140
|
Toast.show({
|
|
141
141
|
type: 'success',
|
|
142
|
-
text1: t('profile.
|
|
142
|
+
text1: t('profile.follow.followedSuccess'),
|
|
143
143
|
});
|
|
144
144
|
} else {
|
|
145
145
|
Toast.show({ type: 'error', text1: t('profile.follow.error') });
|
|
@@ -152,7 +152,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
152
152
|
setIsFollowing(false);
|
|
153
153
|
Toast.show({
|
|
154
154
|
type: 'success',
|
|
155
|
-
text1: t('profile.
|
|
155
|
+
text1: t('profile.follow.unfollowedSuccess'),
|
|
156
156
|
});
|
|
157
157
|
} else {
|
|
158
158
|
Toast.show({ type: 'error', text1: t('profile.follow.error') });
|
|
@@ -296,7 +296,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
296
296
|
title={t('posts.menu.reposts', { defaultValue: 'Reposts' })}
|
|
297
297
|
text={t('posts.menu.reposts', { defaultValue: 'Reposts' })}
|
|
298
298
|
icon={Repeat2Icon}
|
|
299
|
-
action={() =>
|
|
299
|
+
action={() => setRepostModalOpen(true)}
|
|
300
300
|
/>
|
|
301
301
|
<PopupMenuButton
|
|
302
302
|
title={t('posts.menu.reactions', { defaultValue: 'Reactions' })}
|
|
@@ -467,17 +467,21 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
467
467
|
) : null}
|
|
468
468
|
</PopupMenu>
|
|
469
469
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
470
|
+
{repostModalOpen && (
|
|
471
|
+
<RepostModal
|
|
472
|
+
open
|
|
473
|
+
reposts={post.reposts ?? []}
|
|
474
|
+
repostCount={post.repostCount ?? 0}
|
|
475
|
+
onClose={() => setRepostModalOpen(false)}
|
|
476
|
+
/>
|
|
477
|
+
)}
|
|
478
|
+
{reactionsModalOpen && (
|
|
479
|
+
<ReactionsModal
|
|
480
|
+
open
|
|
481
|
+
reactions={post.reactions ?? []}
|
|
482
|
+
onClose={() => setReactionsModalOpen(false)}
|
|
483
|
+
/>
|
|
484
|
+
)}
|
|
481
485
|
{showEditHistory ? (
|
|
482
486
|
<PostEditHistoryModal
|
|
483
487
|
post={post}
|
|
@@ -22,7 +22,7 @@ export const ReplyModal = forwardRef<BottomSheetModal, ReplySheetProps>(
|
|
|
22
22
|
<BaseSheet ref={ref} enableOverDrag={false}>
|
|
23
23
|
<View className="flex-1 px-4 pt-2 pb-8">
|
|
24
24
|
<ThemedText className="text-center text-xl tracking-wider font-semibold">
|
|
25
|
-
{t('posts.
|
|
25
|
+
{t('posts.replyModal.title')}
|
|
26
26
|
</ThemedText>
|
|
27
27
|
{post && (
|
|
28
28
|
<ThreadPost
|
|
@@ -358,7 +358,6 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
358
358
|
{library.posts.length > 0 ? (
|
|
359
359
|
<ThemedText className="text-xs text-muted-foreground">
|
|
360
360
|
{t('resources.library.resourceCount', {
|
|
361
|
-
defaultValue: 'Showing {{count}} resources',
|
|
362
361
|
count: library.posts.length,
|
|
363
362
|
})}
|
|
364
363
|
</ThemedText>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useControlledSheet regression coverage (issue #2110 round 5).
|
|
3
|
+
*
|
|
4
|
+
* Pins the guard the round-4 review asked to protect: an open with a
|
|
5
|
+
* never-attached sheet ref (missing <BottomSheetModalProvider>, or a sheet
|
|
6
|
+
* that unmounted before the effect ran) must fail loudly — console.error plus
|
|
7
|
+
* exactly one console.warn — instead of silently dropping the present.
|
|
8
|
+
*
|
|
9
|
+
* Node jest env (no native modules): the bottom-sheet ref module is mocked so
|
|
10
|
+
* present/dismiss are observable spies; the component never mounts a real
|
|
11
|
+
* BottomSheetModal, it only holds (or deliberately drops) the ref.
|
|
12
|
+
*/
|
|
13
|
+
import { createElement, type ReactNode } from 'react';
|
|
14
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
15
|
+
|
|
16
|
+
// React 19 act() requires the act environment flag, or it warns on every act().
|
|
17
|
+
(
|
|
18
|
+
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
|
19
|
+
).IS_REACT_ACT_ENVIRONMENT = true;
|
|
20
|
+
|
|
21
|
+
// --- bottom sheet: drive the attached instance like the real lib does -------
|
|
22
|
+
const presentSpy = jest.fn();
|
|
23
|
+
const dismissSpy = jest.fn();
|
|
24
|
+
jest.mock('../lib/bottom-sheet-ref', () => ({
|
|
25
|
+
bottomSheetPresent: (ref: { current: unknown } | null) =>
|
|
26
|
+
presentSpy(ref?.current),
|
|
27
|
+
bottomSheetDismiss: (ref: { current: unknown } | null) =>
|
|
28
|
+
dismissSpy(ref?.current),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
import { useControlledSheet } from './use-controlled-sheet';
|
|
32
|
+
|
|
33
|
+
// Stands in for the BottomSheetModal instance a real <BottomSheetModal ref>
|
|
34
|
+
// would attach to the hook's ref. The hook's present/dismiss path requires
|
|
35
|
+
// ref.current to be non-null (the detached-ref guard is what tests #2/#3 probe).
|
|
36
|
+
const FAKE_SHEET = { present: jest.fn(), dismiss: jest.fn() };
|
|
37
|
+
|
|
38
|
+
// Drives the hook and, when `attach` is true, simulates the sheet mounting by
|
|
39
|
+
// attaching the fake instance to the ref (as a real BottomSheetModal would).
|
|
40
|
+
const FakeSheet = ({
|
|
41
|
+
open,
|
|
42
|
+
attach = true,
|
|
43
|
+
}: {
|
|
44
|
+
open: boolean;
|
|
45
|
+
attach?: boolean;
|
|
46
|
+
}) => {
|
|
47
|
+
const ref = useControlledSheet(open);
|
|
48
|
+
if (attach) {
|
|
49
|
+
ref.current = FAKE_SHEET;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Same hook, but the ref is never handed to a sheet: ref.current stays null,
|
|
55
|
+
// which is the detached-ref / missing-provider case the guard must catch.
|
|
56
|
+
const DetachedSheet = ({ open }: { open: boolean }) => {
|
|
57
|
+
useControlledSheet(open);
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const render = (element: ReactNode): ReactTestRenderer.ReactTestRenderer => {
|
|
62
|
+
let renderer!: ReactTestRenderer.ReactTestRenderer;
|
|
63
|
+
ReactTestRenderer.act(() => {
|
|
64
|
+
renderer = ReactTestRenderer.create(element);
|
|
65
|
+
});
|
|
66
|
+
return renderer;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
describe('useControlledSheet', () => {
|
|
70
|
+
let errorSpy: jest.SpyInstance;
|
|
71
|
+
let warnSpy: jest.SpyInstance;
|
|
72
|
+
|
|
73
|
+
// React's own deprecation/act warnings also route through console.error, so
|
|
74
|
+
// count only this hook's messages rather than raw call counts.
|
|
75
|
+
const noSheetErrors = () =>
|
|
76
|
+
errorSpy.mock.calls.filter((c) =>
|
|
77
|
+
String(c[0]).includes('no bottom sheet instance')
|
|
78
|
+
).length;
|
|
79
|
+
const noSheetWarns = () =>
|
|
80
|
+
warnSpy.mock.calls.filter((c) =>
|
|
81
|
+
String(c[0]).includes('no sheet instance on first open')
|
|
82
|
+
).length;
|
|
83
|
+
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
presentSpy.mockClear();
|
|
86
|
+
dismissSpy.mockClear();
|
|
87
|
+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
88
|
+
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
afterEach(() => {
|
|
92
|
+
errorSpy.mockRestore();
|
|
93
|
+
warnSpy.mockRestore();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('presents when open and the sheet ref is attached', () => {
|
|
97
|
+
const renderer = render(createElement(FakeSheet, { open: true }));
|
|
98
|
+
expect(presentSpy).toHaveBeenCalledTimes(1);
|
|
99
|
+
expect(presentSpy).toHaveBeenCalledWith(FAKE_SHEET);
|
|
100
|
+
expect(noSheetErrors()).toBe(0);
|
|
101
|
+
expect(noSheetWarns()).toBe(0);
|
|
102
|
+
ReactTestRenderer.act(() => renderer.unmount());
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('dismisses when open goes false', () => {
|
|
106
|
+
const renderer = render(createElement(FakeSheet, { open: true }));
|
|
107
|
+
expect(presentSpy).toHaveBeenCalledTimes(1);
|
|
108
|
+
expect(dismissSpy).not.toHaveBeenCalled();
|
|
109
|
+
ReactTestRenderer.act(() => {
|
|
110
|
+
renderer.update(createElement(FakeSheet, { open: false }));
|
|
111
|
+
});
|
|
112
|
+
expect(dismissSpy).toHaveBeenCalledTimes(1);
|
|
113
|
+
expect(dismissSpy).toHaveBeenCalledWith(FAKE_SHEET);
|
|
114
|
+
expect(noSheetErrors()).toBe(0);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('errors on a detached ref and warns exactly once per hook instance', () => {
|
|
118
|
+
const renderer = render(createElement(DetachedSheet, { open: false }));
|
|
119
|
+
expect(presentSpy).not.toHaveBeenCalled();
|
|
120
|
+
expect(noSheetErrors()).toBe(0);
|
|
121
|
+
expect(noSheetWarns()).toBe(0);
|
|
122
|
+
|
|
123
|
+
// First open with a never-attached ref: loud error + one provider warning.
|
|
124
|
+
ReactTestRenderer.act(() => {
|
|
125
|
+
renderer.update(createElement(DetachedSheet, { open: true }));
|
|
126
|
+
});
|
|
127
|
+
expect(noSheetErrors()).toBe(1);
|
|
128
|
+
expect(noSheetWarns()).toBe(1);
|
|
129
|
+
|
|
130
|
+
// Re-open after a dismiss must not re-spam the provider warning.
|
|
131
|
+
ReactTestRenderer.act(() => {
|
|
132
|
+
renderer.update(createElement(DetachedSheet, { open: false }));
|
|
133
|
+
});
|
|
134
|
+
ReactTestRenderer.act(() => {
|
|
135
|
+
renderer.update(createElement(DetachedSheet, { open: true }));
|
|
136
|
+
});
|
|
137
|
+
expect(noSheetErrors()).toBe(2);
|
|
138
|
+
expect(noSheetWarns()).toBe(1);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -8,9 +8,32 @@ import {
|
|
|
8
8
|
/** Drives an imperative bottom sheet from web-style `open`/`onClose` props. */
|
|
9
9
|
export const useControlledSheet = (open: boolean) => {
|
|
10
10
|
const ref = useRef<BottomSheetModal>(null);
|
|
11
|
+
// Fired once per hook instance so a missing provider can't spam on every
|
|
12
|
+
// open attempt.
|
|
13
|
+
const warnedMissingProvider = useRef(false);
|
|
11
14
|
useEffect(() => {
|
|
12
|
-
if (open)
|
|
13
|
-
|
|
15
|
+
if (open) {
|
|
16
|
+
if (!ref.current) {
|
|
17
|
+
// The sheet instance never attached: the modal subtree either failed
|
|
18
|
+
// to mount or unmounted before this effect ran.
|
|
19
|
+
console.error(
|
|
20
|
+
'useControlledSheet: no bottom sheet instance to present — the ' +
|
|
21
|
+
'sheet never mounted.'
|
|
22
|
+
);
|
|
23
|
+
if (!warnedMissingProvider.current) {
|
|
24
|
+
warnedMissingProvider.current = true;
|
|
25
|
+
console.warn(
|
|
26
|
+
'useControlledSheet: no sheet instance on first open. If this ' +
|
|
27
|
+
'happens for every sheet, the app root is missing ' +
|
|
28
|
+
'<BottomSheetModalProvider> from @gorhom/bottom-sheet.'
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
bottomSheetPresent(ref);
|
|
34
|
+
} else {
|
|
35
|
+
bottomSheetDismiss(ref);
|
|
36
|
+
}
|
|
14
37
|
}, [open]);
|
|
15
38
|
return ref;
|
|
16
39
|
};
|
package/src/pages/Explore.tsx
CHANGED
|
@@ -64,9 +64,7 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
64
64
|
<View className="max-w-[200px] flex-row items-center">
|
|
65
65
|
<Input
|
|
66
66
|
className="flex-1"
|
|
67
|
-
placeholder={t('explore.searchPlaceholder'
|
|
68
|
-
defaultValue: 'Search',
|
|
69
|
-
})}
|
|
67
|
+
placeholder={t('explore.searchPlaceholder')}
|
|
70
68
|
value={searchQuery}
|
|
71
69
|
onChangeText={setSearchQuery}
|
|
72
70
|
/>
|
|
@@ -35,7 +35,7 @@ export const ConversationInfo = ({ route }: ConversationInfoProps) => {
|
|
|
35
35
|
const navigation =
|
|
36
36
|
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
37
37
|
|
|
38
|
-
useSetPageHeader(t('conversations.info'));
|
|
38
|
+
useSetPageHeader(t('conversations.info.title'));
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
41
|
<ThemedView className="flex-1">
|
|
@@ -46,7 +46,7 @@ export const NewConversation = ({
|
|
|
46
46
|
}, [currentProfile, allProfiles, searchQuery]);
|
|
47
47
|
|
|
48
48
|
useSetPageHeader(
|
|
49
|
-
t('conversations.selectMembers'
|
|
49
|
+
t('conversations.selectMembers'),
|
|
50
50
|
<HeaderActionButton
|
|
51
51
|
title={t('common.next', { defaultValue: 'Next' })}
|
|
52
52
|
onPress={() => navigation.navigate('DraftMessage')}
|
package/src/pages/posts/Edit.tsx
CHANGED
|
@@ -127,7 +127,7 @@ export const EditPost = ({ route, navigation }: PostProps) => {
|
|
|
127
127
|
isPosting
|
|
128
128
|
? t('posts.edit.loading')
|
|
129
129
|
: attachmentsProcessing
|
|
130
|
-
? t('
|
|
130
|
+
? t('form.upload.processing')
|
|
131
131
|
: t('posts.edit.submit')
|
|
132
132
|
}
|
|
133
133
|
onPress={() => void handlePostUpdate()}
|
package/src/pages/posts/New.tsx
CHANGED
|
@@ -273,7 +273,7 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
273
273
|
isPosting
|
|
274
274
|
? t('posts.create.loading')
|
|
275
275
|
: attachmentsProcessing
|
|
276
|
-
? t('
|
|
276
|
+
? t('form.upload.processing')
|
|
277
277
|
: t('posts.create.submit')
|
|
278
278
|
}
|
|
279
279
|
onPress={() => void handlePostCreation()}
|
|
@@ -246,13 +246,13 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
|
|
|
246
246
|
}, [t]);
|
|
247
247
|
|
|
248
248
|
useSetPageHeader(
|
|
249
|
-
t('posts.
|
|
249
|
+
t('posts.replyModal.title'),
|
|
250
250
|
<HeaderActionButton
|
|
251
251
|
title={
|
|
252
252
|
isPosting
|
|
253
253
|
? t('posts.create.loading')
|
|
254
254
|
: attachmentsProcessing
|
|
255
|
-
? t('
|
|
255
|
+
? t('form.upload.processing')
|
|
256
256
|
: t('posts.create.submit')
|
|
257
257
|
}
|
|
258
258
|
onPress={() => void handlePostCreation()}
|