@openpeepshq/rn-components 0.8.7 → 0.9.1

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.8.7",
3
+ "version": "0.9.1",
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,8 +142,8 @@
142
142
  "timezones-list": "^3.1.0",
143
143
  "validator": "^13.15.23",
144
144
  "zustand": "^5.0.3",
145
- "@openpeepshq/common": "^0.4.0",
146
- "@openpeepshq/react": "^0.8.6"
145
+ "@openpeepshq/react": "^0.9.1",
146
+ "@openpeepshq/common": "^0.5.0"
147
147
  },
148
148
  "devDependencies": {
149
149
  "@babel/core": "^7.26.7",
@@ -0,0 +1,138 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { ActivityIndicator, Pressable, ScrollView, View } from 'react-native';
3
+ import {
4
+ conversationLabel,
5
+ messagePreviewText,
6
+ profileName,
7
+ type DirectMessageSearchHit,
8
+ } from '@openpeepshq/common';
9
+ import { useCurrentProfile, useOpenpeeps } from '@openpeepshq/react';
10
+ import { useTranslation } from 'react-i18next';
11
+ import { UpdatingDate } from '../custom/date/updating-date';
12
+ import { Input } from '../ui/input';
13
+ import { ThemedText } from '../ui/themed-text';
14
+
15
+ export const DirectMessageSearch = ({
16
+ conversationId,
17
+ autoFocus,
18
+ onQueryChange,
19
+ onSelect,
20
+ }: {
21
+ conversationId?: string;
22
+ autoFocus?: boolean;
23
+ onQueryChange?: (query: string) => void;
24
+ onSelect: (hit: DirectMessageSearchHit) => void;
25
+ }) => {
26
+ const { t } = useTranslation();
27
+ const me = useCurrentProfile();
28
+ const { openpeepsApi } = useOpenpeeps();
29
+ const [input, setInput] = useState('');
30
+ const [query, setQuery] = useState('');
31
+
32
+ useEffect(() => {
33
+ const handle = setTimeout(() => setQuery(input.trim()), 300);
34
+ return () => clearTimeout(handle);
35
+ }, [input]);
36
+
37
+ useEffect(() => {
38
+ onQueryChange?.(query);
39
+ }, [query, onQueryChange]);
40
+
41
+ const search = openpeepsApi.useSearchDirectMessages(query, conversationId);
42
+ const active = query.length >= 2;
43
+ const hits = search.data ?? [];
44
+ const placeholder = conversationId
45
+ ? t('conversations.search.inConversation', {
46
+ defaultValue: 'Search this conversation…',
47
+ })
48
+ : t('conversations.search.placeholder', {
49
+ defaultValue: 'Search all messages…',
50
+ });
51
+
52
+ return (
53
+ <View className="border-border gap-2 border-b p-3">
54
+ <Input
55
+ value={input}
56
+ onChangeText={setInput}
57
+ placeholder={placeholder}
58
+ accessibilityLabel={placeholder}
59
+ autoFocus={autoFocus}
60
+ autoCapitalize="none"
61
+ autoCorrect={false}
62
+ returnKeyType="search"
63
+ testID="dm-search-input"
64
+ />
65
+ {active && search.isFetching ? (
66
+ <View className="flex-row items-center gap-2">
67
+ <ActivityIndicator size="small" />
68
+ <ThemedText className="text-muted-foreground text-sm">
69
+ {t('conversations.search.searching', {
70
+ defaultValue: 'Searching…',
71
+ })}
72
+ </ThemedText>
73
+ </View>
74
+ ) : null}
75
+ {active && search.isError ? (
76
+ <ThemedText className="text-destructive text-sm">
77
+ {t('conversations.search.error', { defaultValue: 'Search failed' })}
78
+ </ThemedText>
79
+ ) : null}
80
+ {active && !search.isFetching && !search.isError && hits.length === 0 ? (
81
+ <ThemedText className="text-muted-foreground text-sm">
82
+ {t('conversations.search.empty', {
83
+ defaultValue: 'No messages match "{{query}}"',
84
+ query,
85
+ })}
86
+ </ThemedText>
87
+ ) : null}
88
+ {active && hits.length > 0 ? (
89
+ <ScrollView
90
+ style={{ maxHeight: 240 }}
91
+ accessibilityLabel={t('conversations.search.results', {
92
+ defaultValue: 'Message search results',
93
+ })}
94
+ testID="dm-search-results"
95
+ >
96
+ {hits.map((hit) => {
97
+ const senderId = hit.message.profile.id;
98
+ const sender =
99
+ senderId === me?.id
100
+ ? t('common.you', { defaultValue: 'You' })
101
+ : profileName(hit.message.profile);
102
+ const others = conversationLabel(hit.message, me?.id);
103
+ return (
104
+ <Pressable
105
+ key={hit.message.id}
106
+ className="rounded-md px-2 py-2"
107
+ accessibilityLabel={t('conversations.search.openResult', {
108
+ defaultValue: 'Show this message',
109
+ })}
110
+ testID="dm-search-result"
111
+ onPress={() => onSelect(hit)}
112
+ >
113
+ {!conversationId && others ? (
114
+ <ThemedText
115
+ className="text-sm font-semibold"
116
+ numberOfLines={1}
117
+ >
118
+ {others}
119
+ </ThemedText>
120
+ ) : null}
121
+ <ThemedText
122
+ className="text-muted-foreground text-sm"
123
+ numberOfLines={1}
124
+ >
125
+ {sender}
126
+ </ThemedText>
127
+ <UpdatingDate date={hit.message.createdAt} />
128
+ <ThemedText className="text-sm" numberOfLines={2}>
129
+ {messagePreviewText(hit.message)}
130
+ </ThemedText>
131
+ </Pressable>
132
+ );
133
+ })}
134
+ </ScrollView>
135
+ ) : null}
136
+ </View>
137
+ );
138
+ };
@@ -38,6 +38,7 @@ export interface MessageInThreadProps {
38
38
  message: PublicPost;
39
39
  multipleParticipants?: boolean;
40
40
  conversationRootId?: string;
41
+ highlighted?: boolean;
41
42
  }
42
43
 
43
44
  export const MessageInThread = ({
@@ -45,6 +46,7 @@ export const MessageInThread = ({
45
46
  message,
46
47
  multipleParticipants = true,
47
48
  conversationRootId,
49
+ highlighted = false,
48
50
  }: MessageInThreadProps) => {
49
51
  const { t } = useTranslation();
50
52
  const me = useCurrentProfile();
@@ -61,7 +63,7 @@ export const MessageInThread = ({
61
63
  const isMe = message.profile.id === me?.id;
62
64
 
63
65
  return (
64
- <>
66
+ <View className={highlighted ? 'bg-muted rounded-md' : undefined}>
65
67
  {!previous ? (
66
68
  <ThemedText className="mt-2 w-full text-center text-sm">
67
69
  {message.inReplyToId
@@ -126,6 +128,6 @@ export const MessageInThread = ({
126
128
  ) : null}
127
129
  <UpdatingDate date={message.createdAt} />
128
130
  </View>
129
- </>
131
+ </View>
130
132
  );
131
133
  };
@@ -4,5 +4,6 @@ export * from './ConversationPreviewCard';
4
4
  export * from './ConversationProfileHeader';
5
5
  export * from './ConversationSettingsSheet';
6
6
  export * from './CreateNewConversationContext';
7
+ export * from './DirectMessageSearch';
7
8
  export * from './DirectMessagesHeaderActions';
8
9
  export * from './MessageInThread';
@@ -29,6 +29,7 @@ export type MainStackParamList = {
29
29
  MyJams: undefined;
30
30
  Conversation: {
31
31
  id: string;
32
+ messageId?: string;
32
33
  };
33
34
  ConversationInfo: {
34
35
  id: string;
@@ -26,6 +26,7 @@ import { canCreatePost } from '@openpeepshq/common';
26
26
  import { BottomSheetModal } from '@gorhom/bottom-sheet';
27
27
  import {
28
28
  ConversationPreviewCard,
29
+ DirectMessageSearch,
29
30
  useCreateNewConversation,
30
31
  } from '../../components/conversations/index';
31
32
  import { useTranslation } from 'react-i18next';
@@ -47,6 +48,8 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
47
48
  const settingsRef = useRef<BottomSheetModal>(null);
48
49
  const [refreshing, setRefreshing] = useState(false);
49
50
  const [tab, setTab] = useState<ConversationsTab>('active');
51
+ const [messageSearch, setMessageSearch] = useState('');
52
+ const searching = messageSearch.trim().length >= 2;
50
53
 
51
54
  const query = openpeepsApi.useConversations();
52
55
  const archivedQuery = openpeepsApi.useArchivedConversations();
@@ -125,34 +128,52 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
125
128
  contentContainerClassName="grow"
126
129
  className="w-full flex bg-background relative p-2"
127
130
  >
128
- {isLoading && <ActivityIndicator size={'small'} />}
129
- {!isLoading && conversations?.length === 0 && (
130
- <View className="flex h-[80vh] items-center justify-center gap-2">
131
- <MessageCircleOffIcon size={40} className="text-muted-foreground" />
132
- <ThemedText className="text-muted-foreground">
133
- {t('conversations.empty', {
134
- defaultValue: 'No direct messages here',
135
- })}
136
- </ThemedText>
137
- </View>
131
+ {activeQuery.isError ? null : (
132
+ <DirectMessageSearch
133
+ onQueryChange={setMessageSearch}
134
+ onSelect={(hit) =>
135
+ navigation.navigate('Conversation', {
136
+ id: hit.conversationId,
137
+ messageId: hit.message.id,
138
+ })
139
+ }
140
+ />
141
+ )}
142
+ {searching ? null : (
143
+ <>
144
+ {isLoading && <ActivityIndicator size={'small'} />}
145
+ {!isLoading && conversations?.length === 0 && (
146
+ <View className="flex h-[80vh] items-center justify-center gap-2">
147
+ <MessageCircleOffIcon
148
+ size={40}
149
+ className="text-muted-foreground"
150
+ />
151
+ <ThemedText className="text-muted-foreground">
152
+ {t('conversations.empty', {
153
+ defaultValue: 'No direct messages here',
154
+ })}
155
+ </ThemedText>
156
+ </View>
157
+ )}
158
+ {!isLoading &&
159
+ conversations?.map((conversation, idx) => (
160
+ <ConversationPreviewCard
161
+ key={idx}
162
+ conversation={conversation}
163
+ unreadCount={
164
+ conversation[0]?.id
165
+ ? (unseenByConversation[conversation[0].id] ?? 0)
166
+ : 0
167
+ }
168
+ onPress={() =>
169
+ navigation.navigate('Conversation', {
170
+ id: conversation[0]?.id,
171
+ })
172
+ }
173
+ />
174
+ ))}
175
+ </>
138
176
  )}
139
- {!isLoading &&
140
- conversations?.map((conversation, idx) => (
141
- <ConversationPreviewCard
142
- key={idx}
143
- conversation={conversation}
144
- unreadCount={
145
- conversation[0]?.id
146
- ? (unseenByConversation[conversation[0].id] ?? 0)
147
- : 0
148
- }
149
- onPress={() =>
150
- navigation.navigate('Conversation', {
151
- id: conversation[0]?.id,
152
- })
153
- }
154
- />
155
- ))}
156
177
  </KeyboardAwareScrollView>
157
178
  <ConversationSettingsSheet
158
179
  ref={settingsRef}
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { MainScreenProps } from '../../components/navigation/types/index';
3
3
  import {
4
4
  adjustUnseenCounts,
5
+ apiErrorMessage,
5
6
  useOpenpeeps,
6
7
  usePostViewFlush,
7
8
  } from '@openpeepshq/react';
@@ -16,8 +17,9 @@ import {
16
17
  Platform,
17
18
  ActivityIndicator,
18
19
  } from 'react-native';
19
- import { InfoIcon } from '../../components/icons/index';
20
- import { MediaAttachmentData } from '@openpeepshq/common';
20
+ import Toast from 'react-native-toast-message';
21
+ import { InfoIcon, SearchIcon } from '../../components/icons/index';
22
+ import { MediaAttachmentData, type PublicPost } from '@openpeepshq/common';
21
23
  import { ComposeAttachments } from '../../components/post/post-form/ComposeAttachments';
22
24
  import { OpenpeepsMarkdownInput } from '../../components/post/post-form/OpenpeepsMarkdownInput';
23
25
  import { maxContentLength } from '../../lib/utils';
@@ -28,6 +30,7 @@ import { ThemedText } from '../../components/ui/themed-text';
28
30
  import {
29
31
  ConversationParticipantsModal,
30
32
  ConversationProfileHeader,
33
+ DirectMessageSearch,
31
34
  MessageInThread,
32
35
  } from '../../components/conversations/index';
33
36
 
@@ -56,19 +59,41 @@ const ConversationParticipantDetail = ({
56
59
  );
57
60
  };
58
61
 
62
+ const isMessageId = (value: string | undefined): value is string =>
63
+ !!value &&
64
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
65
+
59
66
  type ConversationProps = MainScreenProps<'Conversation'>;
60
67
 
61
68
  export const ConversationShow = ({ route, navigation }: ConversationProps) => {
62
69
  const { t } = useTranslation();
63
70
  const { id } = route.params;
71
+ const messageId = isMessageId(route.params.messageId)
72
+ ? route.params.messageId
73
+ : undefined;
64
74
  const { openpeepsApi, currentProfile, queryClient, client } = useOpenpeeps();
65
- const { data: messages, isLoading } = openpeepsApi.useConversation(id);
75
+ const conversationQuery = openpeepsApi.useConversation(id, messageId);
76
+ const [shownMessages, setShownMessages] = useState<PublicPost[]>([]);
77
+ const [shownFor, setShownFor] = useState(id);
78
+ const [searchOpen, setSearchOpen] = useState(false);
79
+ if (shownFor !== id) {
80
+ setShownFor(id);
81
+ setShownMessages([]);
82
+ setSearchOpen(false);
83
+ }
84
+ useEffect(() => {
85
+ if (conversationQuery.data) setShownMessages(conversationQuery.data);
86
+ }, [conversationQuery.data]);
87
+ const messages = shownMessages;
88
+ const isLoading = conversationQuery.isLoading && messages.length === 0;
66
89
  const markPostsSeen = openpeepsApi.markPostsSeenAction();
67
90
  const flushPostViews = usePostViewFlush();
68
91
  const [isSending, setIsSending] = useState(false);
69
92
  const [attachments, setAttachments] = useState<MediaAttachmentData[]>([]);
70
93
  const [content, setContent] = useState('');
71
94
  const scrollViewRef = useRef<ScrollView>(null);
95
+ const messageOffsets = useRef<Record<string, number>>({});
96
+ const scrolledToMessageRef = useRef<string | null>(null);
72
97
  const [participantsOpen, setParticipantsOpen] = useState(false);
73
98
 
74
99
  const sendMessage = openpeepsApi.createConversationPostAction({ id });
@@ -110,6 +135,10 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
110
135
  scrollViewRef.current?.scrollToEnd({ animated: true });
111
136
  } catch (error) {
112
137
  console.error('Failed to send message:', error);
138
+ Toast.show({
139
+ type: 'error',
140
+ text1: apiErrorMessage(error, t, t('conversations.sendError')),
141
+ });
113
142
  } finally {
114
143
  setIsSending(false);
115
144
  }
@@ -144,6 +173,12 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
144
173
  void markPostsSeen({ postIds: unseenIds });
145
174
  }, [id, currentProfile, messages, isLoading, markPostsSeen]);
146
175
 
176
+ const searchLabel = searchOpen
177
+ ? t('common.close', { defaultValue: 'Close' })
178
+ : t('conversations.search.toggle', {
179
+ defaultValue: 'Search this conversation',
180
+ });
181
+
147
182
  useSetPageHeader(
148
183
  isLoading ? undefined : (
149
184
  <ConversationProfileHeader
@@ -154,11 +189,27 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
154
189
  />
155
190
  ),
156
191
  isLoading ? undefined : (
157
- <TouchableOpacity
158
- onPress={() => navigation.navigate('ConversationInfo', { id })}
159
- >
160
- <InfoIcon size={18} className="text-foreground" />
161
- </TouchableOpacity>
192
+ <View className="flex-row items-center">
193
+ <TouchableOpacity
194
+ onPress={() => setSearchOpen((open) => !open)}
195
+ accessibilityRole="button"
196
+ accessibilityLabel={searchLabel}
197
+ accessibilityState={{ expanded: searchOpen }}
198
+ testID="conversation-search-toggle"
199
+ className={`rounded-md p-1.5 ${searchOpen ? 'bg-muted' : ''}`}
200
+ >
201
+ <SearchIcon
202
+ size={18}
203
+ className={searchOpen ? 'text-foreground' : 'text-muted-foreground'}
204
+ />
205
+ </TouchableOpacity>
206
+ <TouchableOpacity
207
+ onPress={() => navigation.navigate('ConversationInfo', { id })}
208
+ className="rounded-md p-1.5"
209
+ >
210
+ <InfoIcon size={18} className="text-foreground" />
211
+ </TouchableOpacity>
212
+ </View>
162
213
  )
163
214
  );
164
215
 
@@ -208,20 +259,62 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
208
259
  behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
209
260
  keyboardVerticalOffset={Platform.OS === 'ios' ? 90 : 0}
210
261
  >
262
+ {searchOpen ? (
263
+ <View nativeID="conversation-message-search">
264
+ <DirectMessageSearch
265
+ conversationId={id}
266
+ autoFocus
267
+ onSelect={(hit) => {
268
+ navigation.setParams({ messageId: hit.message.id });
269
+ setSearchOpen(false);
270
+ }}
271
+ />
272
+ </View>
273
+ ) : null}
211
274
  <ScrollView
212
275
  ref={scrollViewRef}
213
276
  className="flex-1 pb-8"
214
- onContentSizeChange={() =>
215
- scrollViewRef.current?.scrollToEnd({ animated: true })
216
- }
277
+ onContentSizeChange={() => {
278
+ if (!messageId) {
279
+ scrollViewRef.current?.scrollToEnd({ animated: true });
280
+ return;
281
+ }
282
+ // The messageId param persists, so scroll to the focused
283
+ // message only once — re-scrolling on every content change
284
+ // would fight the user while they read.
285
+ if (scrolledToMessageRef.current === messageId) return;
286
+ const y = messageOffsets.current[messageId];
287
+ if (y !== undefined) {
288
+ scrolledToMessageRef.current = messageId;
289
+ scrollViewRef.current?.scrollTo({ y, animated: true });
290
+ }
291
+ }}
217
292
  >
218
293
  {messages?.map((message, idx) => (
219
- <View key={message.id} className="px-2">
294
+ <View
295
+ key={message.id}
296
+ className="px-2"
297
+ onLayout={(event) => {
298
+ messageOffsets.current[message.id] =
299
+ event.nativeEvent.layout.y;
300
+ if (
301
+ message.id === messageId &&
302
+ scrolledToMessageRef.current !== messageId
303
+ ) {
304
+ scrolledToMessageRef.current = messageId;
305
+ scrollViewRef.current?.scrollTo({
306
+ y: event.nativeEvent.layout.y,
307
+ animated: true,
308
+ });
309
+ }
310
+ }}
311
+ >
220
312
  <MessageInThread
221
313
  previous={messages[idx - 1]}
222
314
  message={message}
223
315
  multipleParticipants={multipleParticipants}
224
316
  conversationRootId={id}
317
+ highlighted={message.id === messageId}
225
318
  />
226
319
  </View>
227
320
  ))}
@@ -5,6 +5,7 @@ import Toast from 'react-native-toast-message';
5
5
  import { useNewEvent } from '@openpeepshq/react';
6
6
  import { HeaderActionButton, useSetPageHeader } from '../../components/layout';
7
7
  import { ThemedView } from '../../components/ui/themed-view';
8
+ import { ThemedText } from '../../components/ui/themed-text';
8
9
  import { MainScreenProps } from '../../components/navigation/types/index';
9
10
  import { EventForm } from '../../components/post/index';
10
11
 
@@ -15,6 +16,7 @@ export const NewEvent = (_props: NewEventProps) => {
15
16
  const {
16
17
  postData,
17
18
  setPostData,
19
+ canCreate,
18
20
  canSubmit,
19
21
  submitting,
20
22
  error,
@@ -33,14 +35,32 @@ export const NewEvent = (_props: NewEventProps) => {
33
35
 
34
36
  useSetPageHeader(
35
37
  t('events.create.title'),
36
- <HeaderActionButton
37
- title={submitting ? t('common.submitting') : t('events.create.title')}
38
- onPress={() => void submit()}
39
- disabled={submitting || !canSubmit}
40
- loading={submitting}
41
- />
38
+ canCreate ? (
39
+ <HeaderActionButton
40
+ title={submitting ? t('common.submitting') : t('events.create.title')}
41
+ onPress={() => void submit()}
42
+ disabled={submitting || !canSubmit}
43
+ loading={submitting}
44
+ />
45
+ ) : undefined
42
46
  );
43
47
 
48
+ if (!canCreate) {
49
+ return (
50
+ <ThemedView
51
+ className="flex-1 items-center justify-center gap-2 px-6 py-16"
52
+ testID="events-create-not-allowed"
53
+ >
54
+ <ThemedText className="text-center text-xl font-semibold">
55
+ {t('events.create.notAllowed.title')}
56
+ </ThemedText>
57
+ <ThemedText className="text-muted-foreground text-center text-sm">
58
+ {t('events.create.notAllowed.description')}
59
+ </ThemedText>
60
+ </ThemedView>
61
+ );
62
+ }
63
+
44
64
  return (
45
65
  <ThemedView className="flex-1">
46
66
  <KeyboardAwareScrollView
@@ -5,7 +5,7 @@ import React, {
5
5
  useRef,
6
6
  useState,
7
7
  } from 'react';
8
- import { useOpenpeeps } from '@openpeepshq/react';
8
+ import { apiErrorMessage, useOpenpeeps } from '@openpeepshq/react';
9
9
  import {
10
10
  AudioPickerSheet,
11
11
  DocumentPickerSheet,
@@ -165,8 +165,11 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
165
165
  await createPost(postData as PostCreationData);
166
166
 
167
167
  handlePostSuccess();
168
- } catch {
169
- Toast.show({ type: 'error', text1: t('posts.replyModal.errorToast') });
168
+ } catch (err) {
169
+ Toast.show({
170
+ type: 'error',
171
+ text1: apiErrorMessage(err, t, t('posts.replyModal.errorToast')),
172
+ });
170
173
  } finally {
171
174
  setIsPosting(false);
172
175
  }