@openpeepshq/rn-components 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/components/groups/GroupAvatar.test.tsx +166 -0
- package/src/components/groups/GroupAvatar.tsx +46 -24
- package/src/components/jams/JamFooter.toast.test.tsx +253 -0
- package/src/components/jams/JamFooter.tsx +66 -2
- package/src/components/jams/JamParticipantConference.tsx +4 -0
- package/src/components/post/post-form/EventForm.tsx +6 -1
- package/src/components/post/post-form/EventTypeSwitcher.test.tsx +247 -0
- package/src/components/post/post-form/EventTypeSwitcher.tsx +36 -1
- package/src/components/profile/Avatar.test.tsx +102 -17
- package/src/components/profile/Avatar.tsx +38 -18
- package/src/components/ui/avatar.test.tsx +123 -0
- package/src/pages/jams/New.test.tsx +179 -0
- package/src/pages/jams/New.tsx +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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,9 +142,9 @@
|
|
|
142
142
|
"timezones-list": "^3.1.0",
|
|
143
143
|
"validator": "^13.15.23",
|
|
144
144
|
"zustand": "^5.0.3",
|
|
145
|
-
"@openpeepshq/
|
|
146
|
-
"@openpeepshq/
|
|
147
|
-
"@openpeepshq/
|
|
145
|
+
"@openpeepshq/fetch-client": "^0.2.1",
|
|
146
|
+
"@openpeepshq/common": "^0.13.0",
|
|
147
|
+
"@openpeepshq/react": "^0.20.0"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"@babel/core": "^7.26.7",
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for the GroupAvatar loading-gap fix (issue #1666, round-4
|
|
3
|
+
* review item 2).
|
|
4
|
+
*
|
|
5
|
+
* A group avatar that is still downloading — or permanently, when the media
|
|
6
|
+
* cache cannot produce the file — must keep the slot filled with the same
|
|
7
|
+
* sized initials tile as a no-avatar group, instead of leaving an empty box
|
|
8
|
+
* that reads as a misaligned avatar. The image branch renders the tile
|
|
9
|
+
* behind the image (tile first in tree order), so the guarantee is uniform
|
|
10
|
+
* with ProfileAvatar.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const React = require('react');
|
|
14
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
15
|
+
|
|
16
|
+
// Mocked element types, shared with the jest.mock factories below so tests can
|
|
17
|
+
// assert tree order by reference instead of by string name. The tile's style
|
|
18
|
+
// (backgroundColor / fontSize) is forwarded so the underlay's actual styling
|
|
19
|
+
// can be pinned, not just its presence and tree position.
|
|
20
|
+
const MockView = (props: {
|
|
21
|
+
children?: unknown;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: unknown;
|
|
24
|
+
}) =>
|
|
25
|
+
React.createElement(
|
|
26
|
+
'View',
|
|
27
|
+
{ className: props.className, style: props.style },
|
|
28
|
+
props.children
|
|
29
|
+
);
|
|
30
|
+
const MockText = (props: {
|
|
31
|
+
children?: unknown;
|
|
32
|
+
className?: string;
|
|
33
|
+
style?: unknown;
|
|
34
|
+
}) =>
|
|
35
|
+
React.createElement(
|
|
36
|
+
'Text',
|
|
37
|
+
{ className: props.className, style: props.style },
|
|
38
|
+
props.children
|
|
39
|
+
);
|
|
40
|
+
const MockAvatar = (props: { children?: unknown; className?: string }) =>
|
|
41
|
+
React.createElement('Avatar', { className: props.className }, props.children);
|
|
42
|
+
const MockAvatarImage = (props: { source?: unknown; className?: string }) =>
|
|
43
|
+
React.createElement('AvatarImage', { source: props.source });
|
|
44
|
+
|
|
45
|
+
jest.mock('react-native', () => ({
|
|
46
|
+
View: MockView,
|
|
47
|
+
Text: MockText,
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
51
|
+
// Only the runtime helper is needed; `Group` is a type-only import.
|
|
52
|
+
getGroupAvatar: (
|
|
53
|
+
group: { avatar?: string | null } | null | undefined,
|
|
54
|
+
_config: unknown
|
|
55
|
+
) => group?.avatar,
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
59
|
+
useOpenpeeps: () => ({
|
|
60
|
+
openpeepsApi: { useServerInfo: () => ({ data: { communityConfig: {} } }) },
|
|
61
|
+
}),
|
|
62
|
+
// Real source for the initials fallback (first + last name initial).
|
|
63
|
+
getInitials: require('../../../../react/src/lib/initialsAvatar').getInitials,
|
|
64
|
+
hueFromHandle: () => 180,
|
|
65
|
+
initialsBackground: () => 'rgb(20, 20, 20)',
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
|
|
69
|
+
useOpenPeepsTheme: () => ({ isDark: false }),
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
jest.mock('../ui/avatar', () => ({
|
|
73
|
+
Avatar: MockAvatar,
|
|
74
|
+
AvatarImage: MockAvatarImage,
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
jest.mock('../../lib/utils', () => ({
|
|
78
|
+
cn: (...parts: Array<string | undefined>) => parts.filter(Boolean).join(' '),
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
import type { Group } from '@openpeepshq/common';
|
|
82
|
+
import { GroupAvatar } from './GroupAvatar';
|
|
83
|
+
|
|
84
|
+
const baseGroup = {
|
|
85
|
+
id: 'g1',
|
|
86
|
+
handle: 'ada-group',
|
|
87
|
+
displayName: 'Ada Group',
|
|
88
|
+
} as unknown as Group;
|
|
89
|
+
|
|
90
|
+
const renderGroupAvatar = (group: Group, className?: string) => {
|
|
91
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
92
|
+
ReactTestRenderer.act(() => {
|
|
93
|
+
tree = ReactTestRenderer.create(
|
|
94
|
+
React.createElement(GroupAvatar, { group, className })
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
return tree;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const initialsText = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
|
|
101
|
+
tree.root
|
|
102
|
+
.findAllByType(MockText)
|
|
103
|
+
.map((node: { props: { children?: unknown } }) => node.props.children)
|
|
104
|
+
.find((child) => typeof child === 'string');
|
|
105
|
+
|
|
106
|
+
// The underlay tile is the View carrying the initialsBackground color.
|
|
107
|
+
const findTile = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
|
|
108
|
+
tree.root
|
|
109
|
+
.findAllByType(MockView)
|
|
110
|
+
.find(
|
|
111
|
+
(node: { props: { style?: { backgroundColor?: string } } }) =>
|
|
112
|
+
typeof node.props.style?.backgroundColor === 'string'
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// The tile's single child is the initials Text (not an array).
|
|
116
|
+
const tileFontSize = (tree: ReturnType<typeof ReactTestRenderer.create>) => {
|
|
117
|
+
const child = findTile(tree)?.props?.children;
|
|
118
|
+
return (Array.isArray(child) ? child[0] : child)?.props?.style?.fontSize;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
describe('GroupAvatar loading-gap fix (issue #1666 round-4 review item 2)', () => {
|
|
122
|
+
it('renders the initials tile behind the image while the group avatar is still loading', () => {
|
|
123
|
+
const tree = renderGroupAvatar({
|
|
124
|
+
...baseGroup,
|
|
125
|
+
avatar: 'https://cdn.example/groups/ada-group.png',
|
|
126
|
+
});
|
|
127
|
+
const avatar = tree.root.findByType('Avatar');
|
|
128
|
+
expect(initialsText(tree)).toBe('AG');
|
|
129
|
+
expect(avatar.findAllByType(MockAvatarImage)).toHaveLength(1);
|
|
130
|
+
const childTypes = avatar.children.map(
|
|
131
|
+
(child: { type?: unknown }) => child.type
|
|
132
|
+
);
|
|
133
|
+
expect(childTypes[0]).toBe(MockView);
|
|
134
|
+
expect(childTypes[childTypes.length - 1]).toBe(MockAvatarImage);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('renders the initials tile standalone when the group has no avatar', () => {
|
|
138
|
+
const tree = renderGroupAvatar(baseGroup);
|
|
139
|
+
const avatar = tree.root.findByType('Avatar');
|
|
140
|
+
expect(initialsText(tree)).toBe('AG');
|
|
141
|
+
expect(avatar.findAllByType(MockAvatarImage)).toHaveLength(0);
|
|
142
|
+
const childTypes = avatar.children.map(
|
|
143
|
+
(child: { type?: unknown }) => child.type
|
|
144
|
+
);
|
|
145
|
+
expect(childTypes).toEqual([MockView]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('pins the underlay style: tile background from initialsBackground and size-derived fontSize (issue #1666 round-20 #1/#3)', () => {
|
|
149
|
+
// Default (no size class) → 64dp box → fontSize 24; background is the
|
|
150
|
+
// real initialsBackground output for the mocked hue.
|
|
151
|
+
const tree = renderGroupAvatar(baseGroup);
|
|
152
|
+
expect(findTile(tree)?.props.style?.backgroundColor).toBe(
|
|
153
|
+
'rgb(20, 20, 20)'
|
|
154
|
+
);
|
|
155
|
+
expect(tileFontSize(tree)).toBe(24);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('scales the tile fontSize with the requested size, including non-bucket sizes (issue #1666 round-20 #3)', () => {
|
|
159
|
+
// size-8 → 32dp → 12 (was the 14px bucket before round-20 #4), size-24 →
|
|
160
|
+
// 96dp → 36, w-12 h-12 → 48dp → 18, and a non-bucket size-14 → 56dp → 21.
|
|
161
|
+
expect(tileFontSize(renderGroupAvatar(baseGroup, 'size-8'))).toBe(12);
|
|
162
|
+
expect(tileFontSize(renderGroupAvatar(baseGroup, 'size-24'))).toBe(36);
|
|
163
|
+
expect(tileFontSize(renderGroupAvatar(baseGroup, 'w-12 h-12'))).toBe(18);
|
|
164
|
+
expect(tileFontSize(renderGroupAvatar(baseGroup, 'size-14'))).toBe(21);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -11,6 +11,11 @@ import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
|
11
11
|
import { Avatar, AvatarImage } from '../ui/avatar';
|
|
12
12
|
import { cn } from '../../lib/utils';
|
|
13
13
|
|
|
14
|
+
/** Tailwind spacing unit in dp (size-N / w-N → N × 4). */
|
|
15
|
+
const TAILWIND_UNIT = 4;
|
|
16
|
+
/** Initials scale with the avatar instead of preset buckets. */
|
|
17
|
+
const FONT_RATIO = 0.375;
|
|
18
|
+
|
|
14
19
|
export const GroupAvatar = ({
|
|
15
20
|
group,
|
|
16
21
|
className,
|
|
@@ -22,19 +27,46 @@ export const GroupAvatar = ({
|
|
|
22
27
|
const { isDark } = useOpenPeepsTheme();
|
|
23
28
|
const { data: server } = openpeepsApi.useServerInfo();
|
|
24
29
|
|
|
25
|
-
const isSmall = className?.includes('size-8');
|
|
26
|
-
const sizeClass = isSmall ? 'h-8 w-8' : 'h-16 w-16';
|
|
27
30
|
const roundedClass = 'rounded-full';
|
|
28
31
|
|
|
32
|
+
// The requested size (size-N / w-N / h-N) drives the initials font size
|
|
33
|
+
// directly, matching ProfileAvatar: every size renders proportionally
|
|
34
|
+
// scaled fallback content instead of preset buckets, so a group tile and a
|
|
35
|
+
// profile tile of the same size read the same next to each other.
|
|
36
|
+
const sizeMatch = (className ?? '').match(
|
|
37
|
+
/(?:^|\s)(?:size-|w-|h-)(\d+)(?=\s|$)/
|
|
38
|
+
);
|
|
39
|
+
const px = sizeMatch ? Number(sizeMatch[1]) * TAILWIND_UNIT : 64;
|
|
40
|
+
const fontSize = Math.max(10, Math.round(px * FONT_RATIO));
|
|
41
|
+
const sizeClass = sizeMatch ? '' : 'h-16 w-16';
|
|
42
|
+
|
|
29
43
|
const avatarUri =
|
|
30
44
|
server && group
|
|
31
45
|
? getGroupAvatar(group, server.communityConfig)
|
|
32
46
|
: group?.avatar;
|
|
33
47
|
|
|
34
48
|
const hue = hueFromHandle(group?.handle ?? '');
|
|
35
|
-
const backgroundColor =
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const backgroundColor = initialsBackground(hue, isDark);
|
|
50
|
+
|
|
51
|
+
// The initials tile is the underlay behind the image branch (absolutely
|
|
52
|
+
// positioned to fill the avatar box): while the group avatar is still
|
|
53
|
+
// downloading — or permanently, when the media cache cannot produce the
|
|
54
|
+
// file — it is the visible content, and it doubles as the standalone
|
|
55
|
+
// content for no-avatar groups. Either way the slot carries sized,
|
|
56
|
+
// centered content (issue #1666).
|
|
57
|
+
const initialsTile = (
|
|
58
|
+
<View
|
|
59
|
+
className={cn(
|
|
60
|
+
'absolute inset-0 flex items-center justify-center',
|
|
61
|
+
roundedClass
|
|
62
|
+
)}
|
|
63
|
+
style={{ backgroundColor }}
|
|
64
|
+
>
|
|
65
|
+
<Text className="text-foreground font-medium" style={{ fontSize }}>
|
|
66
|
+
{getInitials(group?.displayName, group?.handle)}
|
|
67
|
+
</Text>
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
38
70
|
|
|
39
71
|
return (
|
|
40
72
|
<Avatar
|
|
@@ -47,26 +79,16 @@ export const GroupAvatar = ({
|
|
|
47
79
|
)}
|
|
48
80
|
>
|
|
49
81
|
{avatarUri ? (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
<>
|
|
83
|
+
{initialsTile}
|
|
84
|
+
<AvatarImage
|
|
85
|
+
source={{ uri: avatarUri }}
|
|
86
|
+
className={cn('h-full w-full', roundedClass)}
|
|
87
|
+
resizeMode="cover"
|
|
88
|
+
/>
|
|
89
|
+
</>
|
|
55
90
|
) : (
|
|
56
|
-
|
|
57
|
-
className={cn(
|
|
58
|
-
'flex h-full w-full items-center justify-center',
|
|
59
|
-
roundedClass
|
|
60
|
-
)}
|
|
61
|
-
style={{ backgroundColor }}
|
|
62
|
-
>
|
|
63
|
-
<Text
|
|
64
|
-
className="text-foreground font-medium"
|
|
65
|
-
style={{ fontSize: isSmall ? 14 : 24 }}
|
|
66
|
-
>
|
|
67
|
-
{getInitials(group?.displayName, group?.handle)}
|
|
68
|
-
</Text>
|
|
69
|
-
</View>
|
|
91
|
+
initialsTile
|
|
70
92
|
)}
|
|
71
93
|
</Avatar>
|
|
72
94
|
);
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for the waiting-room join toast on the native surface.
|
|
3
|
+
*
|
|
4
|
+
* The shared hook (useJamFooterControls) fires `showToast` when someone joins;
|
|
5
|
+
* the only code that turns that into a user-visible toast lives here in the
|
|
6
|
+
* native footer — `useThemedToastConfig` (which must expose an `info` entry
|
|
7
|
+
* built from the theme palette, else a missing/wrong `type` would render an
|
|
8
|
+
* unstyled default toast or nothing) and `useFooterControls().showToast`
|
|
9
|
+
* (which must route to `Toast.show({ type: 'info', ... })`).
|
|
10
|
+
*
|
|
11
|
+
* Only react-native, livekit, i18n and the heavy footer siblings are stubbed.
|
|
12
|
+
* `useThemedToastConfig` runs against the real `mapColors` so the expected hex
|
|
13
|
+
* values are the ones the app actually ships. `useJamFooterControls` is stubbed
|
|
14
|
+
* to echo back the args object, so `useFooterControls()` returns the real
|
|
15
|
+
* `showToast` closure the footer built — exactly the code under test — without
|
|
16
|
+
* loading the hook's full React dependency graph.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const React = require('react');
|
|
20
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
21
|
+
|
|
22
|
+
const { mapColors } = require('../../theme/defaults');
|
|
23
|
+
|
|
24
|
+
const toastShowMock = jest.fn();
|
|
25
|
+
let mockIsDark = false;
|
|
26
|
+
|
|
27
|
+
const tMock = (key: string, opts?: Record<string, unknown>) =>
|
|
28
|
+
key.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
|
|
29
|
+
String(opts?.[n] ?? '')
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
jest.mock('react-native', () => ({
|
|
33
|
+
View: (props: { style?: unknown; className?: string; children?: unknown }) =>
|
|
34
|
+
React.createElement(
|
|
35
|
+
'View',
|
|
36
|
+
{ style: props.style, className: props.className },
|
|
37
|
+
props.children
|
|
38
|
+
),
|
|
39
|
+
Text: (props: { children?: unknown }) =>
|
|
40
|
+
React.createElement('Text', null, props.children),
|
|
41
|
+
Pressable: (props: { children?: unknown }) =>
|
|
42
|
+
React.createElement('Pressable', null, props.children),
|
|
43
|
+
Alert: { alert: jest.fn() },
|
|
44
|
+
StyleSheet: { create: (s: unknown) => s },
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
jest.mock('react-native-toast-message', () => ({
|
|
48
|
+
__esModule: true,
|
|
49
|
+
default: { show: toastShowMock },
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
jest.mock('@livekit/react-native', () => ({
|
|
53
|
+
useRoomContext: () => ({}),
|
|
54
|
+
useParticipants: () => [],
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
jest.mock('react-i18next', () => ({
|
|
58
|
+
useTranslation: () => ({ t: tMock }),
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
62
|
+
// Echo back the args object so useFooterControls() returns the real
|
|
63
|
+
// showToast closure the footer built (the code under test).
|
|
64
|
+
useJamFooterControls: (args: unknown) => args,
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
|
|
68
|
+
useOpenPeepsTheme: () => ({
|
|
69
|
+
isDark: mockIsDark,
|
|
70
|
+
colors: mapColors(mockIsDark),
|
|
71
|
+
buttonRadius: '9999px',
|
|
72
|
+
refresh: () => {},
|
|
73
|
+
}),
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
jest.mock('../../theme/useThemeOpacity', () => ({
|
|
77
|
+
useThemeOpacity: () => ({ background: () => ({}) }),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
jest.mock('./JamDeviceSelectors', () => ({
|
|
81
|
+
JamAudioOutputSelector: () => React.createElement('JamAudioOutputSelector'),
|
|
82
|
+
JamCameraSelector: () => React.createElement('JamCameraSelector'),
|
|
83
|
+
JamMicSelector: () => React.createElement('JamMicSelector'),
|
|
84
|
+
}));
|
|
85
|
+
jest.mock('./JamReactionMenu', () => ({
|
|
86
|
+
JamReactionMenu: () => React.createElement('JamReactionMenu'),
|
|
87
|
+
}));
|
|
88
|
+
jest.mock('./JamToolbarButton', () => ({
|
|
89
|
+
JamToolbarButton: ({ children }: { children?: unknown }) =>
|
|
90
|
+
React.createElement('JamToolbarButton', null, children),
|
|
91
|
+
toneIconClass: { default: '', active: '' },
|
|
92
|
+
}));
|
|
93
|
+
jest.mock('./LeaveCloseButton', () => ({
|
|
94
|
+
LeaveCloseButton: () => React.createElement('LeaveCloseButton'),
|
|
95
|
+
}));
|
|
96
|
+
jest.mock('../icons/index', () => ({
|
|
97
|
+
CircleEllipsisIcon: () => React.createElement('i'),
|
|
98
|
+
CircleStopIcon: () => React.createElement('i'),
|
|
99
|
+
DiscIcon: () => React.createElement('i'),
|
|
100
|
+
HandIcon: () => React.createElement('i'),
|
|
101
|
+
InfoIcon: () => React.createElement('i'),
|
|
102
|
+
LaughIcon: () => React.createElement('i'),
|
|
103
|
+
MessageSquareTextIcon: () => React.createElement('i'),
|
|
104
|
+
UsersRoundIcon: () => React.createElement('i'),
|
|
105
|
+
}));
|
|
106
|
+
jest.mock('../ui/themed-text', () => ({
|
|
107
|
+
ThemedText: (props: {
|
|
108
|
+
children?: unknown;
|
|
109
|
+
className?: string;
|
|
110
|
+
style?: unknown;
|
|
111
|
+
}) =>
|
|
112
|
+
React.createElement(
|
|
113
|
+
'ThemedText',
|
|
114
|
+
{
|
|
115
|
+
className: props.className,
|
|
116
|
+
style: props.style,
|
|
117
|
+
},
|
|
118
|
+
props.children
|
|
119
|
+
),
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
const { useThemedToastConfig, useFooterControls } = require('./JamFooter');
|
|
123
|
+
|
|
124
|
+
/** Capture the value a hook returns by rendering a component that calls it. */
|
|
125
|
+
const captureHook = <T,>(fn: () => T): T => {
|
|
126
|
+
let value!: T;
|
|
127
|
+
const Capture = () => {
|
|
128
|
+
value = fn();
|
|
129
|
+
return null;
|
|
130
|
+
};
|
|
131
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
132
|
+
ReactTestRenderer.act(() => {
|
|
133
|
+
tree = ReactTestRenderer.create(
|
|
134
|
+
React.createElement(Capture as () => unknown)
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
ReactTestRenderer.act(() => {
|
|
138
|
+
tree.unmount();
|
|
139
|
+
});
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** Render a toast-layout element and return its root View's props. */
|
|
144
|
+
const renderToastBody = (
|
|
145
|
+
layout: (p: { text1?: string }) => unknown,
|
|
146
|
+
text1: string
|
|
147
|
+
) => {
|
|
148
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
149
|
+
ReactTestRenderer.act(() => {
|
|
150
|
+
tree = ReactTestRenderer.create(React.createElement(layout, { text1 }));
|
|
151
|
+
});
|
|
152
|
+
// Read props while the tree is still mounted (instances go stale after
|
|
153
|
+
// unmount); do this outside the create-act, as the repo's existing
|
|
154
|
+
// react-test-renderer tests do.
|
|
155
|
+
const props = {
|
|
156
|
+
className: tree.root.findByType('View').props.className,
|
|
157
|
+
style: tree.root.findByType('View').props.style,
|
|
158
|
+
};
|
|
159
|
+
ReactTestRenderer.act(() => {
|
|
160
|
+
tree.unmount();
|
|
161
|
+
});
|
|
162
|
+
return props;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
describe('useThemedToastConfig', () => {
|
|
166
|
+
it('exposes an info entry built from the theme tokens (light)', () => {
|
|
167
|
+
mockIsDark = false;
|
|
168
|
+
const config = captureHook(useThemedToastConfig);
|
|
169
|
+
|
|
170
|
+
expect(config.info).toBeDefined();
|
|
171
|
+
// Missing `info` from the config is the regression this pins: without it
|
|
172
|
+
// `Toast.show({ type: 'info' })` would fall back to an unstyled default.
|
|
173
|
+
const props = renderToastBody(
|
|
174
|
+
config.info as (p: { text1?: string }) => unknown,
|
|
175
|
+
'1 person joined the waiting room'
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Shipped light palette: info = card background + foreground text.
|
|
179
|
+
expect(props.style).toEqual([
|
|
180
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
181
|
+
{ backgroundColor: '#ffffff', borderColor: '#0a0a0b' },
|
|
182
|
+
]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('keeps success on the primary palette (distinct from info)', () => {
|
|
186
|
+
mockIsDark = false;
|
|
187
|
+
const config = captureHook(useThemedToastConfig);
|
|
188
|
+
|
|
189
|
+
const props = renderToastBody(
|
|
190
|
+
config.success as (p: { text1?: string }) => unknown,
|
|
191
|
+
'recording saved'
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// success = primary background + primary-foreground text (light).
|
|
195
|
+
expect(props.style).toEqual([
|
|
196
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
197
|
+
{ backgroundColor: '#16161a', borderColor: '#fafafa' },
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('adapts the info palette to the dark theme', () => {
|
|
202
|
+
mockIsDark = true;
|
|
203
|
+
const config = captureHook(useThemedToastConfig);
|
|
204
|
+
|
|
205
|
+
const props = renderToastBody(
|
|
206
|
+
config.info as (p: { text1?: string }) => unknown,
|
|
207
|
+
'someone joined'
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// Shipped dark palette: card = #0a0a0f, foreground = #fafafa.
|
|
211
|
+
expect(props.style).toEqual([
|
|
212
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
213
|
+
{ backgroundColor: '#0a0a0f', borderColor: '#fafafa' },
|
|
214
|
+
]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('keeps error on the destructive palette (distinct from info)', () => {
|
|
218
|
+
mockIsDark = false;
|
|
219
|
+
const config = captureHook(useThemedToastConfig);
|
|
220
|
+
|
|
221
|
+
const props = renderToastBody(
|
|
222
|
+
config.error as (p: { text1?: string }) => unknown,
|
|
223
|
+
'recording failed'
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
// error = destructive background + destructive-foreground text (light).
|
|
227
|
+
expect(props.style).toEqual([
|
|
228
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
229
|
+
{ backgroundColor: '#ef4444', borderColor: '#fafafa' },
|
|
230
|
+
]);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('useFooterControls().showToast (native)', () => {
|
|
235
|
+
it('routes a waiting-room join to Toast.show with type info', () => {
|
|
236
|
+
mockIsDark = false;
|
|
237
|
+
const result: { showToast: (text1: string) => void } =
|
|
238
|
+
captureHook(useFooterControls);
|
|
239
|
+
|
|
240
|
+
expect(typeof result.showToast).toBe('function');
|
|
241
|
+
|
|
242
|
+
toastShowMock.mockClear();
|
|
243
|
+
ReactTestRenderer.act(() => {
|
|
244
|
+
result.showToast('2 people joined the waiting room');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(toastShowMock).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(toastShowMock).toHaveBeenCalledWith({
|
|
249
|
+
type: 'info',
|
|
250
|
+
text1: '2 people joined the waiting room',
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import { Alert, Pressable, View } from 'react-native';
|
|
3
3
|
import { useParticipants, useRoomContext } from '@livekit/react-native';
|
|
4
|
-
import Toast
|
|
4
|
+
import Toast, {
|
|
5
|
+
type ToastConfig,
|
|
6
|
+
type ToastConfigParams,
|
|
7
|
+
} from 'react-native-toast-message';
|
|
5
8
|
import { useTranslation } from 'react-i18next';
|
|
6
9
|
import { useJamFooterControls } from '@openpeepshq/react';
|
|
7
10
|
import {
|
|
@@ -15,6 +18,7 @@ import {
|
|
|
15
18
|
UsersRoundIcon,
|
|
16
19
|
} from '../icons/index';
|
|
17
20
|
import { ThemedText } from '../ui/themed-text';
|
|
21
|
+
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
18
22
|
import {
|
|
19
23
|
JamAudioOutputSelector,
|
|
20
24
|
JamCameraSelector,
|
|
@@ -26,6 +30,58 @@ import { JamToolbarButton, toneIconClass } from './JamToolbarButton';
|
|
|
26
30
|
import { LeaveCloseButton } from './LeaveCloseButton';
|
|
27
31
|
import { useThemeOpacity } from '../../theme/useThemeOpacity';
|
|
28
32
|
|
|
33
|
+
/** Themed toast body; the library default colors sit off the app palette. */
|
|
34
|
+
const TOAST_BODY = {
|
|
35
|
+
borderWidth: 1,
|
|
36
|
+
borderRadius: 8,
|
|
37
|
+
paddingHorizontal: 16,
|
|
38
|
+
paddingVertical: 10,
|
|
39
|
+
maxWidth: '90%' as const,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const ThemedToast = ({
|
|
43
|
+
text1,
|
|
44
|
+
bg,
|
|
45
|
+
fg,
|
|
46
|
+
}: {
|
|
47
|
+
text1?: string;
|
|
48
|
+
bg: string;
|
|
49
|
+
fg: string;
|
|
50
|
+
}) => (
|
|
51
|
+
<View style={[TOAST_BODY, { backgroundColor: bg, borderColor: fg }]}>
|
|
52
|
+
<ThemedText style={{ color: fg }} className="text-sm font-medium">
|
|
53
|
+
{text1}
|
|
54
|
+
</ThemedText>
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
/** Toast layouts mapped to theme tokens (success, error/destructive, info/primary). */
|
|
59
|
+
export const useThemedToastConfig = (): ToastConfig => {
|
|
60
|
+
const { colors } = useOpenPeepsTheme();
|
|
61
|
+
return useMemo(
|
|
62
|
+
() => ({
|
|
63
|
+
success: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
|
|
64
|
+
<ThemedToast
|
|
65
|
+
text1={text1}
|
|
66
|
+
bg={colors.primary}
|
|
67
|
+
fg={colors['primary-foreground']}
|
|
68
|
+
/>
|
|
69
|
+
),
|
|
70
|
+
error: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
|
|
71
|
+
<ThemedToast
|
|
72
|
+
text1={text1}
|
|
73
|
+
bg={colors.destructive}
|
|
74
|
+
fg={colors['destructive-foreground']}
|
|
75
|
+
/>
|
|
76
|
+
),
|
|
77
|
+
info: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
|
|
78
|
+
<ThemedToast text1={text1} bg={colors.card} fg={colors.foreground} />
|
|
79
|
+
),
|
|
80
|
+
}),
|
|
81
|
+
[colors]
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
29
85
|
export interface JamFooterProps {
|
|
30
86
|
chatOpen: boolean;
|
|
31
87
|
onToggleChat: () => void;
|
|
@@ -45,6 +101,13 @@ export const useFooterControls = () => {
|
|
|
45
101
|
const room = useRoomContext();
|
|
46
102
|
const participants = useParticipants();
|
|
47
103
|
|
|
104
|
+
// Stable identity: the footer controls hook lists showToast in an effect
|
|
105
|
+
// deps array, and an inline lambda would tear that effect down every render.
|
|
106
|
+
// Waiting-room joins are neutral info on native.
|
|
107
|
+
const showToast = useCallback((text1: string) => {
|
|
108
|
+
Toast.show({ type: 'info', text1 });
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
48
111
|
const confirmStopRecording = () =>
|
|
49
112
|
new Promise<boolean>((resolve) => {
|
|
50
113
|
Alert.alert('', t('jams.recording.stopConfirm'), [
|
|
@@ -67,6 +130,7 @@ export const useFooterControls = () => {
|
|
|
67
130
|
confirmStopRecording,
|
|
68
131
|
onSuccess: (text1) => Toast.show({ type: 'success', text1 }),
|
|
69
132
|
onError: (text1) => Toast.show({ type: 'error', text1 }),
|
|
133
|
+
showToast,
|
|
70
134
|
});
|
|
71
135
|
};
|
|
72
136
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useRoomContext,
|
|
8
8
|
useTracks,
|
|
9
9
|
} from '@livekit/react-native';
|
|
10
|
+
import Toast from 'react-native-toast-message';
|
|
10
11
|
import { Track } from 'livekit-client';
|
|
11
12
|
import { truncateText } from '@openpeepshq/common';
|
|
12
13
|
import {
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
JamsBannerStack,
|
|
30
31
|
} from './JamRoomIndicators';
|
|
31
32
|
import { JamVideoLayout } from './JamVideoLayout';
|
|
33
|
+
import { useThemedToastConfig } from './JamFooter';
|
|
32
34
|
|
|
33
35
|
type Drawer = 'chat' | 'people' | 'details' | null;
|
|
34
36
|
|
|
@@ -39,6 +41,7 @@ const JamParticipantConferenceInner = () => {
|
|
|
39
41
|
const [drawer, setDrawer] = useState<Drawer>(null);
|
|
40
42
|
const [settings, updateSettings] = useJamLocalSettings();
|
|
41
43
|
const remoteParticipants = useRemoteParticipants();
|
|
44
|
+
const toastConfig = useThemedToastConfig();
|
|
42
45
|
|
|
43
46
|
const tracks = useTracks(
|
|
44
47
|
[
|
|
@@ -100,6 +103,7 @@ const JamParticipantConferenceInner = () => {
|
|
|
100
103
|
<JamObserverBanner />
|
|
101
104
|
<JamRecordingIndicator />
|
|
102
105
|
</JamsBannerStack>
|
|
106
|
+
<Toast config={toastConfig} />
|
|
103
107
|
<View className="relative min-h-0 w-full flex-1 overflow-hidden p-2">
|
|
104
108
|
<View className="min-h-0 flex-1 overflow-hidden">
|
|
105
109
|
<View className="shrink-0 flex-row items-center">
|
|
@@ -344,7 +344,12 @@ export const EventForm = ({
|
|
|
344
344
|
|
|
345
345
|
<SectionTitle>{t('events.form.location')}</SectionTitle>
|
|
346
346
|
|
|
347
|
-
<EventTypeSwitcher
|
|
347
|
+
<EventTypeSwitcher
|
|
348
|
+
event={event}
|
|
349
|
+
isEdit={isEdit}
|
|
350
|
+
onChange={setEvent}
|
|
351
|
+
visibility={postData.visibility}
|
|
352
|
+
/>
|
|
348
353
|
|
|
349
354
|
<SectionTitle>{t('events.form.people')}</SectionTitle>
|
|
350
355
|
|