@openpeepshq/rn-components 0.19.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.19.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/fetch-client": "^0.2.1",
146
145
  "@openpeepshq/common": "^0.13.0",
147
- "@openpeepshq/react": "^0.20.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 { useCurrentProfile, usePostReactionToggle } from '@openpeepshq/react';
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 { Button } from '../ui/button';
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 { iReacted, canReact, toggleReaction } = usePostReactionToggle(message);
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
- <Button
53
- variant="ghost"
54
- onPress={() => void toggleReaction()}
55
- accessibilityLabel={t('posts.actions.react')}
56
- className="items-center gap-1 native:px-2 native:py-1"
57
- >
58
- <ThumbsUpIcon
59
- size={16}
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
- {reactionCount > 0 ? (
63
- <ThemedText
64
- className={`text-xs ${
65
- iReacted ? 'text-primary' : 'text-muted-foreground'
66
- }`}
67
- >
68
- {reactionCount}
69
- </ThemedText>
70
- ) : null}
71
- </Button>
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>
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react';
2
- import { Pressable, ScrollView, View } from 'react-native';
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 { ThemedText } from '../ui/themed-text';
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
- <EmojiButton
55
+ <ReactionButton
77
56
  key={emoji}
78
- emoji={emoji}
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
- <EmojiButton
66
+ <ReactionButton
88
67
  key={emoji}
89
- emoji={emoji}
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
- <EmojiButton
98
- emoji={getSkinToneEmoji(skinTone)}
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
- <EmojiButton
87
+ <ReactionButton
109
88
  key={option.tone}
110
- emoji={option.emoji}
89
+ reaction={option.emoji}
111
90
  title={t('jams.reactions.skinToneTitle')}
112
91
  active={skinTone === option.tone}
113
92
  onPress={() => handleSetSkinTone(option.tone)}
@@ -1,11 +1,13 @@
1
1
  /**
2
- * Native PostActions reaction-picker wiring (issue #80 review round 5).
2
+ * Native PostActions reaction-picker wiring (issue #276, round-15 review item
3
+ * #2 — this suite was removed when the RN picker switched to the allowed-set
4
+ * model and is restored here).
3
5
  *
4
- * Pins that the RN PostActions React button opens the picker and threads
5
- * `myReactions` / `toggleReaction` / `onClose` through to it (the web path has
6
- * useFeedPostActions + ReactionPicker tests, but the native wiring was
7
- * untested). Mirrors PostMenu.test.tsx: node jest env, every external import
8
- * mocked — the decision under test is the button→picker threading.
6
+ * Pins that the RN PostActions Like button opens the picker and threads
7
+ * `myReactions`, the community `reactions` (from useAllowedReactions) and
8
+ * `onToggle` through to it. Mirrors PostMenu.test.tsx: node jest env, every
9
+ * external import mocked — the decision under test is the button→picker
10
+ * threading.
9
11
  */
10
12
  import { type ReactNode } from 'react';
11
13
  import ReactTestRenderer from 'react-test-renderer';
@@ -22,8 +24,8 @@ let mockCanReact = true;
22
24
  let lastPickerProps:
23
25
  | {
24
26
  myReactions: string[];
27
+ reactions: readonly string[];
25
28
  onToggle: (r: string) => void;
26
- onClose: () => void;
27
29
  }
28
30
  | undefined;
29
31
  const buttonInstances: { onPress?: () => void }[] = [];
@@ -47,12 +49,12 @@ jest.mock('react-i18next', () => ({
47
49
  }),
48
50
  }));
49
51
 
50
- // --- the feed action hook under test --------------------------------------
52
+ // --- the feed action hooks under test --------------------------------------
51
53
  jest.mock('@openpeepshq/react', () => ({
52
54
  useFeedPostActions: () => ({
53
55
  me: { id: 'me-1' },
54
56
  myRepost: undefined,
55
- iReacted: mockMyReactions.length > 0,
57
+ iLiked: mockMyReactions.includes('👍'),
56
58
  myReactions: mockMyReactions,
57
59
  canReply: true,
58
60
  canRepost: true,
@@ -61,14 +63,15 @@ jest.mock('@openpeepshq/react', () => ({
61
63
  toggleRepost,
62
64
  toggleReaction,
63
65
  }),
66
+ useAllowedReactions: () => REACTION_TYPES,
64
67
  }));
65
68
 
66
69
  // --- local UI: capture picker props and button presses --------------------
67
70
  jest.mock('./ReactionPicker', () => ({
68
71
  ReactionPicker: (props: {
69
72
  myReactions: string[];
73
+ reactions: readonly string[];
70
74
  onToggle: (r: string) => void;
71
- onClose: () => void;
72
75
  }) => {
73
76
  lastPickerProps = props;
74
77
  return null;
@@ -151,24 +154,24 @@ const renderPostActions = (
151
154
  return { tree };
152
155
  };
153
156
 
154
- /** The React button is the one whose text is the react footer label. */
157
+ /** The Like button is the one whose text is the react footer label. */
155
158
  const reactButtonPress = (json: unknown): (() => void) | undefined => {
156
159
  let found: (() => void) | undefined;
157
160
  walk(json, (n) => {
158
161
  if (found || n.type !== 'Button') return;
159
- if (collectText(n).includes('posts.footer.react')) {
162
+ if (collectText(n).includes('posts.footer.like')) {
160
163
  found = n.props?.onPress as () => void;
161
164
  }
162
165
  });
163
166
  return found;
164
167
  };
165
168
 
166
- /** The React button's `disabled` prop (undefined when the button is absent). */
169
+ /** The Like button's `disabled` prop (undefined when the button is absent). */
167
170
  const reactButtonDisabled = (json: unknown): boolean | undefined => {
168
171
  let found: boolean | undefined;
169
172
  walk(json, (n) => {
170
173
  if (found !== undefined || n.type !== 'Button') return;
171
- if (collectText(n).includes('posts.footer.react')) {
174
+ if (collectText(n).includes('posts.footer.like')) {
172
175
  found = n.props?.disabled as boolean | undefined;
173
176
  }
174
177
  });
@@ -186,7 +189,7 @@ beforeEach(() => {
186
189
  buttonInstances.length = 0;
187
190
  });
188
191
 
189
- test('tapping the React button opens the picker wired to the feed actions', () => {
192
+ test('tapping the Like button opens the picker wired to the feed actions', () => {
190
193
  const { tree } = renderPostActions(makePost());
191
194
  const press = reactButtonPress(tree.toJSON());
192
195
  expect(press).toBeTruthy();
@@ -198,6 +201,7 @@ test('tapping the React button opens the picker wired to the feed actions', () =
198
201
 
199
202
  expect(lastPickerProps).toBeDefined();
200
203
  expect(lastPickerProps?.myReactions).toEqual(['❤️']);
204
+ expect(lastPickerProps?.reactions).toEqual(REACTION_TYPES);
201
205
  tree.unmount();
202
206
  });
203
207
 
@@ -217,7 +221,10 @@ test('picking an emoji from the open picker calls toggleReaction with it', () =>
217
221
  tree.unmount();
218
222
  });
219
223
 
220
- test('the picker close control calls onClose without toggling a reaction', () => {
224
+ test('an orphan (no longer allowed) reaction still toggles', () => {
225
+ // The picker renders the profile's own reactions that are no longer in the
226
+ // community allowed set (orphans) so they stay retractable; the RN wrapper
227
+ // must thread them through onToggle the same as allowed reactions.
221
228
  const { tree } = renderPostActions(makePost());
222
229
  ReactTestRenderer.act(() => {
223
230
  reactButtonPress(tree.toJSON())!();
@@ -225,14 +232,15 @@ test('the picker close control calls onClose without toggling a reaction', () =>
225
232
  expect(lastPickerProps).toBeDefined();
226
233
 
227
234
  ReactTestRenderer.act(() => {
228
- lastPickerProps?.onClose();
235
+ lastPickerProps?.onToggle('🎉');
229
236
  });
230
237
 
231
- expect(toggleReaction).not.toHaveBeenCalled();
238
+ expect(toggleReaction).toHaveBeenCalledTimes(1);
239
+ expect(toggleReaction).toHaveBeenCalledWith('🎉');
232
240
  tree.unmount();
233
241
  });
234
242
 
235
- test('the React button renders disabled when the profile cannot react and has no reactions', () => {
243
+ test('the Like button renders disabled when the profile cannot react and has no reactions', () => {
236
244
  // Native mirror of the web ReactionPicker contract: without the react
237
245
  // capability and no existing reaction, the trigger is inert (the web path
238
246
  // pins this in ReactionPicker.test.tsx).
@@ -11,26 +11,24 @@ import {
11
11
  } from '../../icons/index';
12
12
  import { type PublicPost } from '@openpeepshq/common';
13
13
  import { useTranslation } from 'react-i18next';
14
- import { useFeedPostActions } from '@openpeepshq/react';
14
+ import { useFeedPostActions, useAllowedReactions } from '@openpeepshq/react';
15
15
  import { ReactionPicker } from './ReactionPicker';
16
16
  import { ShareMenu } from './ShareMenu';
17
17
 
18
18
  interface PostActionsProps {
19
19
  post: PublicPost;
20
20
  previewMode?: boolean;
21
- compact?: boolean;
22
21
  }
23
22
 
24
23
  export const PostActions = ({
25
24
  post,
26
25
  previewMode = false,
27
- compact: _compact = false,
28
26
  }: PostActionsProps) => {
29
27
  const { t } = useTranslation();
30
28
  const {
31
29
  me,
32
30
  myRepost,
33
- iReacted,
31
+ iLiked,
34
32
  myReactions,
35
33
  canReply,
36
34
  canRepost,
@@ -39,6 +37,7 @@ export const PostActions = ({
39
37
  toggleRepost,
40
38
  toggleReaction,
41
39
  } = useFeedPostActions(post);
40
+ const allowedReactions = useAllowedReactions();
42
41
  const [reactionPickerOpen, setReactionPickerOpen] = useState(false);
43
42
 
44
43
  const replyActive = !previewMode && canReply;
@@ -145,12 +144,9 @@ export const PostActions = ({
145
144
  onPress={() => setReactionPickerOpen((open) => !open)}
146
145
  className={cn(actionClass, 'justify-end', !reactActive && idleClass)}
147
146
  >
148
- <ThumbsUpIcon
149
- size={16}
150
- className={iconClass(reactActive, iReacted)}
151
- />
152
- <ThemedText className={labelClass(reactActive, iReacted)}>
153
- {t('posts.footer.react')}
147
+ <ThumbsUpIcon size={16} className={iconClass(reactActive, iLiked)} />
148
+ <ThemedText className={labelClass(reactActive, iLiked)}>
149
+ {t('posts.footer.like')}
154
150
  </ThemedText>
155
151
  </Button>
156
152
  <View className="flex-1 items-end">{shareButton}</View>
@@ -159,7 +155,7 @@ export const PostActions = ({
159
155
  <View className="flex-row gap-1 px-4 pb-2">
160
156
  <ReactionPicker
161
157
  myReactions={myReactions}
162
- onClose={() => setReactionPickerOpen(false)}
158
+ reactions={allowedReactions}
163
159
  onToggle={(reaction) => {
164
160
  setReactionPickerOpen(false);
165
161
  void toggleReaction(reaction);
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { Pressable } from 'react-native';
3
+ import { ThemedText } from '../../ui/themed-text';
4
+ import { cn } from '../../../lib/utils';
5
+
6
+ export interface ReactionButtonProps {
7
+ reaction: string;
8
+ /** Accessible label; defaults to the emoji itself. */
9
+ title?: string;
10
+ /** Highlight the emoji the profile has already attached. */
11
+ active?: boolean;
12
+ /** An emoji no longer in the allowed set but still attached — dim it. */
13
+ orphan?: boolean;
14
+ onPress: () => void;
15
+ }
16
+
17
+ /**
18
+ * A single emoji reaction control, shared by the post reaction picker and the
19
+ * jam reaction menu so tap/active styling lives in one place instead of
20
+ * drifting across copies.
21
+ */
22
+ export const ReactionButton = ({
23
+ reaction,
24
+ title,
25
+ active = false,
26
+ orphan = false,
27
+ onPress,
28
+ }: ReactionButtonProps) => (
29
+ <Pressable
30
+ accessibilityRole="button"
31
+ accessibilityLabel={title ?? reaction}
32
+ onPress={onPress}
33
+ className={cn(
34
+ 'shrink-0 rounded-md p-2',
35
+ active && 'bg-border',
36
+ orphan && 'opacity-60'
37
+ )}
38
+ >
39
+ <ThemedText className="text-lg">{reaction}</ThemedText>
40
+ </Pressable>
41
+ );
@@ -1,184 +1,103 @@
1
1
  /**
2
- * Native ReactionPicker render test (issue #80 review round 4).
2
+ * Regression test for the native `ReactionPicker` orphaned-reaction path
3
+ * (issue #276, round-5 review item #2) — the mirror of the web picker test.
4
+ * Orphans — reactions attached before the community removed the emoji from its
5
+ * allowed set — render after a divider, flagged `orphan` (dimmed by
6
+ * `ReactionButton`), and stay retractable; there is no divider/orphan section
7
+ * when every attached reaction is still allowed.
3
8
  *
4
- * Pins the picker contract on React Native, mirroring the web
5
- * ReactionPicker.test.tsx per the AGENTS.md sync rule: the row renders all 7
6
- * curated reactions plus the explicit close affordance, the current
7
- * profile's own reactions are highlighted, a tap calls `onToggle` with the
8
- * tapped emoji, and the close button fires `onClose`.
9
- *
10
- * Mirrors the inline-mock pattern of PostMenu.test.tsx / ShareMenu.test.tsx:
11
- * node jest env, every external import mocked; `@openpeepshq/common` is
12
- * stubbed with the real curated set so the row is asserted against the
13
- * actual REACTION_TYPES values.
9
+ * The RN primitives, i18n, and `ReactionButton` are stubbed to self-describing
10
+ * host tags (`RB_ALLOWED` / `RB_ORPHAN` / `DIVIDER`) so the assertions read the
11
+ * real picker's orphan computation and render order from the rendered tree.
14
12
  */
15
- import { type ReactNode } from 'react';
16
- import ReactTestRenderer from 'react-test-renderer';
17
-
18
- const REACTION_TYPES = ['👍', '👎', '❤️', '😂', '😮', '😢', '🎉'];
19
- const CLOSE_LABEL = 'posts.actions.closeReactionPicker';
13
+ const React = require('react');
14
+ const ReactTestRenderer = require('react-test-renderer');
20
15
 
21
16
  jest.mock('react-native', () => {
22
- const React = require('react');
23
- const make = (tag: string) => (props: { children?: ReactNode }) => {
24
- const { children, ...rest } = props;
25
- return React.createElement(tag, rest, children);
26
- };
27
- return {
28
- View: make('View'),
29
- Pressable: make('Pressable'),
30
- };
17
+ const V = (props: { className?: string; children?: unknown }) =>
18
+ React.createElement(
19
+ props.className === 'mx-1 h-8 w-px shrink-0 bg-border'
20
+ ? 'DIVIDER'
21
+ : 'DIV',
22
+ null,
23
+ props.children
24
+ );
25
+ const T = (props: { children?: unknown }) =>
26
+ React.createElement('Text', null, props.children);
27
+ const P = (props: { children?: unknown }) =>
28
+ React.createElement('Pressable', null, props.children);
29
+ return { View: V, Text: T, Pressable: P };
31
30
  });
32
-
33
31
  jest.mock('react-i18next', () => ({
34
- useTranslation: () => ({
35
- t: (key: string, opts?: { defaultValue?: string }) =>
36
- opts?.defaultValue ?? key,
37
- }),
32
+ useTranslation: () => ({ t: (key: string) => key }),
38
33
  }));
39
-
40
- jest.mock('@openpeepshq/common', () => ({
41
- REACTION_TYPES,
34
+ jest.mock('./ReactionButton', () => ({
35
+ ReactionButton: (props: {
36
+ reaction?: string;
37
+ orphan?: boolean;
38
+ onPress?: () => void;
39
+ }) =>
40
+ React.createElement(
41
+ props.orphan ? 'RB_ORPHAN' : 'RB_ALLOWED',
42
+ { onPress: props.onPress },
43
+ props.reaction
44
+ ),
42
45
  }));
43
46
 
44
- jest.mock('../../ui/themed-text', () => {
45
- const React = require('react');
46
- return {
47
- ThemedText: (props: { children?: ReactNode }) =>
48
- React.createElement('Text', null, props.children),
49
- };
50
- });
51
-
52
- jest.mock('../../icons/index', () => ({
53
- XIcon: () => null,
54
- }));
55
-
56
- jest.mock('../../../lib/utils', () => ({
57
- cn: (...parts: Array<string | false | null | undefined>) =>
58
- parts.filter(Boolean).join(' '),
59
- }));
60
-
61
- import { ReactionPicker } from './ReactionPicker';
62
-
63
- type TreeNode = {
64
- type?: string;
65
- props?: Record<string, unknown> | null;
66
- children?: (TreeNode | string | null)[];
67
- };
47
+ const { ReactionPicker } = require('./ReactionPicker');
68
48
 
69
- function collectText(node: unknown, out: string[] = []): string[] {
70
- if (node === null || typeof node !== 'object') return out;
71
- const n = node as TreeNode;
72
- for (const c of n.children || []) {
73
- if (typeof c === 'string') out.push(c);
74
- else if (c) collectText(c, out);
75
- }
76
- return out;
77
- }
78
-
79
- /** Depth-first walk over the render tree, visiting every element node. */
80
- function walk(node: unknown, visit: (n: TreeNode) => void): void {
81
- if (node === null || typeof node !== 'object') return;
82
- const n = node as TreeNode;
83
- visit(n);
84
- for (const c of n.children || []) {
85
- if (typeof c !== 'string' && c !== null) walk(c, visit);
86
- }
87
- }
88
-
89
- /** The Pressable whose only text content is the given emoji. */
90
- function emojiPressable(json: unknown, emoji: string): TreeNode | undefined {
91
- let found: TreeNode | undefined;
92
- walk(json, (n) => {
93
- if (found || n.type !== 'Pressable') return;
94
- if (collectText(n).join('') === emoji) found = n;
95
- });
96
- return found;
97
- }
98
-
99
- const renderPicker = (props?: {
100
- myReactions?: string[];
101
- onToggle?: (reaction: string) => void;
102
- onClose?: () => void;
103
- }) => {
104
- const onToggle = props?.onToggle ?? jest.fn();
105
- const onClose = props?.onClose ?? jest.fn();
106
- let tree!: ReactTestRenderer.ReactTestRenderer;
49
+ const render = (
50
+ myReactions: string[],
51
+ reactions: readonly string[],
52
+ onToggle: (reaction: string) => void
53
+ ) => {
54
+ let tree!: ReturnType<typeof ReactTestRenderer.create>;
107
55
  ReactTestRenderer.act(() => {
108
56
  tree = ReactTestRenderer.create(
109
- <ReactionPicker
110
- myReactions={props?.myReactions ?? []}
111
- onToggle={onToggle}
112
- onClose={onClose}
113
- />
57
+ React.createElement(ReactionPicker, {
58
+ myReactions,
59
+ reactions,
60
+ onToggle,
61
+ })
114
62
  );
115
63
  });
116
- return { tree, onToggle, onClose };
64
+ return tree;
117
65
  };
118
66
 
119
- test('renders every curated reaction plus the close affordance', () => {
120
- const { tree } = renderPicker();
121
- const text = collectText(tree.toJSON());
122
- for (const emoji of REACTION_TYPES) {
123
- expect(text).toContain(emoji);
124
- }
125
- let sawClose = false;
126
- walk(tree.toJSON(), (n) => {
127
- if (n.props?.accessibilityLabel === CLOSE_LABEL) sawClose = true;
128
- });
129
- expect(sawClose).toBe(true);
130
- tree.unmount();
131
- });
132
-
133
- test('highlights only the reactions the current profile already attached', () => {
134
- const { tree } = renderPicker({ myReactions: ['❤️'] });
135
- const highlighted: string[] = [];
136
- walk(tree.toJSON(), (n) => {
137
- const className = n.props?.className;
138
- if (typeof className === 'string' && className.includes('bg-border')) {
139
- highlighted.push(...collectText(n));
140
- }
67
+ describe('ReactionPicker (native) orphans', () => {
68
+ it('renders the orphan (dimmed flag) after the divider', () => {
69
+ const tree = render(['🐰'], ['👍'], () => {});
70
+ const dividers = tree.root.findAllByType('DIVIDER');
71
+ const orphans = tree.root.findAllByType('RB_ORPHAN');
72
+ expect(dividers.length).toBe(1);
73
+ expect(orphans.length).toBe(1);
74
+ // The divider precedes the orphan in render order.
75
+ const all = tree.root.findAll(() => true);
76
+ const dividerIdx = all.findIndex((n) => n.type === 'DIVIDER');
77
+ const orphanIdx = all.findIndex((n) => n.type === 'RB_ORPHAN');
78
+ expect(dividerIdx).toBeGreaterThanOrEqual(0);
79
+ expect(dividerIdx).toBeLessThan(orphanIdx);
80
+ // The orphan row carries the emoji it retracts.
81
+ expect(orphans[0].children).toContain('🐰');
141
82
  });
142
- expect(highlighted).toEqual(['❤️']);
143
- tree.unmount();
144
- });
145
-
146
- test('gives each emoji button an accessibility label with the reaction name', () => {
147
- const { tree } = renderPicker();
148
- for (const emoji of REACTION_TYPES) {
149
- const button = emojiPressable(tree.toJSON(), emoji);
150
- expect(button).toBeTruthy();
151
- expect(button?.props?.accessibilityLabel).toBe(emoji);
152
- }
153
- tree.unmount();
154
- });
155
83
 
156
- test('tapping an emoji calls onToggle with that emoji', () => {
157
- const onToggle = jest.fn();
158
- const { tree } = renderPicker({ onToggle });
159
- const pressed = emojiPressable(tree.toJSON(), '😂');
160
- expect(pressed).toBeTruthy();
161
- ReactTestRenderer.act(() => {
162
- (pressed?.props?.onPress as () => void)();
84
+ it('retracts when the orphan is tapped', () => {
85
+ let toggled: string | undefined;
86
+ const tree = render(['👍', '🐰'], ['👍'], (r) => {
87
+ toggled = r;
88
+ });
89
+ const orphan = tree.root.findAllByType('RB_ORPHAN')[0];
90
+ expect(orphan.children).toContain('🐰');
91
+ // The orphan button is wired to retract its own emoji.
92
+ ReactTestRenderer.act(() => {
93
+ orphan.props.onPress();
94
+ });
95
+ expect(toggled).toBe('🐰');
163
96
  });
164
- expect(onToggle).toHaveBeenCalledTimes(1);
165
- expect(onToggle).toHaveBeenCalledWith('😂');
166
- tree.unmount();
167
- });
168
97
 
169
- test('the close button fires onClose without toggling a reaction', () => {
170
- const onToggle = jest.fn();
171
- const onClose = jest.fn();
172
- const { tree } = renderPicker({ onToggle, onClose });
173
- let closed = false;
174
- walk(tree.toJSON(), (n) => {
175
- if (n.props?.accessibilityLabel === CLOSE_LABEL && n.props?.onPress) {
176
- closed = true;
177
- ReactTestRenderer.act(() => (n.props.onPress as () => void)());
178
- }
98
+ it('renders no orphan section when every attached reaction is allowed', () => {
99
+ const tree = render(['👍', '🎉'], ['👍', '🎉'], () => {});
100
+ expect(tree.root.findAllByType('RB_ORPHAN').length).toBe(0);
101
+ expect(tree.root.findAllByType('DIVIDER').length).toBe(0);
179
102
  });
180
- expect(closed).toBe(true);
181
- expect(onClose).toHaveBeenCalledTimes(1);
182
- expect(onToggle).not.toHaveBeenCalled();
183
- tree.unmount();
184
103
  });
@@ -1,58 +1,57 @@
1
1
  import React from 'react';
2
- import { Pressable, View } from 'react-native';
3
- import { REACTION_TYPES } from '@openpeepshq/common';
2
+ import { View } from 'react-native';
4
3
  import type { ReactionData } from '@openpeepshq/common/types';
5
4
  import { useTranslation } from 'react-i18next';
6
- import { ThemedText } from '../../ui/themed-text';
7
- import { XIcon } from '../../icons/index';
8
- import { cn } from '../../../lib/utils';
5
+ import { ReactionButton } from './ReactionButton';
9
6
 
10
7
  export interface ReactionPickerProps {
11
8
  /** Reactions the current profile already attached to this post. */
12
9
  myReactions: string[];
10
+ /** Emojis the community allows on posts (from useAllowedReactions). */
11
+ reactions: readonly string[];
13
12
  onToggle: (reaction: ReactionData['reaction']) => void;
14
- /** Closes the picker (mirrors the web popover closing on outside click). */
15
- onClose: () => void;
16
13
  }
17
14
 
18
15
  /**
19
- * Post reaction selection: a row of the curated reactions. Tapping an emoji
20
- * toggles the current profile's reaction for the post (mirrors the jam
21
- * reaction menu). A close (dismiss) button at the end of the row lets the
22
- * picker be closed without re-tapping the React button, matching the web
23
- * picker's outside-click dismissal.
16
+ * Post reaction selection: a row of the community's allowed reactions, plus
17
+ * any of the profile's own reactions that are no longer allowed (orphans) so
18
+ * they stay visible and retractable. Tapping an emoji toggles the current
19
+ * profile's reaction for the post (mirrors the jam reaction menu).
24
20
  */
25
21
  export const ReactionPicker = ({
26
22
  myReactions,
23
+ reactions,
27
24
  onToggle,
28
- onClose,
29
25
  }: ReactionPickerProps) => {
30
26
  const { t } = useTranslation();
31
-
27
+ const orphans = myReactions.filter(
28
+ (reaction) => !reactions.includes(reaction)
29
+ );
32
30
  return (
33
31
  <View className="flex-row items-center gap-1">
34
- {REACTION_TYPES.map((reaction) => (
35
- <Pressable
32
+ {reactions.map((reaction) => (
33
+ <ReactionButton
36
34
  key={reaction}
37
- accessibilityRole="button"
38
- accessibilityLabel={reaction}
35
+ reaction={reaction}
36
+ active={myReactions.includes(reaction)}
39
37
  onPress={() => onToggle(reaction)}
40
- className={cn(
41
- 'shrink-0 rounded-md p-2',
42
- myReactions.includes(reaction) && 'bg-border'
43
- )}
44
- >
45
- <ThemedText className="text-lg">{reaction}</ThemedText>
46
- </Pressable>
38
+ />
47
39
  ))}
48
- <Pressable
49
- accessibilityRole="button"
50
- accessibilityLabel={t('posts.actions.closeReactionPicker')}
51
- onPress={onClose}
52
- className="shrink-0 rounded-md p-2"
53
- >
54
- <XIcon size={16} className="text-muted-foreground" />
55
- </Pressable>
40
+ {orphans.length > 0 ? (
41
+ <>
42
+ <View className="mx-1 h-8 w-px shrink-0 bg-border" />
43
+ {orphans.map((reaction) => (
44
+ <ReactionButton
45
+ key={reaction}
46
+ reaction={reaction}
47
+ orphan
48
+ active
49
+ title={t('posts.actions.orphanedReaction')}
50
+ onPress={() => onToggle(reaction)}
51
+ />
52
+ ))}
53
+ </>
54
+ ) : null}
56
55
  </View>
57
56
  );
58
57
  };
@@ -19,6 +19,7 @@ export * from './PostInfoHeader';
19
19
  export * from './PostMenu';
20
20
  export * from './PostReactionHeader';
21
21
  export * from './ReactionPicker';
22
+ export * from './ReactionButton';
22
23
  export * from './ShareMenu';
23
24
  export * from './UnreadPostIndicator';
24
25
  export * from './VideoPlayer';