@openpeepshq/rn-components 0.18.0 → 0.20.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/conversations/ConversationMessageBubble.test.tsx +158 -0
- package/src/components/conversations/ConversationMessageBubble.tsx +43 -25
- package/src/components/groups/GroupAvatar.test.tsx +166 -0
- package/src/components/groups/GroupAvatar.tsx +46 -24
- package/src/components/jams/JamReactionMenu.tsx +10 -31
- package/src/components/post/pieces/PostActions.test.tsx +27 -19
- package/src/components/post/pieces/PostActions.tsx +7 -11
- package/src/components/post/pieces/ReactionButton.tsx +41 -0
- package/src/components/post/pieces/ReactionPicker.test.tsx +80 -161
- package/src/components/post/pieces/ReactionPicker.tsx +32 -33
- package/src/components/post/pieces/index.ts +1 -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.20.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/common": "^0.13.0",
|
|
146
|
+
"@openpeepshq/fetch-client": "^0.2.1",
|
|
147
|
+
"@openpeepshq/react": "^0.21.0"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"@babel/core": "^7.26.7",
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for the native DM-bubble reaction wiring (issue #276,
|
|
3
|
+
* round-5 review item #2) — the mirror of the web bubble test. The bubble must
|
|
4
|
+
* feed the picker the profile's reactions and the community's allowed set, and
|
|
5
|
+
* route the picker's toggle back through `usePostReactionToggle` (which also
|
|
6
|
+
* closes the picker). Without this, a DM bubble could silently drop the picker
|
|
7
|
+
* or call the toggle with the wrong emoji.
|
|
8
|
+
*
|
|
9
|
+
* Only the RN primitives, i18n, theme, and the `@openpeepshq/react` hooks are
|
|
10
|
+
* stubbed; the real `ConversationMessageBubble` open/close state machine runs.
|
|
11
|
+
* The picker is stubbed to a self-describing host tag so its props are read
|
|
12
|
+
* from the rendered tree.
|
|
13
|
+
*/
|
|
14
|
+
const React = require('react');
|
|
15
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
16
|
+
|
|
17
|
+
const mockToggle = jest.fn();
|
|
18
|
+
const mockCanReact = { value: true };
|
|
19
|
+
const mockMyReactions = { value: ['👍'] };
|
|
20
|
+
const mockAllowed = { value: ['👍', '🎉'] as readonly string[] };
|
|
21
|
+
|
|
22
|
+
jest.mock('react-native', () => ({
|
|
23
|
+
View: (p: { children?: unknown }) =>
|
|
24
|
+
React.createElement('View', null, p.children),
|
|
25
|
+
Text: (p: { children?: unknown }) =>
|
|
26
|
+
React.createElement('Text', null, p.children),
|
|
27
|
+
Pressable: (p: { onPress?: () => void; children?: unknown }) =>
|
|
28
|
+
React.createElement('Pressable', { onPress: p.onPress }, p.children),
|
|
29
|
+
}));
|
|
30
|
+
jest.mock('react-i18next', () => ({
|
|
31
|
+
useTranslation: () => ({ t: (key: string) => key }),
|
|
32
|
+
}));
|
|
33
|
+
jest.mock('../../theme/useThemeOpacity', () => ({
|
|
34
|
+
useThemeOpacity: () => ({ background: () => undefined }),
|
|
35
|
+
}));
|
|
36
|
+
jest.mock('../post/FeedPostContent', () => ({
|
|
37
|
+
FeedPostContent: () => null,
|
|
38
|
+
}));
|
|
39
|
+
jest.mock('../post/pieces/UnreadPostIndicator', () => ({
|
|
40
|
+
UnreadPostIndicator: () => null,
|
|
41
|
+
}));
|
|
42
|
+
jest.mock('../icons/index', () => ({
|
|
43
|
+
ThumbsUpIcon: () => null,
|
|
44
|
+
}));
|
|
45
|
+
// The closed trigger shows the reaction count next to the icon (round-10
|
|
46
|
+
// review item #1/#2). Mock ThemedText to a host tag that carries the count so
|
|
47
|
+
// the display can be asserted without loading @rn-primitives.
|
|
48
|
+
jest.mock('../ui/themed-text', () => ({
|
|
49
|
+
ThemedText: (p: { children?: unknown; className?: string }) =>
|
|
50
|
+
React.createElement(
|
|
51
|
+
'CountText',
|
|
52
|
+
{ 'data-count': String(p.children) },
|
|
53
|
+
p.children
|
|
54
|
+
),
|
|
55
|
+
}));
|
|
56
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
57
|
+
useCurrentProfile: () => ({ id: 'me-1' }),
|
|
58
|
+
usePostReactionToggle: () => ({
|
|
59
|
+
iLiked: false,
|
|
60
|
+
myReactions: mockMyReactions.value,
|
|
61
|
+
canReact: mockCanReact.value,
|
|
62
|
+
toggleReaction: mockToggle,
|
|
63
|
+
}),
|
|
64
|
+
useAllowedReactions: () => mockAllowed.value,
|
|
65
|
+
}));
|
|
66
|
+
jest.mock('../post/pieces/ReactionPicker', () => ({
|
|
67
|
+
ReactionPicker: (props: {
|
|
68
|
+
myReactions: string[];
|
|
69
|
+
reactions: readonly string[];
|
|
70
|
+
onToggle: (reaction: string) => void;
|
|
71
|
+
}) =>
|
|
72
|
+
React.createElement(
|
|
73
|
+
'PICKER',
|
|
74
|
+
{ onPress: () => props.onToggle('🎉') },
|
|
75
|
+
`MR=${JSON.stringify(props.myReactions)}`,
|
|
76
|
+
`RC=${JSON.stringify(props.reactions)}`
|
|
77
|
+
),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
const { ConversationMessageBubble } = require('./ConversationMessageBubble');
|
|
81
|
+
|
|
82
|
+
const renderBubble = (message: unknown) => {
|
|
83
|
+
let tree!: ReturnType<typeof ReactTestRenderer.create>;
|
|
84
|
+
ReactTestRenderer.act(() => {
|
|
85
|
+
tree = ReactTestRenderer.create(
|
|
86
|
+
React.createElement(ConversationMessageBubble, { message })
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
return tree;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const message = { id: 'post-1', profile: { id: 'other-1' } };
|
|
93
|
+
|
|
94
|
+
describe('ConversationMessageBubble (native) reaction wiring', () => {
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
mockToggle.mockClear();
|
|
97
|
+
mockCanReact.value = true;
|
|
98
|
+
mockMyReactions.value = ['👍'];
|
|
99
|
+
mockAllowed.value = ['👍', '🎉'];
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('feeds the picker the profile reactions and allowed set on open', () => {
|
|
103
|
+
const tree = renderBubble(message);
|
|
104
|
+
// Closed by default: a thumbs-up trigger, no picker yet.
|
|
105
|
+
expect(tree.root.findAllByType('PICKER').length).toBe(0);
|
|
106
|
+
const trigger = tree.root.findAllByType('Pressable')[0];
|
|
107
|
+
ReactTestRenderer.act(() => {
|
|
108
|
+
trigger.props.onPress();
|
|
109
|
+
});
|
|
110
|
+
// The picker opened and was fed the profile reactions + allowed set.
|
|
111
|
+
const picker = tree.root.findAllByType('PICKER')[0];
|
|
112
|
+
const text = (picker.children ?? []).join(' ');
|
|
113
|
+
expect(text).toContain('MR=["👍"]');
|
|
114
|
+
expect(text).toContain('RC=["👍","🎉"]');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('routes the picker toggle through toggleReaction and closes', () => {
|
|
118
|
+
const tree = renderBubble(message);
|
|
119
|
+
ReactTestRenderer.act(() => {
|
|
120
|
+
tree.root.findAllByType('Pressable')[0].props.onPress();
|
|
121
|
+
});
|
|
122
|
+
const picker = tree.root.findAllByType('PICKER')[0];
|
|
123
|
+
ReactTestRenderer.act(() => {
|
|
124
|
+
picker.props.onPress();
|
|
125
|
+
});
|
|
126
|
+
expect(mockToggle).toHaveBeenCalledWith('🎉');
|
|
127
|
+
// The picker closed back to the trigger.
|
|
128
|
+
expect(tree.root.findAllByType('PICKER').length).toBe(0);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('renders no trigger when the profile cannot react', () => {
|
|
132
|
+
mockCanReact.value = false;
|
|
133
|
+
const tree = renderBubble(message);
|
|
134
|
+
expect(tree.root.findAllByType('Pressable').length).toBe(0);
|
|
135
|
+
expect(tree.root.findAllByType('PICKER').length).toBe(0);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('hides the reaction count on the closed trigger when there are no reactions', () => {
|
|
139
|
+
const tree = renderBubble({ ...message, reactions: [] });
|
|
140
|
+
expect(tree.root.findAllByType('CountText').length).toBe(0);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('shows the reaction count on the closed trigger when reactions exist', () => {
|
|
144
|
+
const withReactions = {
|
|
145
|
+
...message,
|
|
146
|
+
reactions: [
|
|
147
|
+
{ reaction: '👍', profile: { id: 'other-2' } },
|
|
148
|
+
{ reaction: '🎉', profile: { id: 'other-3' } },
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
const tree = renderBubble(withReactions);
|
|
152
|
+
const counts = tree.root.findAllByType('CountText');
|
|
153
|
+
expect(counts).toHaveLength(1);
|
|
154
|
+
expect(counts[0].props['data-count']).toBe('2');
|
|
155
|
+
// The picker is still closed: the count is on the trigger, not a picker.
|
|
156
|
+
expect(tree.root.findAllByType('PICKER').length).toBe(0);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import type { PublicPost } from '@openpeepshq/common/types';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
useCurrentProfile,
|
|
7
|
+
usePostReactionToggle,
|
|
8
|
+
useAllowedReactions,
|
|
9
|
+
} from '@openpeepshq/react';
|
|
6
10
|
import { useThemeOpacity } from '../../theme/useThemeOpacity';
|
|
7
11
|
import { FeedPostContent } from '../post/FeedPostContent';
|
|
8
12
|
import { UnreadPostIndicator } from '../post/pieces/UnreadPostIndicator';
|
|
9
|
-
import {
|
|
10
|
-
import { ThemedText } from '../ui/themed-text';
|
|
13
|
+
import { ReactionPicker } from '../post/pieces/ReactionPicker';
|
|
11
14
|
import { ThumbsUpIcon } from '../icons/index';
|
|
15
|
+
import { ThemedText } from '../ui/themed-text';
|
|
12
16
|
|
|
13
17
|
export interface ConversationMessageBubbleProps {
|
|
14
18
|
message: PublicPost;
|
|
@@ -23,7 +27,10 @@ export const ConversationMessageBubble = ({
|
|
|
23
27
|
const { background } = useThemeOpacity();
|
|
24
28
|
const { t } = useTranslation();
|
|
25
29
|
const mine = message.profile.id === me?.id;
|
|
26
|
-
const {
|
|
30
|
+
const { iLiked, myReactions, canReact, toggleReaction } =
|
|
31
|
+
usePostReactionToggle(message);
|
|
32
|
+
const allowedReactions = useAllowedReactions();
|
|
33
|
+
const [reactionPickerOpen, setReactionPickerOpen] = useState(false);
|
|
27
34
|
const reactionCount = message.reactions?.length ?? 0;
|
|
28
35
|
|
|
29
36
|
// NativeWind v4 can't apply `/N` opacity to CSS-variable colors (e.g.
|
|
@@ -49,26 +56,37 @@ export const ConversationMessageBubble = ({
|
|
|
49
56
|
mine ? 'mt-2 flex-row justify-end' : 'mt-2 flex-row justify-start'
|
|
50
57
|
}
|
|
51
58
|
>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
className={iReacted ? 'text-primary' : 'text-muted-foreground'}
|
|
59
|
+
{reactionPickerOpen ? (
|
|
60
|
+
<ReactionPicker
|
|
61
|
+
myReactions={myReactions}
|
|
62
|
+
reactions={allowedReactions}
|
|
63
|
+
onToggle={(reaction) => {
|
|
64
|
+
setReactionPickerOpen(false);
|
|
65
|
+
void toggleReaction(reaction);
|
|
66
|
+
}}
|
|
61
67
|
/>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
) : (
|
|
69
|
+
<Pressable
|
|
70
|
+
className="items-center gap-1"
|
|
71
|
+
accessibilityRole="button"
|
|
72
|
+
accessibilityLabel={t('posts.actions.react')}
|
|
73
|
+
onPress={() => setReactionPickerOpen(true)}
|
|
74
|
+
>
|
|
75
|
+
<ThumbsUpIcon
|
|
76
|
+
size={16}
|
|
77
|
+
className={iLiked ? 'text-primary' : 'text-muted-foreground'}
|
|
78
|
+
/>
|
|
79
|
+
{reactionCount > 0 ? (
|
|
80
|
+
<ThemedText
|
|
81
|
+
className={`text-xs ${
|
|
82
|
+
iLiked ? 'text-primary' : 'text-muted-foreground'
|
|
83
|
+
}`}
|
|
84
|
+
>
|
|
85
|
+
{reactionCount}
|
|
86
|
+
</ThemedText>
|
|
87
|
+
) : null}
|
|
88
|
+
</Pressable>
|
|
89
|
+
)}
|
|
72
90
|
</View>
|
|
73
91
|
) : null}
|
|
74
92
|
</View>
|
|
@@ -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
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ScrollView, View } from 'react-native';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import {
|
|
5
5
|
SKIN_TONE_OPTIONS,
|
|
@@ -10,33 +10,12 @@ import {
|
|
|
10
10
|
isDefaultEmoji,
|
|
11
11
|
useJamReactionPreferences,
|
|
12
12
|
} from '@openpeepshq/react';
|
|
13
|
-
import {
|
|
14
|
-
import { cn } from '../../lib/utils';
|
|
13
|
+
import { ReactionButton } from '../post/pieces/ReactionButton';
|
|
15
14
|
|
|
16
15
|
export interface JamReactionMenuProps {
|
|
17
16
|
onSelect: (emoji: string) => void | Promise<void>;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
const EmojiButton = ({
|
|
21
|
-
emoji,
|
|
22
|
-
title,
|
|
23
|
-
active,
|
|
24
|
-
onPress,
|
|
25
|
-
}: {
|
|
26
|
-
emoji: string;
|
|
27
|
-
title: string;
|
|
28
|
-
active?: boolean;
|
|
29
|
-
onPress: () => void;
|
|
30
|
-
}) => (
|
|
31
|
-
<Pressable
|
|
32
|
-
accessibilityLabel={title}
|
|
33
|
-
onPress={onPress}
|
|
34
|
-
className={cn('shrink-0 rounded-md p-2', active && 'bg-border')}
|
|
35
|
-
>
|
|
36
|
-
<ThemedText className="text-lg">{emoji}</ThemedText>
|
|
37
|
-
</Pressable>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
19
|
/**
|
|
41
20
|
* Reaction picker: a quick row of default emojis (with the preferred skin
|
|
42
21
|
* tone applied), recently used emojis and a skin-tone selector. The web "all
|
|
@@ -73,9 +52,9 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
73
52
|
contentContainerClassName="flex-row items-center gap-x-1"
|
|
74
53
|
>
|
|
75
54
|
{defaultEmojis.map((emoji) => (
|
|
76
|
-
<
|
|
55
|
+
<ReactionButton
|
|
77
56
|
key={emoji}
|
|
78
|
-
|
|
57
|
+
reaction={emoji}
|
|
79
58
|
title={emoji}
|
|
80
59
|
onPress={() => void onSelect(emoji)}
|
|
81
60
|
/>
|
|
@@ -84,9 +63,9 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
84
63
|
<>
|
|
85
64
|
<View className="mx-1 h-8 w-px shrink-0 bg-border" />
|
|
86
65
|
{recentDisplayEmojis.map((emoji) => (
|
|
87
|
-
<
|
|
66
|
+
<ReactionButton
|
|
88
67
|
key={emoji}
|
|
89
|
-
|
|
68
|
+
reaction={emoji}
|
|
90
69
|
title={emoji}
|
|
91
70
|
onPress={() => void onSelect(emoji)}
|
|
92
71
|
/>
|
|
@@ -94,8 +73,8 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
94
73
|
</>
|
|
95
74
|
) : null}
|
|
96
75
|
<View className="mx-1 h-8 w-px shrink-0 bg-border" />
|
|
97
|
-
<
|
|
98
|
-
|
|
76
|
+
<ReactionButton
|
|
77
|
+
reaction={getSkinToneEmoji(skinTone)}
|
|
99
78
|
title={t('jams.reactions.skinToneTitle')}
|
|
100
79
|
active={showSkinToneSelector}
|
|
101
80
|
onPress={() => setShowSkinToneSelector((open) => !open)}
|
|
@@ -105,9 +84,9 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
105
84
|
{showSkinToneSelector ? (
|
|
106
85
|
<View className="mt-2 flex-row gap-1 border-t border-border pt-2">
|
|
107
86
|
{SKIN_TONE_OPTIONS.map((option) => (
|
|
108
|
-
<
|
|
87
|
+
<ReactionButton
|
|
109
88
|
key={option.tone}
|
|
110
|
-
|
|
89
|
+
reaction={option.emoji}
|
|
111
90
|
title={t('jams.reactions.skinToneTitle')}
|
|
112
91
|
active={skinTone === option.tone}
|
|
113
92
|
onPress={() => handleSetSkinTone(option.tone)}
|