@openpeepshq/rn-components 0.15.0 → 0.17.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.
Files changed (36) hide show
  1. package/package.json +3 -3
  2. package/src/components/conversations/ConversationPreviewCard.tsx +2 -6
  3. package/src/components/custom/navigation/side-menu.test.tsx +212 -0
  4. package/src/components/custom/navigation/side-menu.tsx +3 -8
  5. package/src/components/groups/GroupCard.tsx +3 -6
  6. package/src/components/icons/index.ts +2 -0
  7. package/src/components/jams/JamChatDrawer.test.tsx +113 -41
  8. package/src/components/jams/JamChatDrawer.tsx +23 -20
  9. package/src/components/jams/JamVideoLayout.tsx +2 -2
  10. package/src/components/jams/useLateTrackMediaStream.test.ts +113 -24
  11. package/src/components/jams/useLateTrackMediaStream.ts +86 -24
  12. package/src/components/navigation/nativeRouter.tsx +13 -3
  13. package/src/components/notifications/NotificationHeaderActions.test.tsx +285 -0
  14. package/src/components/notifications/NotificationHeaderActions.tsx +91 -4
  15. package/src/components/notifications/NotificationsList.test.tsx +109 -0
  16. package/src/components/notifications/NotificationsList.tsx +13 -3
  17. package/src/components/notifications/types/Reaction.tsx +6 -2
  18. package/src/components/post/pieces/PostActions.test.tsx +244 -0
  19. package/src/components/post/pieces/PostActions.tsx +74 -49
  20. package/src/components/post/pieces/ReactionPicker.test.tsx +184 -0
  21. package/src/components/post/pieces/ReactionPicker.tsx +58 -0
  22. package/src/components/post/pieces/index.ts +1 -0
  23. package/src/components/post/pieces/modals/ReactionsModal.tsx +1 -1
  24. package/src/components/post/post-form/ResourceForm.tsx +1 -1
  25. package/src/components/profile/EditProfileForm.test.tsx +316 -0
  26. package/src/components/profile/EditProfileForm.tsx +33 -4
  27. package/src/components/ui/dropdown-menu.test.ts +332 -0
  28. package/src/components/ui/dropdown-menu.tsx +108 -19
  29. package/src/components/ui/index.ts +1 -0
  30. package/src/components/ui/unread-badge.test.tsx +111 -0
  31. package/src/components/ui/unread-badge.tsx +43 -0
  32. package/src/pages/Members.test.tsx +117 -0
  33. package/src/pages/Members.tsx +1 -1
  34. package/src/pages/Notifications.tsx +3 -1
  35. package/src/pages/Welcome.test.tsx +166 -0
  36. package/src/pages/Welcome.tsx +50 -4
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Native PostActions reaction-picker wiring (issue #80 review round 5).
3
+ *
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.
9
+ */
10
+ import { type ReactNode } from 'react';
11
+ import ReactTestRenderer from 'react-test-renderer';
12
+
13
+ const REACTION_TYPES = ['👍', '👎', '❤️', '😂', '😮', '😢', '🎉'];
14
+
15
+ // --- shared mutable state read by the module mocks (hoisting-safe) ---------
16
+ let toggleReaction: (reaction: string) => void | Promise<void> = jest.fn();
17
+ let toggleRepost: () => void | Promise<void> = jest.fn();
18
+ let reply: () => void = jest.fn();
19
+ const mockMyReactions: string[] = ['❤️'];
20
+ let mockCanReact = true;
21
+
22
+ let lastPickerProps:
23
+ | {
24
+ myReactions: string[];
25
+ onToggle: (r: string) => void;
26
+ onClose: () => void;
27
+ }
28
+ | undefined;
29
+ const buttonInstances: { onPress?: () => void }[] = [];
30
+
31
+ // --- react-native: host elements render as plain host tags ----------------
32
+ jest.mock('react-native', () => {
33
+ const React = require('react');
34
+ const make = (tag: string) => (props: { children?: ReactNode }) =>
35
+ React.createElement(tag, props, props.children);
36
+ return {
37
+ View: make('View'),
38
+ Pressable: make('Pressable'),
39
+ };
40
+ });
41
+
42
+ // --- i18n: resolve keys to their key name ---------------------------------
43
+ jest.mock('react-i18next', () => ({
44
+ useTranslation: () => ({
45
+ t: (key: string, opts?: { defaultValue?: string }) =>
46
+ opts?.defaultValue ?? key,
47
+ }),
48
+ }));
49
+
50
+ // --- the feed action hook under test --------------------------------------
51
+ jest.mock('@openpeepshq/react', () => ({
52
+ useFeedPostActions: () => ({
53
+ me: { id: 'me-1' },
54
+ myRepost: undefined,
55
+ iReacted: mockMyReactions.length > 0,
56
+ myReactions: mockMyReactions,
57
+ canReply: true,
58
+ canRepost: true,
59
+ canReact: mockCanReact,
60
+ reply,
61
+ toggleRepost,
62
+ toggleReaction,
63
+ }),
64
+ }));
65
+
66
+ // --- local UI: capture picker props and button presses --------------------
67
+ jest.mock('./ReactionPicker', () => ({
68
+ ReactionPicker: (props: {
69
+ myReactions: string[];
70
+ onToggle: (r: string) => void;
71
+ onClose: () => void;
72
+ }) => {
73
+ lastPickerProps = props;
74
+ return null;
75
+ },
76
+ }));
77
+
78
+ jest.mock('./ShareMenu', () => ({
79
+ ShareMenu: () => null,
80
+ }));
81
+
82
+ jest.mock('../../ui/button', () => {
83
+ const React = require('react');
84
+ return {
85
+ Button: (props: { children?: ReactNode; onPress?: () => void }) => {
86
+ buttonInstances.push(props);
87
+ return React.createElement('Button', props, props.children);
88
+ },
89
+ };
90
+ });
91
+
92
+ jest.mock('../../ui/themed-text', () => {
93
+ const React = require('react');
94
+ return {
95
+ ThemedText: (props: { children?: ReactNode }) =>
96
+ React.createElement('Text', null, props.children),
97
+ };
98
+ });
99
+
100
+ jest.mock('../../icons/index', () => ({
101
+ Repeat2Icon: () => null,
102
+ ReplyIcon: () => null,
103
+ ShareIcon: () => null,
104
+ ThumbsUpIcon: () => null,
105
+ }));
106
+
107
+ jest.mock('../../../lib/utils', () => ({
108
+ cn: (...parts: Array<string | false | null | undefined>) =>
109
+ parts.filter(Boolean).join(' '),
110
+ }));
111
+
112
+ jest.mock('@openpeepshq/common', () => ({ REACTION_TYPES }));
113
+
114
+ import { PostActions } from './PostActions';
115
+ import type { PublicPost } from '@openpeepshq/common/types';
116
+
117
+ const makePost = (): PublicPost => ({ id: 'post-1' }) as unknown as PublicPost;
118
+
119
+ type TreeNode = {
120
+ type?: string;
121
+ props?: Record<string, unknown> | null;
122
+ children?: (TreeNode | string | null)[];
123
+ };
124
+ function collectText(node: unknown, out: string[] = []): string[] {
125
+ if (node === null || typeof node !== 'object') return out;
126
+ const n = node as TreeNode;
127
+ for (const c of n.children || []) {
128
+ if (typeof c === 'string') out.push(c);
129
+ else if (c) collectText(c, out);
130
+ }
131
+ return out;
132
+ }
133
+ /** Depth-first walk visiting every element node. */
134
+ function walk(node: unknown, visit: (n: TreeNode) => void): void {
135
+ if (node === null || typeof node !== 'object') return;
136
+ const n = node as TreeNode;
137
+ visit(n);
138
+ for (const c of n.children || []) {
139
+ if (typeof c !== 'string' && c !== null) walk(c, visit);
140
+ }
141
+ }
142
+
143
+ const renderPostActions = (
144
+ post: PublicPost,
145
+ props: { previewMode?: boolean } = {}
146
+ ) => {
147
+ let tree!: ReactTestRenderer.ReactTestRenderer;
148
+ ReactTestRenderer.act(() => {
149
+ tree = ReactTestRenderer.create(<PostActions post={post} {...props} />);
150
+ });
151
+ return { tree };
152
+ };
153
+
154
+ /** The React button is the one whose text is the react footer label. */
155
+ const reactButtonPress = (json: unknown): (() => void) | undefined => {
156
+ let found: (() => void) | undefined;
157
+ walk(json, (n) => {
158
+ if (found || n.type !== 'Button') return;
159
+ if (collectText(n).includes('posts.footer.react')) {
160
+ found = n.props?.onPress as () => void;
161
+ }
162
+ });
163
+ return found;
164
+ };
165
+
166
+ /** The React button's `disabled` prop (undefined when the button is absent). */
167
+ const reactButtonDisabled = (json: unknown): boolean | undefined => {
168
+ let found: boolean | undefined;
169
+ walk(json, (n) => {
170
+ if (found !== undefined || n.type !== 'Button') return;
171
+ if (collectText(n).includes('posts.footer.react')) {
172
+ found = n.props?.disabled as boolean | undefined;
173
+ }
174
+ });
175
+ return found;
176
+ };
177
+
178
+ beforeEach(() => {
179
+ toggleReaction = jest.fn();
180
+ toggleRepost = jest.fn();
181
+ reply = jest.fn();
182
+ mockMyReactions.length = 0;
183
+ mockMyReactions.push('❤️');
184
+ mockCanReact = true;
185
+ lastPickerProps = undefined;
186
+ buttonInstances.length = 0;
187
+ });
188
+
189
+ test('tapping the React button opens the picker wired to the feed actions', () => {
190
+ const { tree } = renderPostActions(makePost());
191
+ const press = reactButtonPress(tree.toJSON());
192
+ expect(press).toBeTruthy();
193
+
194
+ expect(lastPickerProps).toBeUndefined();
195
+ ReactTestRenderer.act(() => {
196
+ press!();
197
+ });
198
+
199
+ expect(lastPickerProps).toBeDefined();
200
+ expect(lastPickerProps?.myReactions).toEqual(['❤️']);
201
+ tree.unmount();
202
+ });
203
+
204
+ test('picking an emoji from the open picker calls toggleReaction with it', () => {
205
+ const { tree } = renderPostActions(makePost());
206
+ ReactTestRenderer.act(() => {
207
+ reactButtonPress(tree.toJSON())!();
208
+ });
209
+ expect(lastPickerProps).toBeDefined();
210
+
211
+ ReactTestRenderer.act(() => {
212
+ lastPickerProps?.onToggle('😂');
213
+ });
214
+
215
+ expect(toggleReaction).toHaveBeenCalledTimes(1);
216
+ expect(toggleReaction).toHaveBeenCalledWith('😂');
217
+ tree.unmount();
218
+ });
219
+
220
+ test('the picker close control calls onClose without toggling a reaction', () => {
221
+ const { tree } = renderPostActions(makePost());
222
+ ReactTestRenderer.act(() => {
223
+ reactButtonPress(tree.toJSON())!();
224
+ });
225
+ expect(lastPickerProps).toBeDefined();
226
+
227
+ ReactTestRenderer.act(() => {
228
+ lastPickerProps?.onClose();
229
+ });
230
+
231
+ expect(toggleReaction).not.toHaveBeenCalled();
232
+ tree.unmount();
233
+ });
234
+
235
+ test('the React button renders disabled when the profile cannot react and has no reactions', () => {
236
+ // Native mirror of the web ReactionPicker contract: without the react
237
+ // capability and no existing reaction, the trigger is inert (the web path
238
+ // pins this in ReactionPicker.test.tsx).
239
+ mockCanReact = false;
240
+ mockMyReactions.length = 0;
241
+ const { tree } = renderPostActions(makePost());
242
+ expect(reactButtonDisabled(tree.toJSON())).toBe(true);
243
+ tree.unmount();
244
+ });
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { Pressable, View } from 'react-native';
3
3
  import { cn } from '../../../lib/utils';
4
4
  import { Button } from '../../ui/button';
@@ -12,6 +12,7 @@ import {
12
12
  import { type PublicPost } from '@openpeepshq/common';
13
13
  import { useTranslation } from 'react-i18next';
14
14
  import { useFeedPostActions } from '@openpeepshq/react';
15
+ import { ReactionPicker } from './ReactionPicker';
15
16
  import { ShareMenu } from './ShareMenu';
16
17
 
17
18
  interface PostActionsProps {
@@ -30,6 +31,7 @@ export const PostActions = ({
30
31
  me,
31
32
  myRepost,
32
33
  iReacted,
34
+ myReactions,
33
35
  canReply,
34
36
  canRepost,
35
37
  canReact,
@@ -37,6 +39,7 @@ export const PostActions = ({
37
39
  toggleRepost,
38
40
  toggleReaction,
39
41
  } = useFeedPostActions(post);
42
+ const [reactionPickerOpen, setReactionPickerOpen] = useState(false);
40
43
 
41
44
  const replyActive = !previewMode && canReply;
42
45
  const repostActive = !previewMode && canRepost;
@@ -94,54 +97,76 @@ export const PostActions = ({
94
97
  }
95
98
 
96
99
  return (
97
- // A disabled control does not take the touch, so the feed card would open
98
- // the post. This row absorbs that tap and still yields to scrolling.
99
- <Pressable
100
- accessible={false}
101
- onPress={() => {}}
102
- className="w-full flex-row items-center py-2"
103
- >
104
- <Button
105
- variant="ghost"
106
- disabled={!replyActive}
107
- onPress={() => reply()}
108
- className={cn(actionClass, 'justify-start', !replyActive && idleClass)}
100
+ <>
101
+ {/* A disabled control does not take the touch, so the feed card would
102
+ open the post. This row absorbs that tap and still yields to
103
+ scrolling. */}
104
+ <Pressable
105
+ accessible={false}
106
+ onPress={() => {}}
107
+ className="w-full flex-row items-center py-2"
109
108
  >
110
- <ReplyIcon size={16} className={iconClass(replyActive, false)} />
111
- <ThemedText className={labelClass(replyActive, false)}>
112
- {t('posts.footer.reply')}
113
- </ThemedText>
114
- </Button>
115
- <Button
116
- variant="ghost"
117
- disabled={!repostActive}
118
- onPress={() => void toggleRepost()}
119
- className={cn(
120
- actionClass,
121
- 'justify-center',
122
- !repostActive && idleClass
123
- )}
124
- >
125
- <Repeat2Icon
126
- size={16}
127
- className={iconClass(repostActive, !!myRepost)}
128
- />
129
- <ThemedText className={labelClass(repostActive, !!myRepost)}>
130
- {t('posts.footer.repost')}
131
- </ThemedText>
132
- </Button>
133
- <Button
134
- variant="ghost"
135
- disabled={!reactActive}
136
- onPress={() => void toggleReaction()}
137
- className={cn(actionClass, 'justify-end', !reactActive && idleClass)}
138
- >
139
- <ThumbsUpIcon size={16} className={iconClass(reactActive, iReacted)} />
140
- <ThemedText className={labelClass(reactActive, iReacted)}>
141
- {t('posts.footer.like')}
142
- </ThemedText>
143
- </Button>
144
- <View className="flex-1 items-end">{shareButton}</View>
145
- </Pressable>
109
+ <Button
110
+ variant="ghost"
111
+ disabled={!replyActive}
112
+ onPress={() => reply()}
113
+ className={cn(
114
+ actionClass,
115
+ 'justify-start',
116
+ !replyActive && idleClass
117
+ )}
118
+ >
119
+ <ReplyIcon size={16} className={iconClass(replyActive, false)} />
120
+ <ThemedText className={labelClass(replyActive, false)}>
121
+ {t('posts.footer.reply')}
122
+ </ThemedText>
123
+ </Button>
124
+ <Button
125
+ variant="ghost"
126
+ disabled={!repostActive}
127
+ onPress={() => void toggleRepost()}
128
+ className={cn(
129
+ actionClass,
130
+ 'justify-center',
131
+ !repostActive && idleClass
132
+ )}
133
+ >
134
+ <Repeat2Icon
135
+ size={16}
136
+ className={iconClass(repostActive, !!myRepost)}
137
+ />
138
+ <ThemedText className={labelClass(repostActive, !!myRepost)}>
139
+ {t('posts.footer.repost')}
140
+ </ThemedText>
141
+ </Button>
142
+ <Button
143
+ variant="ghost"
144
+ disabled={!reactActive}
145
+ onPress={() => setReactionPickerOpen((open) => !open)}
146
+ className={cn(actionClass, 'justify-end', !reactActive && idleClass)}
147
+ >
148
+ <ThumbsUpIcon
149
+ size={16}
150
+ className={iconClass(reactActive, iReacted)}
151
+ />
152
+ <ThemedText className={labelClass(reactActive, iReacted)}>
153
+ {t('posts.footer.react')}
154
+ </ThemedText>
155
+ </Button>
156
+ <View className="flex-1 items-end">{shareButton}</View>
157
+ </Pressable>
158
+ {reactionPickerOpen ? (
159
+ <View className="flex-row gap-1 px-4 pb-2">
160
+ <ReactionPicker
161
+ myReactions={myReactions}
162
+ onClose={() => setReactionPickerOpen(false)}
163
+ onToggle={(reaction) => {
164
+ setReactionPickerOpen(false);
165
+ void toggleReaction(reaction);
166
+ }}
167
+ />
168
+ </View>
169
+ ) : null}
170
+ </>
146
171
  );
147
172
  };
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Native ReactionPicker render test (issue #80 review round 4).
3
+ *
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.
14
+ */
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';
20
+
21
+ 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
+ };
31
+ });
32
+
33
+ jest.mock('react-i18next', () => ({
34
+ useTranslation: () => ({
35
+ t: (key: string, opts?: { defaultValue?: string }) =>
36
+ opts?.defaultValue ?? key,
37
+ }),
38
+ }));
39
+
40
+ jest.mock('@openpeepshq/common', () => ({
41
+ REACTION_TYPES,
42
+ }));
43
+
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
+ };
68
+
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;
107
+ ReactTestRenderer.act(() => {
108
+ tree = ReactTestRenderer.create(
109
+ <ReactionPicker
110
+ myReactions={props?.myReactions ?? []}
111
+ onToggle={onToggle}
112
+ onClose={onClose}
113
+ />
114
+ );
115
+ });
116
+ return { tree, onToggle, onClose };
117
+ };
118
+
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
+ }
141
+ });
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
+
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)();
163
+ });
164
+ expect(onToggle).toHaveBeenCalledTimes(1);
165
+ expect(onToggle).toHaveBeenCalledWith('😂');
166
+ tree.unmount();
167
+ });
168
+
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
+ }
179
+ });
180
+ expect(closed).toBe(true);
181
+ expect(onClose).toHaveBeenCalledTimes(1);
182
+ expect(onToggle).not.toHaveBeenCalled();
183
+ tree.unmount();
184
+ });
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import { Pressable, View } from 'react-native';
3
+ import { REACTION_TYPES } from '@openpeepshq/common';
4
+ import type { ReactionData } from '@openpeepshq/common/types';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { ThemedText } from '../../ui/themed-text';
7
+ import { XIcon } from '../../icons/index';
8
+ import { cn } from '../../../lib/utils';
9
+
10
+ export interface ReactionPickerProps {
11
+ /** Reactions the current profile already attached to this post. */
12
+ myReactions: string[];
13
+ onToggle: (reaction: ReactionData['reaction']) => void;
14
+ /** Closes the picker (mirrors the web popover closing on outside click). */
15
+ onClose: () => void;
16
+ }
17
+
18
+ /**
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.
24
+ */
25
+ export const ReactionPicker = ({
26
+ myReactions,
27
+ onToggle,
28
+ onClose,
29
+ }: ReactionPickerProps) => {
30
+ const { t } = useTranslation();
31
+
32
+ return (
33
+ <View className="flex-row items-center gap-1">
34
+ {REACTION_TYPES.map((reaction) => (
35
+ <Pressable
36
+ key={reaction}
37
+ accessibilityRole="button"
38
+ accessibilityLabel={reaction}
39
+ 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>
47
+ ))}
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>
56
+ </View>
57
+ );
58
+ };
@@ -18,6 +18,7 @@ export * from './PostActions';
18
18
  export * from './PostInfoHeader';
19
19
  export * from './PostMenu';
20
20
  export * from './PostReactionHeader';
21
+ export * from './ReactionPicker';
21
22
  export * from './ShareMenu';
22
23
  export * from './UnreadPostIndicator';
23
24
  export * from './VideoPlayer';
@@ -29,7 +29,7 @@ export const ReactionsModal = ({
29
29
  </ThemedText>
30
30
  {reactions.map(({ reaction, profile }) => (
31
31
  <ProfileWithActionCard
32
- key={profile.id}
32
+ key={`${profile.id}-${reaction}`}
33
33
  profile={profile}
34
34
  leading={<ThemedText>{reaction}</ThemedText>}
35
35
  />
@@ -229,7 +229,7 @@ export const ResourceForm = ({
229
229
  className="items-center rounded-md border border-input px-3 py-2"
230
230
  >
231
231
  <ThemedText>
232
- {t('resources.form.addMedia', { defaultValue: 'Add files' })}
232
+ {t('resources.form.addMedia', { defaultValue: 'Add file' })}
233
233
  </ThemedText>
234
234
  </Pressable>
235
235
  ) : null}