@openpeepshq/rn-components 0.24.0 → 0.28.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 (26) hide show
  1. package/package.json +2 -2
  2. package/src/components/conversations/ConversationPreviewCard.test.tsx +345 -0
  3. package/src/components/conversations/ConversationPreviewCard.tsx +29 -24
  4. package/src/components/custom/navigation/side-menu.test.tsx +9 -0
  5. package/src/components/custom/navigation/side-menu.tsx +19 -3
  6. package/src/components/groups/GroupAvatar.test.tsx +20 -2
  7. package/src/components/groups/GroupAvatar.tsx +7 -1
  8. package/src/components/jams/JamCallParticipant.test.tsx +303 -0
  9. package/src/components/jams/JamCallParticipant.tsx +7 -1
  10. package/src/components/jams/useLateTrackMediaStream.test.ts +139 -25
  11. package/src/components/jams/useLateTrackMediaStream.ts +62 -19
  12. package/src/components/post/pieces/ShareMenu.test.tsx +105 -11
  13. package/src/components/post/pieces/ShareMenu.tsx +55 -10
  14. package/src/components/post/pieces/modals/SendToConversationModal.tsx +140 -0
  15. package/src/components/post/pieces/modals/ShareIntoGroupModal.tsx +121 -0
  16. package/src/components/post/pieces/modals/index.ts +2 -0
  17. package/src/components/post/pieces/sharePickers.test.tsx +819 -0
  18. package/src/components/profile/Avatar.test.tsx +19 -0
  19. package/src/components/profile/Avatar.tsx +9 -1
  20. package/src/lib/push-notifications.test.ts +244 -0
  21. package/src/lib/push-notifications.ts +65 -0
  22. package/src/pages/auth/Login.tsx +16 -2
  23. package/src/pages/conversations/Index.test.tsx +235 -0
  24. package/src/pages/conversations/Index.tsx +15 -16
  25. package/src/pages/settings/Account.test.tsx +4 -0
  26. package/src/pages/settings/Account.tsx +14 -0
@@ -16,8 +16,12 @@ import ReactTestRenderer from 'react-test-renderer';
16
16
  import { Share } from 'react-native';
17
17
  import Clipboard from '@react-native-clipboard/clipboard';
18
18
  import Toast from 'react-native-toast-message';
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
19
21
 
20
22
  let mockSignedIn = true;
23
+ let mockShareIntoGroup: jest.Mock = jest.fn();
24
+ let mockSendToConversation: jest.Mock = jest.fn();
21
25
 
22
26
  jest.mock('react-native', () => ({
23
27
  Share: { share: jest.fn() },
@@ -62,6 +66,8 @@ jest.mock('@openpeepshq/react', () => ({
62
66
  signedIn: mockSignedIn,
63
67
  isEvent: false,
64
68
  repost: jest.fn(),
69
+ shareIntoGroup: mockShareIntoGroup,
70
+ sendToConversation: mockSendToConversation,
65
71
  eventIcsFile: () => null,
66
72
  }),
67
73
  }));
@@ -69,9 +75,11 @@ jest.mock('@openpeepshq/react', () => ({
69
75
  jest.mock('../../icons/index', () => ({
70
76
  CalendarIcon: () => null,
71
77
  CopyIcon: () => null,
78
+ MessageCircleIcon: () => null,
72
79
  Repeat2Icon: () => null,
73
80
  SendIcon: () => null,
74
81
  ShareIcon: () => null,
82
+ UsersIcon: () => null,
75
83
  }));
76
84
 
77
85
  jest.mock('../../ui', () => {
@@ -99,6 +107,23 @@ jest.mock('../../../stores/useNewConversationStore', () => ({
99
107
  selector({ setContt: jest.fn() }),
100
108
  }));
101
109
 
110
+ jest.mock('./modals/index', () => {
111
+ const React = require('react');
112
+ return {
113
+ // The real modals pull in @gorhom/bottom-sheet (→ react-native-gesture-handler),
114
+ // whose native module is absent from the node jest env. Render a stub the
115
+ // tests can assert against so we can confirm the pickers open on tap.
116
+ ShareIntoGroupModal: (props: { open?: boolean }) =>
117
+ props.open
118
+ ? React.createElement('View', { testID: 'share-into-group-modal' })
119
+ : null,
120
+ SendToConversationModal: (props: { open?: boolean }) =>
121
+ props.open
122
+ ? React.createElement('View', { testID: 'send-to-conversation-modal' })
123
+ : null,
124
+ };
125
+ });
126
+
102
127
  import { ShareMenu } from './ShareMenu';
103
128
 
104
129
  type TreeNode = {
@@ -109,22 +134,34 @@ type TreeNode = {
109
134
 
110
135
  function collectText(node: unknown, out: string[] = []): string[] {
111
136
  if (node === null || typeof node !== 'object') return out;
112
- const n = node as TreeNode;
113
- for (const c of n.children || []) {
114
- if (typeof c === 'string') out.push(c);
115
- else if (c) collectText(c, out);
137
+ const nodes = Array.isArray(node) ? node : [node];
138
+ for (const entry of nodes) {
139
+ if (typeof entry === 'string') {
140
+ out.push(entry);
141
+ continue;
142
+ }
143
+ if (!entry) continue;
144
+ const n = entry as TreeNode;
145
+ for (const c of n.children || []) {
146
+ if (typeof c === 'string') out.push(c);
147
+ else if (c) collectText(c, out);
148
+ }
116
149
  }
117
150
  return out;
118
151
  }
119
152
 
120
153
  function findByTestID(json: unknown, testID: string): TreeNode | undefined {
121
154
  if (json === null || typeof json !== 'object') return undefined;
122
- const node = json as TreeNode;
123
- if (node.props?.testID === testID) return node;
124
- for (const c of node.children || []) {
125
- if (typeof c !== 'string' && c !== null) {
126
- const found = findByTestID(c, testID);
127
- if (found) return found;
155
+ const nodes = Array.isArray(json) ? json : [json];
156
+ for (const entry of nodes) {
157
+ if (typeof entry === 'string' || entry === null) continue;
158
+ const node = entry as TreeNode;
159
+ if (node.props?.testID === testID) return node;
160
+ for (const c of node.children || []) {
161
+ if (typeof c !== 'string' && c !== null) {
162
+ const found = findByTestID(c, testID);
163
+ if (found) return found;
164
+ }
128
165
  }
129
166
  }
130
167
  return undefined;
@@ -142,6 +179,8 @@ beforeEach(() => {
142
179
  mockSignedIn = true;
143
180
  (Toast.show as jest.Mock).mockClear();
144
181
  (Clipboard.setString as jest.Mock).mockClear();
182
+ mockShareIntoGroup.mockClear();
183
+ mockSendToConversation.mockClear();
145
184
  });
146
185
 
147
186
  test('public post: external items, in-community items, and the section header render', () => {
@@ -151,17 +190,24 @@ test('public post: external items, in-community items, and the section header re
151
190
  expect(findByTestID(json, 'menu-Share via…')).toBeTruthy();
152
191
  expect(findByTestID(json, 'menu-Repost')).toBeTruthy();
153
192
  expect(findByTestID(json, 'menu-Send in message')).toBeTruthy();
193
+ expect(findByTestID(json, 'menu-Share into group…')).toBeTruthy();
194
+ expect(findByTestID(json, 'menu-Send to conversation…')).toBeTruthy();
154
195
  expect(collectText(json)).toContain('Other options');
155
196
  tree.unmount();
156
197
  });
157
198
 
158
- test('private post: external items and the orphaned section header are gone, repost/DM stay', () => {
199
+ test('private post: external items and the orphaned section header are gone, all in-community targets stay', () => {
159
200
  const tree = render({ id: 'post-2', visibility: 'private' });
160
201
  const json = tree.toJSON();
161
202
  expect(findByTestID(json, 'menu-Copy link')).toBeUndefined();
162
203
  expect(findByTestID(json, 'menu-Share via…')).toBeUndefined();
163
204
  expect(findByTestID(json, 'menu-Repost')).toBeTruthy();
164
205
  expect(findByTestID(json, 'menu-Send in message')).toBeTruthy();
206
+ // Link-only share: "Share into group…" is available for any post the
207
+ // viewer can see (the link is never a repost), so the public-source gate
208
+ // is gone; DM-thread sharing remains available.
209
+ expect(findByTestID(json, 'menu-Share into group…')).toBeTruthy();
210
+ expect(findByTestID(json, 'menu-Send to conversation…')).toBeTruthy();
165
211
  expect(collectText(json)).not.toContain('Other options');
166
212
  tree.unmount();
167
213
  });
@@ -202,11 +248,35 @@ test('signed-out viewer of a public post sees only external items, no in-communi
202
248
  expect(findByTestID(json, 'menu-Share via…')).toBeTruthy();
203
249
  expect(findByTestID(json, 'menu-Repost')).toBeUndefined();
204
250
  expect(findByTestID(json, 'menu-Send in message')).toBeUndefined();
251
+ expect(findByTestID(json, 'menu-Share into group…')).toBeUndefined();
252
+ expect(findByTestID(json, 'menu-Send to conversation…')).toBeUndefined();
205
253
  // No orphaned "Other options" header with nothing above it.
206
254
  expect(collectText(json)).not.toContain('Other options');
207
255
  tree.unmount();
208
256
  });
209
257
 
258
+ test('tap "Share into group…" opens the group picker (#1851)', () => {
259
+ const tree = render({ id: 'post-1', visibility: 'public' });
260
+ const item = findByTestID(tree.toJSON(), 'menu-Share into group…');
261
+ ReactTestRenderer.act(() => {
262
+ (item?.props?.onPress as () => void)();
263
+ });
264
+ expect(findByTestID(tree.toJSON(), 'share-into-group-modal')).toBeTruthy();
265
+ tree.unmount();
266
+ });
267
+
268
+ test('tap "Send to conversation…" opens the conversation picker (#1851)', () => {
269
+ const tree = render({ id: 'post-1', visibility: 'public' });
270
+ const item = findByTestID(tree.toJSON(), 'menu-Send to conversation…');
271
+ ReactTestRenderer.act(() => {
272
+ (item?.props?.onPress as () => void)();
273
+ });
274
+ expect(
275
+ findByTestID(tree.toJSON(), 'send-to-conversation-modal')
276
+ ).toBeTruthy();
277
+ tree.unmount();
278
+ });
279
+
210
280
  test('signed-out viewer of a non-public post gets no Share menu at all (#306 round 5 S1)', () => {
211
281
  mockSignedIn = false;
212
282
  const tree = render({ id: 'post-2', visibility: 'private' });
@@ -215,3 +285,27 @@ test('signed-out viewer of a non-public post gets no Share menu at all (#306 rou
215
285
  expect(tree.toJSON()).toBeNull();
216
286
  tree.unmount();
217
287
  });
288
+
289
+ // Review round 7 S1 (parity): the review claimed RN "shares link-only" while
290
+ // web appends a 200-char excerpt. That divergence does not exist — the link
291
+ // note (link + excerpt for public posts, link-only otherwise) is built by the
292
+ // SHARED `useShareMenu` hook, and RN wires `onSend={sendToConversation}` to
293
+ // exactly that hook function (via `@openpeepshq/react` → `react-native.ts` →
294
+ // `hooks/index.ts` → the same `useShareMenu.ts` web uses). This pins that
295
+ // contract in the source so a future platform-specific link-only copy can't
296
+ // silently reintroduce the divergence the review was worried about. The RN
297
+ // modal's own behavior (row list, onSend forwarding, toasts) is covered in
298
+ // sharePickers.test.tsx.
299
+ test('RN wires "Send to conversation…" to the shared useShareMenu hook, not a local link-only path (#1851 round 7 S1)', () => {
300
+ const src = fs.readFileSync(path.join(__dirname, 'ShareMenu.tsx'), 'utf8');
301
+ // The hook is consumed from the shared react package entry.
302
+ expect(src).toMatch(/from '@openpeepshq\/react'/);
303
+ expect(src).toMatch(/useShareMenu/);
304
+ // `sendToConversation` is destructured from the hook (not defined locally)
305
+ // and handed to the modal as its `onSend`.
306
+ expect(src).toMatch(/\bsendToConversation\b/);
307
+ expect(src).toMatch(/onSend=\{sendToConversation\}/);
308
+ // No local re-implementation of the share payload in this file (the hook
309
+ // owns the API call).
310
+ expect(src).not.toMatch(/createConversationPostAction/);
311
+ });
@@ -1,4 +1,4 @@
1
- import React, { type ReactNode } from 'react';
1
+ import React, { useState, type ReactNode } from 'react';
2
2
  import { Share } from 'react-native';
3
3
  import RNFS from 'react-native-fs';
4
4
  import Clipboard from '@react-native-clipboard/clipboard';
@@ -12,9 +12,11 @@ import { postPublicPath, useShareMenu } from '@openpeepshq/react';
12
12
  import {
13
13
  CalendarIcon,
14
14
  CopyIcon,
15
+ MessageCircleIcon,
15
16
  Repeat2Icon,
16
17
  SendIcon,
17
18
  ShareIcon,
19
+ UsersIcon,
18
20
  } from '../../icons/index';
19
21
  import {
20
22
  PopupMenu,
@@ -25,6 +27,7 @@ import {
25
27
  import { MainStackParamList } from '../../navigation/types/index';
26
28
  import { BASE_URL } from '../../../lib/constants';
27
29
  import { useNewConversationStore } from '../../../stores/useNewConversationStore';
30
+ import { SendToConversationModal, ShareIntoGroupModal } from './modals/index';
28
31
 
29
32
  export interface ShareMenuProps {
30
33
  post: PublicPost;
@@ -37,10 +40,16 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
37
40
  useNavigation<NativeStackNavigationProp<MainStackParamList>>();
38
41
  const setDraftMessage = useNewConversationStore((s) => s.setContt);
39
42
  const postUrl = `${BASE_URL}${postPublicPath(post)}`;
40
- const { signedIn, isEvent, repost, eventIcsFile } = useShareMenu(
41
- post,
42
- postUrl
43
- );
43
+ const [groupPickerOpen, setGroupPickerOpen] = useState(false);
44
+ const [conversationPickerOpen, setConversationPickerOpen] = useState(false);
45
+ const {
46
+ signedIn,
47
+ isEvent,
48
+ repost,
49
+ shareIntoGroup,
50
+ sendToConversation,
51
+ eventIcsFile,
52
+ } = useShareMenu(post, postUrl);
44
53
  // Repost/DM are valid for any post the viewer can see; handing the link to
45
54
  // the outside world only makes sense for publicly readable posts.
46
55
  const externallyShareable = isPubliclyShareable(post);
@@ -103,7 +112,7 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
103
112
  text={t('posts.shareMenu.repostToFeed', {
104
113
  defaultValue: 'Repost',
105
114
  })}
106
- icon={Repeat2Icon as any}
115
+ icon={Repeat2Icon}
107
116
  action={repost}
108
117
  />
109
118
  <PopupMenuButton
@@ -113,12 +122,34 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
113
122
  text={t('posts.shareMenu.sendInMessage', {
114
123
  defaultValue: 'Send in message',
115
124
  })}
116
- icon={SendIcon as any}
125
+ icon={SendIcon}
117
126
  action={() => {
118
127
  setDraftMessage(postUrl);
119
128
  navigation.navigate('SelectPrivateMessageMembers');
120
129
  }}
121
130
  />
131
+ {/* Link-only share: available for any post the viewer can see,
132
+ including private sources (the link is never a repost). */}
133
+ <PopupMenuButton
134
+ title={t('posts.shareMenu.shareIntoGroup', {
135
+ defaultValue: 'Share into group…',
136
+ })}
137
+ text={t('posts.shareMenu.shareIntoGroup', {
138
+ defaultValue: 'Share into group…',
139
+ })}
140
+ icon={UsersIcon}
141
+ action={() => setGroupPickerOpen(true)}
142
+ />
143
+ <PopupMenuButton
144
+ title={t('posts.shareMenu.sendToConversation', {
145
+ defaultValue: 'Send to conversation…',
146
+ })}
147
+ text={t('posts.shareMenu.sendToConversation', {
148
+ defaultValue: 'Send to conversation…',
149
+ })}
150
+ icon={MessageCircleIcon}
151
+ action={() => setConversationPickerOpen(true)}
152
+ />
122
153
  </>
123
154
  ) : null}
124
155
  {signedIn && (isEvent || externallyShareable) ? (
@@ -139,7 +170,7 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
139
170
  text={t('posts.shareMenu.downloadCalendarIcs', {
140
171
  defaultValue: 'Add to calendar (.ics)',
141
172
  })}
142
- icon={CalendarIcon as any}
173
+ icon={CalendarIcon}
143
174
  action={shareEventIcs}
144
175
  />
145
176
  ) : null}
@@ -152,7 +183,7 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
152
183
  text={t('posts.shareMenu.systemShare', {
153
184
  defaultValue: 'Share via…',
154
185
  })}
155
- icon={ShareIcon as any}
186
+ icon={ShareIcon}
156
187
  action={() => void systemShare()}
157
188
  />
158
189
  <PopupMenuButton
@@ -162,12 +193,26 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
162
193
  text={t('posts.shareMenu.copyLink', {
163
194
  defaultValue: 'Copy link',
164
195
  })}
165
- icon={CopyIcon as any}
196
+ icon={CopyIcon}
166
197
  action={copyLink}
167
198
  />
168
199
  </>
169
200
  ) : null}
170
201
  </PopupMenu>
202
+ {signedIn && groupPickerOpen ? (
203
+ <ShareIntoGroupModal
204
+ open
205
+ onClose={() => setGroupPickerOpen(false)}
206
+ onShare={shareIntoGroup}
207
+ />
208
+ ) : null}
209
+ {signedIn && conversationPickerOpen ? (
210
+ <SendToConversationModal
211
+ open
212
+ onClose={() => setConversationPickerOpen(false)}
213
+ onSend={sendToConversation}
214
+ />
215
+ ) : null}
171
216
  </>
172
217
  );
173
218
  };
@@ -0,0 +1,140 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Toast from 'react-native-toast-message';
5
+ import type { PublicPost } from '@openpeepshq/common/types';
6
+ import { truncateText } from '@openpeepshq/common/lib';
7
+ import {
8
+ conversationTitle,
9
+ useCurrentProfile,
10
+ useOpenpeeps,
11
+ } from '@openpeepshq/react';
12
+ import { useControlledSheet } from '../../../../hooks/use-controlled-sheet';
13
+ import { BaseSheet } from '../../../custom/modals/common';
14
+ import { ThemedText } from '../../../ui/themed-text';
15
+ import { LoadingSpinner } from '../../../ui/loading-spinner';
16
+ import { Button } from '../../../ui/button';
17
+
18
+ export interface SendToConversationModalProps {
19
+ open: boolean;
20
+ onClose: () => void;
21
+ /** Called with the chosen conversation; the caller posts the message. */
22
+ onSend: (conversation: PublicPost[]) => Promise<void>;
23
+ }
24
+
25
+ export const SendToConversationModal = ({
26
+ open,
27
+ onClose,
28
+ onSend,
29
+ }: SendToConversationModalProps) => {
30
+ const { t } = useTranslation();
31
+ const me = useCurrentProfile();
32
+ const { openpeepsApi } = useOpenpeeps();
33
+ const conversationsQuery = openpeepsApi.useConversations();
34
+ const ref = useControlledSheet(open);
35
+ const [sending, setSending] = useState<string | null>(null);
36
+
37
+ const conversations = useMemo(
38
+ () => (conversationsQuery.data ?? []).filter((c) => c.length > 0),
39
+ [conversationsQuery.data]
40
+ );
41
+
42
+ // The last post's audience is the current view; a leaver (or a
43
+ // note-to-self follow-up) can leave it with no other members, so fall back
44
+ // to the root post's participants before labeling it "You" (shared helper).
45
+ const conversationTitleFor = (conversation: PublicPost[]) =>
46
+ conversationTitle(conversation, t, me?.id, { fallbackToRoot: true });
47
+
48
+ const send = async (conversation: PublicPost[]) => {
49
+ const root = conversation[0];
50
+ if (!root || sending) return;
51
+ setSending(root.id);
52
+ try {
53
+ await onSend(conversation);
54
+ Toast.show({
55
+ type: 'success',
56
+ text1: t('posts.shareMenu.sentToConversation', {
57
+ defaultValue: 'Sent to {{name}}',
58
+ name: truncateText(conversationTitleFor(conversation), 30),
59
+ }),
60
+ });
61
+ onClose();
62
+ } catch {
63
+ Toast.show({
64
+ type: 'error',
65
+ text1: t('posts.shareMenu.shareFailed', {
66
+ defaultValue: "Couldn't share the post",
67
+ }),
68
+ });
69
+ } finally {
70
+ setSending(null);
71
+ }
72
+ };
73
+
74
+ return (
75
+ <BaseSheet
76
+ ref={ref}
77
+ snapPoints={['85%']}
78
+ scrollable
79
+ onDismiss={() => {
80
+ if (!sending) onClose();
81
+ }}
82
+ >
83
+ <View className="p-6 pb-2">
84
+ <ThemedText className="text-lg font-semibold">
85
+ {t('posts.shareMenu.sendToConversationPickerTitle', {
86
+ defaultValue: 'Send to conversation',
87
+ })}
88
+ </ThemedText>
89
+ </View>
90
+ {conversationsQuery.isLoading ? (
91
+ <View className="p-8">
92
+ <LoadingSpinner />
93
+ </View>
94
+ ) : conversations.length === 0 ? (
95
+ <ThemedText className="p-5 text-center text-sm text-muted-foreground">
96
+ {t('posts.shareMenu.noConversations', {
97
+ defaultValue: "You don't have any conversations yet",
98
+ })}
99
+ </ThemedText>
100
+ ) : (
101
+ conversations.map((conversation) => {
102
+ const root = conversation[0];
103
+ const last = conversation[conversation.length - 1];
104
+ if (!root || !last) return null;
105
+ const isMine =
106
+ last.data?.type === 'note' && last.profile?.id === me?.id;
107
+ return (
108
+ <Button
109
+ key={root.id}
110
+ variant="ghost"
111
+ className="min-h-[70px] flex-row items-center justify-between px-4 py-3"
112
+ disabled={sending !== null}
113
+ onPress={() => send(conversation)}
114
+ >
115
+ <View className="flex-1 flex-row items-center">
116
+ {sending === root.id ? (
117
+ <LoadingSpinner className="mr-2" />
118
+ ) : null}
119
+ <View className="flex-1">
120
+ <ThemedText className="text-foreground">
121
+ {truncateText(conversationTitleFor(conversation), 40)}
122
+ </ThemedText>
123
+ {last.data?.type === 'note' ? (
124
+ <ThemedText className="text-sm text-muted-foreground">
125
+ {isMine
126
+ ? t('common.you', { defaultValue: 'You' })
127
+ : `@${last.profile?.handle ?? ''}`}
128
+ {': '}
129
+ {truncateText(last.data.content, 40)}
130
+ </ThemedText>
131
+ ) : null}
132
+ </View>
133
+ </View>
134
+ </Button>
135
+ );
136
+ })
137
+ )}
138
+ </BaseSheet>
139
+ );
140
+ };
@@ -0,0 +1,121 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Toast from 'react-native-toast-message';
5
+ import type { GroupWithMeta } from '@openpeepshq/common/types';
6
+ import { checkGroupCapabilities, truncateText } from '@openpeepshq/common/lib';
7
+ import { useAuthData, useCurrentProfile } from '@openpeepshq/react';
8
+ import { useControlledSheet } from '../../../../hooks/use-controlled-sheet';
9
+ import { BaseSheet } from '../../../custom/modals/common';
10
+ import { ThemedText } from '../../../ui/themed-text';
11
+ import { LoadingSpinner } from '../../../ui/loading-spinner';
12
+ import { Button } from '../../../ui/button';
13
+
14
+ export interface ShareIntoGroupModalProps {
15
+ open: boolean;
16
+ onClose: () => void;
17
+ /**
18
+ * Called with the chosen group's id; the caller posts the post's link
19
+ * into it as a new note (never a repost).
20
+ */
21
+ onShare: (groupId: string) => Promise<void>;
22
+ }
23
+
24
+ export const ShareIntoGroupModal = ({
25
+ open,
26
+ onClose,
27
+ onShare,
28
+ }: ShareIntoGroupModalProps) => {
29
+ const { t } = useTranslation();
30
+ const me = useCurrentProfile();
31
+ const authData = useAuthData();
32
+ const ref = useControlledSheet(open);
33
+ const [sharing, setSharing] = useState<string | null>(null);
34
+
35
+ const groups = useMemo(
36
+ () =>
37
+ (me?.memberships ?? [])
38
+ .map((m) => m.group as GroupWithMeta)
39
+ .filter(
40
+ (g) =>
41
+ checkGroupCapabilities(authData, ['core-posts-create-note'], g)
42
+ .success
43
+ ),
44
+ [me?.memberships, authData]
45
+ );
46
+
47
+ const share = async (group: GroupWithMeta) => {
48
+ if (sharing) return;
49
+ setSharing(group.id);
50
+ try {
51
+ await onShare(group.id);
52
+ Toast.show({
53
+ type: 'success',
54
+ text1: t('posts.shareMenu.sharedIntoGroup', {
55
+ defaultValue: 'Shared into {{name}}',
56
+ name: truncateText(group.displayName || `@${group.handle}`, 30),
57
+ }),
58
+ });
59
+ onClose();
60
+ } catch {
61
+ Toast.show({
62
+ type: 'error',
63
+ text1: t('posts.shareMenu.shareFailed', {
64
+ defaultValue: "Couldn't share the post",
65
+ }),
66
+ });
67
+ } finally {
68
+ setSharing(null);
69
+ }
70
+ };
71
+
72
+ return (
73
+ <BaseSheet
74
+ ref={ref}
75
+ snapPoints={['85%']}
76
+ scrollable
77
+ onDismiss={() => {
78
+ if (!sharing) onClose();
79
+ }}
80
+ >
81
+ <View className="p-6 pb-2">
82
+ <ThemedText className="text-lg font-semibold">
83
+ {t('posts.shareMenu.shareIntoGroupPickerTitle', {
84
+ defaultValue: 'Share into group',
85
+ })}
86
+ </ThemedText>
87
+ </View>
88
+ {groups.length === 0 ? (
89
+ <ThemedText className="p-5 text-center text-sm text-muted-foreground">
90
+ {t('posts.shareMenu.noShareableGroups', {
91
+ defaultValue: "You can't post to any group",
92
+ })}
93
+ </ThemedText>
94
+ ) : (
95
+ groups.map((group) => (
96
+ <Button
97
+ key={group.id}
98
+ variant="ghost"
99
+ className="min-h-[70px] flex-row items-center justify-between px-4 py-3"
100
+ disabled={sharing !== null}
101
+ onPress={() => share(group)}
102
+ >
103
+ <View className="flex-1 flex-row items-center">
104
+ {sharing === group.id ? (
105
+ <LoadingSpinner className="mr-2" />
106
+ ) : null}
107
+ <View className="flex-1">
108
+ <ThemedText className="text-foreground">
109
+ {truncateText(group.displayName || `@${group.handle}`, 40)}
110
+ </ThemedText>
111
+ <ThemedText className="text-sm text-muted-foreground">
112
+ @{group.handle}
113
+ </ThemedText>
114
+ </View>
115
+ </View>
116
+ </Button>
117
+ ))
118
+ )}
119
+ </BaseSheet>
120
+ );
121
+ };
@@ -5,3 +5,5 @@ export * from './PostOptionsSheet';
5
5
  export * from './PostEditHistoryModal';
6
6
  export * from './ReactionsModal';
7
7
  export * from './RepostModal';
8
+ export * from './SendToConversationModal';
9
+ export * from './ShareIntoGroupModal';