@openpeepshq/rn-components 0.10.0 → 0.10.2
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 +5 -6
- package/src/components/conversations/ConversationMessageBubble.tsx +36 -1
- package/src/components/custom/date/updating-date.tsx +13 -3
- package/src/components/jams/JamCallParticipant.tsx +4 -3
- package/src/components/navigation/nativeRouter.tsx +2 -0
- package/src/components/post/types/event/FullEvent.test.tsx +383 -0
- package/src/components/post/types/event/FullEvent.tsx +19 -0
- package/src/components/preview-link/RemotePreviewLink.test.tsx +356 -0
- package/src/components/preview-link/RemotePreviewLink.tsx +62 -24
- package/src/components/resources/ResourceLibrary.tsx +25 -0
- package/src/pages/conversations/NewDraft.tsx +80 -23
- package/src/pages/conversations/Show.tsx +58 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
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",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@hookform/resolvers": "^5.4.2",
|
|
63
63
|
"@livekit/react-native": "2.11.0",
|
|
64
64
|
"@livekit/react-native-krisp-noise-filter": "^0.0.3",
|
|
65
|
-
"@livekit/react-native-webrtc": "144.1.
|
|
65
|
+
"@livekit/react-native-webrtc": "144.1.1",
|
|
66
66
|
"@notifee/react-native": "^9.1.8",
|
|
67
67
|
"@react-native-async-storage/async-storage": "^2.1.1",
|
|
68
68
|
"@react-native-clipboard/clipboard": "^1.16.1",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"clsx": "^2.1.1",
|
|
99
99
|
"date-fns": "^4.1.0",
|
|
100
100
|
"i18next": "^24.2.3",
|
|
101
|
-
"i18next-http-backend": "^3.0.
|
|
101
|
+
"i18next-http-backend": "^3.0.6",
|
|
102
102
|
"js-base64": "^3.7.7",
|
|
103
103
|
"livekit-client": "2.19.2",
|
|
104
104
|
"lucide-react-native": "^0.474.0",
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
"timezones-list": "^3.1.0",
|
|
143
143
|
"validator": "^13.15.23",
|
|
144
144
|
"zustand": "^5.0.3",
|
|
145
|
-
"@openpeepshq/common": "^0.6.
|
|
145
|
+
"@openpeepshq/common": "^0.6.1",
|
|
146
146
|
"@openpeepshq/react": "^0.10.0"
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
174
174
|
"commitlint": "^17.0.2",
|
|
175
175
|
"del-cli": "^5.1.0",
|
|
176
|
-
"eslint": "^10.
|
|
176
|
+
"eslint": "^10.14.0",
|
|
177
177
|
"eslint-config-prettier": "^9.1.0",
|
|
178
178
|
"eslint-plugin-prettier": "^5.0.1",
|
|
179
179
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
@@ -184,7 +184,6 @@
|
|
|
184
184
|
"react-test-renderer": "19.2.3",
|
|
185
185
|
"release-it": "^17.10.0",
|
|
186
186
|
"ts-jest": "^29.3.4",
|
|
187
|
-
"turbo": "^1.10.7",
|
|
188
187
|
"typescript": "^6.0.2",
|
|
189
188
|
"@eslint/js": "^9.17.0"
|
|
190
189
|
},
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
3
4
|
import type { PublicPost } from '@openpeepshq/common/types';
|
|
4
|
-
import { useCurrentProfile } from '@openpeepshq/react';
|
|
5
|
+
import { useCurrentProfile, usePostReactionToggle } from '@openpeepshq/react';
|
|
5
6
|
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
6
7
|
import { FeedPostContent } from '../post/FeedPostContent';
|
|
7
8
|
import { UnreadPostIndicator } from '../post/pieces/UnreadPostIndicator';
|
|
8
9
|
import { hexWithOpacity } from '../../theme/utils';
|
|
10
|
+
import { Button } from '../ui/button';
|
|
11
|
+
import { ThemedText } from '../ui/themed-text';
|
|
12
|
+
import { ThumbsUpIcon } from '../icons/index';
|
|
9
13
|
|
|
10
14
|
export interface ConversationMessageBubbleProps {
|
|
11
15
|
message: PublicPost;
|
|
@@ -18,7 +22,10 @@ export const ConversationMessageBubble = ({
|
|
|
18
22
|
}: ConversationMessageBubbleProps) => {
|
|
19
23
|
const me = useCurrentProfile();
|
|
20
24
|
const theme = useOpenPeepsTheme();
|
|
25
|
+
const { t } = useTranslation();
|
|
21
26
|
const mine = message.profile.id === me?.id;
|
|
27
|
+
const { iReacted, canReact, toggleReaction } = usePostReactionToggle(message);
|
|
28
|
+
const reactionCount = message.reactions?.length ?? 0;
|
|
22
29
|
|
|
23
30
|
// NativeWind v4 can't apply `/N` opacity to CSS-variable colors (e.g.
|
|
24
31
|
// `bg-primary/10`), so we use an inline rgba style for own-message bubbles.
|
|
@@ -39,6 +46,34 @@ export const ConversationMessageBubble = ({
|
|
|
39
46
|
style={bubbleStyle}
|
|
40
47
|
>
|
|
41
48
|
<FeedPostContent post={message} />
|
|
49
|
+
{me && canReact ? (
|
|
50
|
+
<View
|
|
51
|
+
className={
|
|
52
|
+
mine ? 'mt-2 flex-row justify-end' : 'mt-2 flex-row justify-start'
|
|
53
|
+
}
|
|
54
|
+
>
|
|
55
|
+
<Button
|
|
56
|
+
variant="ghost"
|
|
57
|
+
onPress={() => void toggleReaction()}
|
|
58
|
+
accessibilityLabel={t('posts.actions.react')}
|
|
59
|
+
className="items-center gap-1 native:px-2 native:py-1"
|
|
60
|
+
>
|
|
61
|
+
<ThumbsUpIcon
|
|
62
|
+
size={16}
|
|
63
|
+
className={iReacted ? 'text-primary' : 'text-muted-foreground'}
|
|
64
|
+
/>
|
|
65
|
+
{reactionCount > 0 ? (
|
|
66
|
+
<ThemedText
|
|
67
|
+
className={`text-xs ${
|
|
68
|
+
iReacted ? 'text-primary' : 'text-muted-foreground'
|
|
69
|
+
}`}
|
|
70
|
+
>
|
|
71
|
+
{reactionCount}
|
|
72
|
+
</ThemedText>
|
|
73
|
+
) : null}
|
|
74
|
+
</Button>
|
|
75
|
+
</View>
|
|
76
|
+
) : null}
|
|
42
77
|
</View>
|
|
43
78
|
{!mine ? (
|
|
44
79
|
<UnreadPostIndicator
|
|
@@ -17,10 +17,20 @@ export const UpdatingDate = ({
|
|
|
17
17
|
const [formattedDate, setFormattedDate] = React.useState(formatter(date));
|
|
18
18
|
|
|
19
19
|
useEffect(() => {
|
|
20
|
-
|
|
20
|
+
// Tick when the displayed value can change: at the next minute
|
|
21
|
+
// boundary of the time since `date`, instead of polling every 60s.
|
|
22
|
+
const dateMs =
|
|
23
|
+
date instanceof Date ? date.getTime() : new Date(date).getTime();
|
|
24
|
+
setFormattedDate(formatter(date));
|
|
25
|
+
if (!Number.isFinite(dateMs)) return;
|
|
26
|
+
const msUntilNextMinute = () => 60_000 - ((Date.now() - dateMs) % 60_000);
|
|
27
|
+
let handle: ReturnType<typeof setTimeout> | undefined;
|
|
28
|
+
const tick = () => {
|
|
21
29
|
setFormattedDate(formatter(date));
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
handle = setTimeout(tick, msUntilNextMinute());
|
|
31
|
+
};
|
|
32
|
+
handle = setTimeout(tick, msUntilNextMinute());
|
|
33
|
+
return () => clearTimeout(handle);
|
|
24
34
|
}, [date, formatter]);
|
|
25
35
|
|
|
26
36
|
return (
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import Toast from 'react-native-toast-message';
|
|
12
12
|
import { useTranslation } from 'react-i18next';
|
|
13
13
|
import {
|
|
14
|
-
|
|
14
|
+
participantTileProfile,
|
|
15
15
|
useCurrentProfile,
|
|
16
16
|
useJamContext,
|
|
17
17
|
useJamEventsContext,
|
|
@@ -177,7 +177,7 @@ const JamParticipantOverlay = ({
|
|
|
177
177
|
const micOn = participant.isMicrophoneEnabled;
|
|
178
178
|
const handUp = raisedHands.has(participant.identity);
|
|
179
179
|
const handRaiseSound = useRef<Sound | null>(null);
|
|
180
|
-
const profile =
|
|
180
|
+
const profile = participantTileProfile(participant, me);
|
|
181
181
|
const isModerator = jam.moderators.includes(participant.identity);
|
|
182
182
|
const viewerIsModerator = !!me && jam.moderators.includes(me.id);
|
|
183
183
|
const iconSize = compact ? 12 : 16;
|
|
@@ -285,8 +285,9 @@ export const JamCallParticipant = ({
|
|
|
285
285
|
onToggleSpotlight,
|
|
286
286
|
}: JamCallParticipantProps) => {
|
|
287
287
|
const { t } = useTranslation();
|
|
288
|
+
const me = useCurrentProfile();
|
|
288
289
|
const participant = trackRef.participant;
|
|
289
|
-
const profile =
|
|
290
|
+
const profile = participantTileProfile(participant, me);
|
|
290
291
|
const connectionLost = useConnectionLost(participant);
|
|
291
292
|
const speaking = useIsSpeaking(participant);
|
|
292
293
|
// React Native's RTCView only re-resolves its media stream when the
|
|
@@ -239,6 +239,8 @@ export const useNativeRouterAdapter = (): RouterAdapter =>
|
|
|
239
239
|
() => ({
|
|
240
240
|
pathname: '',
|
|
241
241
|
searchParams: new URLSearchParams(),
|
|
242
|
+
// Native has no URL bar to keep in sync, so there is no query to write.
|
|
243
|
+
setSearchParams: () => {},
|
|
242
244
|
hrefOf: () => '',
|
|
243
245
|
match: () => null,
|
|
244
246
|
navigate: (target) => {
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Join-Jam affordance for signed-in attendees on the single event page
|
|
3
|
+
* (issue #1815). The RN `FullEvent` previously rendered a Join/Start button
|
|
4
|
+
* only for the host or a jam moderator, so an attendee on a *live* jam had no
|
|
5
|
+
* way to join from this screen. This locks in the attendee button: it appears
|
|
6
|
+
* only when the user is signed in, LiveKit is enabled, and the jam is active;
|
|
7
|
+
* it is mutually exclusive with the host/moderator button; and pressing it
|
|
8
|
+
* navigates to the JamSession (the same route CardEvent uses), leaving all
|
|
9
|
+
* auth/capacity/moderation gating to JamSession -> JamRoom.
|
|
10
|
+
*
|
|
11
|
+
* FullEvent is a large composite, so every external import is mocked (node
|
|
12
|
+
* jest env, no native modules) — mirroring MessageInThread.test.tsx. Only the
|
|
13
|
+
* jam-section decision tree under test is exercised; the surrounding feed /
|
|
14
|
+
* tabs / share UI render inert mocks.
|
|
15
|
+
*/
|
|
16
|
+
import { type ReactNode } from 'react';
|
|
17
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
18
|
+
|
|
19
|
+
// --- shared mutable state read by the module mocks (mock* = hoisting-safe) --
|
|
20
|
+
let mockJamState: { active: boolean } | undefined;
|
|
21
|
+
let mockProfile: { id: string; displayName?: string; handle?: string } | null =
|
|
22
|
+
{ id: 'u-1', displayName: 'Att', handle: 'att' };
|
|
23
|
+
const mockNavigate = jest.fn();
|
|
24
|
+
const mockClient = { posts: { exportRsvps: jest.fn() } };
|
|
25
|
+
const mockUseServerInfo = jest.fn(() => ({
|
|
26
|
+
jams: { livekit: { enabled: true } },
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
// --- react-native: host elements render as plain host tags ----------------
|
|
30
|
+
jest.mock('react-native', () => {
|
|
31
|
+
const React = require('react');
|
|
32
|
+
const make = (tag: string) => (props: { children?: ReactNode }) =>
|
|
33
|
+
React.createElement(tag, null, props.children);
|
|
34
|
+
return {
|
|
35
|
+
View: make('View'),
|
|
36
|
+
Pressable: make('Pressable'),
|
|
37
|
+
TouchableOpacity: make('TouchableOpacity'),
|
|
38
|
+
Image: make('Image'),
|
|
39
|
+
Share: { share: jest.fn() },
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// --- i18n: resolve keys to their defaultValue -----------------------------
|
|
44
|
+
jest.mock('react-i18next', () => ({
|
|
45
|
+
useTranslation: () => ({
|
|
46
|
+
t: (_key: string, opts?: { defaultValue?: string }) =>
|
|
47
|
+
opts?.defaultValue ?? _key,
|
|
48
|
+
}),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
// --- openpeeps context + server info --------------------------------------
|
|
52
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
53
|
+
useOpenpeeps: () => ({
|
|
54
|
+
currentProfile: mockProfile,
|
|
55
|
+
openpeepsApi: {
|
|
56
|
+
rsvpManageAction: () => ({}),
|
|
57
|
+
useJamAttendance: () => ({ isSuccess: false, data: [] }),
|
|
58
|
+
useJamState: () => ({ data: mockJamState }),
|
|
59
|
+
usePostRecordings: () => ({ data: [] }),
|
|
60
|
+
usePostContext: () => ({ data: undefined }),
|
|
61
|
+
},
|
|
62
|
+
client: mockClient,
|
|
63
|
+
}),
|
|
64
|
+
useServerInfo: mockUseServerInfo,
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
// --- shared (pure) helpers -------------------------------------------------
|
|
68
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
69
|
+
buildThreads: (posts: unknown[]) => (Array.isArray(posts) ? posts : []),
|
|
70
|
+
}));
|
|
71
|
+
jest.mock('@openpeepshq/common/lib', () => ({
|
|
72
|
+
availableSpots: () => null,
|
|
73
|
+
canAccessJamRecordings: () => false,
|
|
74
|
+
canModerateJam: () => false,
|
|
75
|
+
canViewJamAttendees: () => false,
|
|
76
|
+
effectiveEventTimes: () => ({}),
|
|
77
|
+
eventTimeZoneOptions: () => ({ label: 'UTC' }),
|
|
78
|
+
formatEventClockTime: () => '',
|
|
79
|
+
formatEventRecurrence: () => '',
|
|
80
|
+
listRsvpOccurrences: () => [],
|
|
81
|
+
parseOccurrenceQuery: () => null,
|
|
82
|
+
rsvpExportFilename: () => 'rsvp.csv',
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
// --- navigation ------------------------------------------------------------
|
|
86
|
+
jest.mock('@react-navigation/native', () => ({
|
|
87
|
+
useNavigation: () => ({
|
|
88
|
+
navigate: (...args: unknown[]) => mockNavigate(...args),
|
|
89
|
+
}),
|
|
90
|
+
}));
|
|
91
|
+
jest.mock('@react-navigation/native-stack', () => ({}));
|
|
92
|
+
|
|
93
|
+
// --- native third-party modules (no native impl in node) ------------------
|
|
94
|
+
jest.mock('react-native-fs', () => ({ default: { CachesDirectoryPath: '' } }));
|
|
95
|
+
jest.mock('@react-native-clipboard/clipboard', () => ({
|
|
96
|
+
default: { setString: jest.fn(), getString: jest.fn() },
|
|
97
|
+
}));
|
|
98
|
+
jest.mock('react-native-toast-message', () => ({
|
|
99
|
+
default: { show: jest.fn() },
|
|
100
|
+
}));
|
|
101
|
+
jest.mock('@gorhom/bottom-sheet', () => ({
|
|
102
|
+
BottomSheetModal: () => null,
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
// --- local modules (state stores, sheets, utils, constants) ---------------
|
|
106
|
+
jest.mock('../../../../stores/useNewConversationStore', () => ({
|
|
107
|
+
useNewConversationStore: () => ({ setContt: jest.fn() }),
|
|
108
|
+
}));
|
|
109
|
+
jest.mock('../../../../hooks/use-controlled-sheet', () => ({
|
|
110
|
+
useControlledSheet: () => ({ current: {} }),
|
|
111
|
+
}));
|
|
112
|
+
jest.mock('../../../../lib/utils', () => ({
|
|
113
|
+
profileName: (p?: { displayName?: string; handle?: string }) =>
|
|
114
|
+
p?.displayName ?? p?.handle ?? '',
|
|
115
|
+
groupName: (g?: { name?: string }) => g?.name ?? '',
|
|
116
|
+
truncateText: (s: string, n: number) => (s ? s.slice(0, n) : ''),
|
|
117
|
+
canManageEventRsvps: () => false,
|
|
118
|
+
}));
|
|
119
|
+
jest.mock('../../../../lib/constants', () => ({
|
|
120
|
+
BASE_URL: 'https://openpeeps.org',
|
|
121
|
+
}));
|
|
122
|
+
jest.mock('../../../../lib/downloadFile', () => ({
|
|
123
|
+
downloadDocument: jest.fn(),
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
// --- ui primitives ---------------------------------------------------------
|
|
127
|
+
// Each factory is self-contained (React.createElement) because jest.mock
|
|
128
|
+
// factories run during hoisted import resolution, before top-level consts.
|
|
129
|
+
jest.mock('../../../ui/themed-text', () => {
|
|
130
|
+
const React = require('react');
|
|
131
|
+
return {
|
|
132
|
+
ThemedText: (props: { children?: ReactNode }) =>
|
|
133
|
+
React.createElement('Text', null, props.children),
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
jest.mock('../../../ui/themed-view', () => {
|
|
137
|
+
const React = require('react');
|
|
138
|
+
return {
|
|
139
|
+
ThemedView: (props: { children?: ReactNode }) =>
|
|
140
|
+
React.createElement('View', null, props.children),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
jest.mock('../../../ui/button', () => {
|
|
144
|
+
const React = require('react');
|
|
145
|
+
// forwards props (incl. onPress/className) to a host View so the button is
|
|
146
|
+
// findable, pressable, and carries the styling under test.
|
|
147
|
+
return {
|
|
148
|
+
Button: (props: {
|
|
149
|
+
children?: ReactNode;
|
|
150
|
+
className?: string;
|
|
151
|
+
size?: string;
|
|
152
|
+
onPress?: () => void;
|
|
153
|
+
}) =>
|
|
154
|
+
React.createElement(
|
|
155
|
+
'View',
|
|
156
|
+
{
|
|
157
|
+
className: props.className,
|
|
158
|
+
size: props.size,
|
|
159
|
+
onPress: props.onPress,
|
|
160
|
+
},
|
|
161
|
+
props.children
|
|
162
|
+
),
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
jest.mock('../../../ui/dropdown-menu', () => {
|
|
166
|
+
const React = require('react');
|
|
167
|
+
const V = (p: { children?: ReactNode }) =>
|
|
168
|
+
React.createElement('View', null, p.children);
|
|
169
|
+
return {
|
|
170
|
+
DropdownMenu: V,
|
|
171
|
+
DropdownMenuContent: V,
|
|
172
|
+
DropdownMenuGroup: V,
|
|
173
|
+
DropdownMenuTrigger: V,
|
|
174
|
+
DropdownMenuItem: () => null,
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
jest.mock('../../../ui/tabs', () => {
|
|
178
|
+
const React = require('react');
|
|
179
|
+
const V = (p: { children?: ReactNode }) =>
|
|
180
|
+
React.createElement('View', null, p.children);
|
|
181
|
+
return { Tabs: V, TabsList: V, TabsTrigger: V, TabsContent: V };
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// --- sibling components (render inert) ------------------------------------
|
|
185
|
+
jest.mock('../../../profile/Avatar', () => ({ ProfileAvatar: () => null }));
|
|
186
|
+
jest.mock('../../../profile/ProfileFromId', () => ({
|
|
187
|
+
ProfileFromId: () => null,
|
|
188
|
+
}));
|
|
189
|
+
jest.mock('../../../profile/index', () => ({
|
|
190
|
+
ReportProfileOrPostModal: () => null,
|
|
191
|
+
}));
|
|
192
|
+
jest.mock('../../../custom/date/updating-date', () => ({
|
|
193
|
+
UpdatingDate: () => null,
|
|
194
|
+
}));
|
|
195
|
+
jest.mock('../../../custom/modals/common', () => ({
|
|
196
|
+
BaseSheet: () => null,
|
|
197
|
+
SheetFooter: () => null,
|
|
198
|
+
}));
|
|
199
|
+
jest.mock('../../pieces/VideoPlayer', () => ({ VideoPlayer: () => null }));
|
|
200
|
+
jest.mock('../../pieces/EventOccurrenceList', () => ({
|
|
201
|
+
EventOccurrenceList: () => null,
|
|
202
|
+
}));
|
|
203
|
+
jest.mock('../../pieces/EventRsvpList', () => ({
|
|
204
|
+
EventRsvpList: () => null,
|
|
205
|
+
}));
|
|
206
|
+
jest.mock('../../../markdown/index', () => ({
|
|
207
|
+
OpenpeepsMarkdown: () => null,
|
|
208
|
+
}));
|
|
209
|
+
jest.mock('../../../icons/index', () => ({
|
|
210
|
+
MoreVerticalIcon: () => null,
|
|
211
|
+
ShareIcon: () => null,
|
|
212
|
+
DownloadIcon: () => null,
|
|
213
|
+
Trash2Icon: () => null,
|
|
214
|
+
MapPinIcon: () => null,
|
|
215
|
+
LinkIcon: () => null,
|
|
216
|
+
PhoneCallIcon: () => null,
|
|
217
|
+
Link2Icon: () => null,
|
|
218
|
+
SendIcon: () => null,
|
|
219
|
+
PencilIcon: () => null,
|
|
220
|
+
FlagIcon: () => null,
|
|
221
|
+
}));
|
|
222
|
+
// The components barrel (EventRsvpButton, ReplyBox, ShareMenu, useNewPostModal, ...)
|
|
223
|
+
jest.mock('../../index', () => ({
|
|
224
|
+
EventMenu: () => null,
|
|
225
|
+
EventRsvpButton: () => null,
|
|
226
|
+
ReplyBox: () => null,
|
|
227
|
+
ShareMenu: () => null,
|
|
228
|
+
ThreadedFeed: () => null,
|
|
229
|
+
useNewPostModal: () => ({ openNewPost: jest.fn() }),
|
|
230
|
+
}));
|
|
231
|
+
|
|
232
|
+
import { FullEvent } from './FullEvent';
|
|
233
|
+
|
|
234
|
+
type TreeNode = {
|
|
235
|
+
type: string;
|
|
236
|
+
props?: Record<string, unknown>;
|
|
237
|
+
children?: (string | TreeNode)[];
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// A "Join Jam" button is the host View that carries the label AND forwards
|
|
241
|
+
// onPress (only Button does). Search deepest-first so the button itself — not
|
|
242
|
+
// an ancestor container that merely contains the label — is returned.
|
|
243
|
+
function joinButton(node: TreeNode): TreeNode | undefined {
|
|
244
|
+
if (node.type !== 'View') return undefined;
|
|
245
|
+
const kids = (node.children || []).filter(
|
|
246
|
+
(c): c is TreeNode => typeof c !== 'string'
|
|
247
|
+
);
|
|
248
|
+
for (const c of kids) {
|
|
249
|
+
const found = joinButton(c);
|
|
250
|
+
if (found) return found;
|
|
251
|
+
}
|
|
252
|
+
if (typeof node.props?.onPress !== 'function') return undefined;
|
|
253
|
+
return JSON.stringify(node.children || []).includes('Join Jam')
|
|
254
|
+
? node
|
|
255
|
+
: undefined;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const BASE_POST = {
|
|
259
|
+
id: 'post-1',
|
|
260
|
+
profile: { id: 'owner-1', displayName: 'Owner' },
|
|
261
|
+
visibility: 'public',
|
|
262
|
+
// `image` set so the header uses a remote URI instead of require()ing a
|
|
263
|
+
// local placeholder PNG (jest's node env cannot parse binary assets).
|
|
264
|
+
data: {
|
|
265
|
+
type: 'event',
|
|
266
|
+
name: 'Meetup',
|
|
267
|
+
jam: true,
|
|
268
|
+
image: 'https://openpeeps.org/img/pic.svg',
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
function render(
|
|
273
|
+
post: unknown,
|
|
274
|
+
occurrence?: string
|
|
275
|
+
): ReactTestRenderer.ReactTestRenderer {
|
|
276
|
+
mockNavigate.mockClear();
|
|
277
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
278
|
+
ReactTestRenderer.act(() => {
|
|
279
|
+
tree = ReactTestRenderer.create(
|
|
280
|
+
<FullEvent post={post as never} occurrence={occurrence} />
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
return tree;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
beforeEach(() => {
|
|
287
|
+
mockJamState = undefined;
|
|
288
|
+
mockProfile = { id: 'u-1', displayName: 'Att', handle: 'att' };
|
|
289
|
+
mockUseServerInfo.mockReset();
|
|
290
|
+
mockUseServerInfo.mockReturnValue({ jams: { livekit: { enabled: true } } });
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('1. signed-in attendee, live jam, livekit on -> Join Jam button navigates to JamSession', () => {
|
|
294
|
+
mockJamState = { active: true };
|
|
295
|
+
const tree = render(BASE_POST, 'occ-1');
|
|
296
|
+
const json = JSON.stringify(tree.toJSON());
|
|
297
|
+
expect(json).toContain('Join Jam');
|
|
298
|
+
expect(json).not.toContain('Start jam'); // attendee never sees the host block
|
|
299
|
+
const button = joinButton(tree.toJSON() as unknown as TreeNode);
|
|
300
|
+
expect(button).toBeDefined();
|
|
301
|
+
// Pressing it navigates to the jam session with the occurrence (CardEvent parity).
|
|
302
|
+
ReactTestRenderer.act(() => {
|
|
303
|
+
(button!.props?.onPress as () => void)();
|
|
304
|
+
});
|
|
305
|
+
expect(mockNavigate).toHaveBeenCalledWith('JamSession', {
|
|
306
|
+
jamId: 'post-1',
|
|
307
|
+
occurrence: 'occ-1',
|
|
308
|
+
});
|
|
309
|
+
// Button styling matches the host button on this screen (review suggestion #2):
|
|
310
|
+
// full width, default size — not the inline `size="sm"` of CardEvent.
|
|
311
|
+
expect(button!.props?.className).toBe('mt-2 w-full');
|
|
312
|
+
expect(button!.props?.size).toBeUndefined();
|
|
313
|
+
tree.unmount();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test('2. signed out (no profile) -> no Join Jam button', () => {
|
|
317
|
+
mockJamState = { active: true };
|
|
318
|
+
mockProfile = null;
|
|
319
|
+
const tree = render(BASE_POST);
|
|
320
|
+
const json = JSON.stringify(tree.toJSON());
|
|
321
|
+
expect(json).not.toContain('Join Jam');
|
|
322
|
+
tree.unmount();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('3. jam not started (jamState inactive) -> no Join Jam button for attendee', () => {
|
|
326
|
+
mockJamState = { active: false };
|
|
327
|
+
const tree = render(BASE_POST);
|
|
328
|
+
const json = JSON.stringify(tree.toJSON());
|
|
329
|
+
expect(json).not.toContain('Join Jam');
|
|
330
|
+
expect(json).not.toContain('Start jam'); // attendee, not host
|
|
331
|
+
tree.unmount();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('4. jam ended -> no Join Jam button (ended jam reports inactive state)', () => {
|
|
335
|
+
mockJamState = { active: false };
|
|
336
|
+
const tree = render(BASE_POST);
|
|
337
|
+
const json = JSON.stringify(tree.toJSON());
|
|
338
|
+
expect(json).not.toContain('Join Jam');
|
|
339
|
+
tree.unmount();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test('5. livekit disabled on server -> no Join Jam button', () => {
|
|
343
|
+
mockJamState = { active: true };
|
|
344
|
+
mockUseServerInfo.mockReturnValue({ jams: { livekit: { enabled: false } } });
|
|
345
|
+
const tree = render(BASE_POST);
|
|
346
|
+
const json = JSON.stringify(tree.toJSON());
|
|
347
|
+
expect(json).not.toContain('Join Jam');
|
|
348
|
+
tree.unmount();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test('6. host, live jam -> host Join Jam shown (single; attendee block gated off)', () => {
|
|
352
|
+
mockJamState = { active: true };
|
|
353
|
+
// Host: currentProfile.id === post.profile.id
|
|
354
|
+
const hostPost = { ...BASE_POST, profile: { id: 'u-1', displayName: 'Me' } };
|
|
355
|
+
const tree = render(hostPost);
|
|
356
|
+
const json = JSON.stringify(tree.toJSON());
|
|
357
|
+
expect(json).toContain('Join Jam');
|
|
358
|
+
const button = joinButton(tree.toJSON() as unknown as TreeNode);
|
|
359
|
+
expect(button).toBeDefined();
|
|
360
|
+
// Only the host button renders; the attendee block is mutually exclusive.
|
|
361
|
+
expect(json.match(/Join Jam/g)).toHaveLength(1);
|
|
362
|
+
expect(button!.props?.className).toBe('mt-2 w-full');
|
|
363
|
+
tree.unmount();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('7. button is a pure navigation trigger — capacity gated in JamSession, not here', () => {
|
|
367
|
+
mockJamState = { active: true };
|
|
368
|
+
// FullEvent has no capacity/attendee model; JamSession → JamRoom owns that gate.
|
|
369
|
+
// The button simply navigates regardless of room capacity.
|
|
370
|
+
const tree = render(BASE_POST);
|
|
371
|
+
const json = JSON.stringify(tree.toJSON());
|
|
372
|
+
expect(json).toContain('Join Jam');
|
|
373
|
+
const button = joinButton(tree.toJSON() as unknown as TreeNode);
|
|
374
|
+
expect(button).toBeDefined();
|
|
375
|
+
ReactTestRenderer.act(() => {
|
|
376
|
+
(button!.props?.onPress as () => void)();
|
|
377
|
+
});
|
|
378
|
+
expect(mockNavigate).toHaveBeenCalledWith('JamSession', {
|
|
379
|
+
jamId: 'post-1',
|
|
380
|
+
occurrence: undefined,
|
|
381
|
+
});
|
|
382
|
+
tree.unmount();
|
|
383
|
+
});
|
|
@@ -156,6 +156,10 @@ export const FullEvent: React.FC<FullEventProps> = ({ post, occurrence }) => {
|
|
|
156
156
|
const jamAttendeesQuery = openpeepsApi.useJamAttendance(post.id);
|
|
157
157
|
const jamStateQuery = openpeepsApi.useJamState(post.id, occurrence);
|
|
158
158
|
const jamState = event.jam ? jamStateQuery.data : undefined;
|
|
159
|
+
// Signed-in attendees (not just the host/moderator) can join a live jam,
|
|
160
|
+
// mirroring CardEvent. jamState is only populated when the event has a jam.
|
|
161
|
+
const canJoinLiveJam =
|
|
162
|
+
!!currentProfile && livekitEnabled && !!jamState?.active;
|
|
159
163
|
const recordingsQuery = openpeepsApi.usePostRecordings(
|
|
160
164
|
post.id,
|
|
161
165
|
!!event.jam && canViewRecordings
|
|
@@ -409,6 +413,21 @@ export const FullEvent: React.FC<FullEventProps> = ({ post, occurrence }) => {
|
|
|
409
413
|
</ThemedText>
|
|
410
414
|
)
|
|
411
415
|
) : null}
|
|
416
|
+
{!myEvent && !iAmModerator && canJoinLiveJam ? (
|
|
417
|
+
<Button
|
|
418
|
+
className="mt-2 w-full"
|
|
419
|
+
onPress={() =>
|
|
420
|
+
navigation.navigate('JamSession', {
|
|
421
|
+
jamId: post.id,
|
|
422
|
+
occurrence: occurrence,
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
>
|
|
426
|
+
<ThemedText numberOfLines={1}>
|
|
427
|
+
{t('jam.join.submit', { defaultValue: 'Join Jam' })}
|
|
428
|
+
</ThemedText>
|
|
429
|
+
</Button>
|
|
430
|
+
) : null}
|
|
412
431
|
<Tabs
|
|
413
432
|
onValueChange={setTabValue}
|
|
414
433
|
value={tabValue}
|