@openpeepshq/rn-components 0.3.6 → 0.3.7

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 +1 -1
  2. package/src/components/custom/common/empty-state-container.tsx +42 -114
  3. package/src/components/custom/headers/tab-screens-header.tsx +3 -4
  4. package/src/components/custom/navigation/side-menu.tsx +2 -2
  5. package/src/components/navigation/auth-wrapper.tsx +1 -1
  6. package/src/components/notifications/NotificationItem.tsx +1 -1
  7. package/src/components/notifications/NotificationsList.tsx +5 -1
  8. package/src/components/post/Feed.tsx +3 -1
  9. package/src/components/post/FeedPost.tsx +32 -37
  10. package/src/components/post/FeedPostContent.tsx +6 -8
  11. package/src/components/post/feed/events/EventsFeed.tsx +1 -0
  12. package/src/components/post/pieces/PostActions.tsx +46 -121
  13. package/src/components/post/pieces/PostInfoHeader.tsx +9 -5
  14. package/src/components/post/post-form/Footer.tsx +47 -64
  15. package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +3 -0
  16. package/src/components/post/post-form/PollComposerFields.tsx +2 -2
  17. package/src/components/post/post-form/PostForm.tsx +133 -129
  18. package/src/components/post/types/Note.tsx +1 -1
  19. package/src/components/post/types/Poll.tsx +1 -1
  20. package/src/components/post/types/article/CardArticle.tsx +1 -1
  21. package/src/components/post/types/event/CardEvent.tsx +1 -1
  22. package/src/components/post/types/event/FullEvent.tsx +21 -20
  23. package/src/components/profile/ProfileCard.tsx +1 -1
  24. package/src/components/profile/ProfileHeader.tsx +8 -10
  25. package/src/pages/Explore.tsx +30 -5
  26. package/src/pages/Members.tsx +2 -2
  27. package/src/pages/conversations/Index.tsx +1 -1
  28. package/src/pages/conversations/New.tsx +8 -1
  29. package/src/pages/groups/Index.tsx +8 -1
  30. package/src/pages/groups/Info.tsx +4 -4
  31. package/src/pages/groups/Show.tsx +42 -3
  32. package/src/pages/posts/Edit.tsx +43 -5
  33. package/src/pages/posts/New.tsx +121 -74
  34. package/src/pages/posts/Reply.tsx +77 -49
  35. package/src/pages/profile/Followers.tsx +4 -1
  36. package/src/pages/profile/Following.tsx +4 -1
@@ -1,4 +1,10 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
1
+ import React, {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ } from 'react';
2
8
  import { useOpenpeeps } from '@openpeepshq/react';
3
9
  import {
4
10
  AudioPickerSheet,
@@ -6,12 +12,13 @@ import {
6
12
  type DocumentPickerSheetHandle,
7
13
  GenericHeader,
8
14
  ImagePickerSheet,
9
- VideoPickerSheet,
10
15
  } from '../../components/custom/index';
11
16
  import {
12
17
  MediaAttachment,
18
+ pollOptionsWithinLimit,
13
19
  PostCreationData,
14
20
  PublicPost,
21
+ resolvePollOptionContents,
15
22
  } from '@openpeepshq/common';
16
23
  import Toast from 'react-native-toast-message';
17
24
  import { ThemedSafeAreaView } from '../../components/ui/themed-safe-area-view';
@@ -28,14 +35,10 @@ import { MainScreenProps } from '../../components/navigation/types/index';
28
35
  import { BottomSheetModal } from '@gorhom/bottom-sheet';
29
36
  import { useTranslation } from 'react-i18next';
30
37
  import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
31
- import Footer from '../../components/post/post-form/Footer';
38
+ import { Footer } from '../../components/post/post-form/Footer';
39
+ import { PostTypeSwitcher } from '../../components/post/post-form/PostTypeSwitcher';
32
40
  import { useForm } from 'react-hook-form';
33
- import {
34
- hasProcessingAttachments,
35
- toArticle,
36
- toNote,
37
- toQuestion,
38
- } from '../../lib/post';
41
+ import { hasProcessingAttachments, toNote, toQuestion } from '../../lib/post';
39
42
  import { CompactReplyParent } from '../../components/post/CompactReplyParent';
40
43
 
41
44
  import { ReplyModal } from '../../components/post/index';
@@ -114,9 +117,40 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
114
117
  scrollRef.current?.scrollToEnd(false);
115
118
  }, [isPostLoading, post, postData]);
116
119
 
120
+ const trimmedContent = (postData?.data.content ?? '').trim();
121
+ const pollOptions =
122
+ postData?.data.type === 'question'
123
+ ? postData.data.options.map((option) => option.content)
124
+ : [];
125
+ const resolvedPollOptions = resolvePollOptionContents(pollOptions, (index) =>
126
+ t('posts.form.poll.option', { number: index + 1 })
127
+ );
128
+ const pollOptionsValid =
129
+ resolvedPollOptions.length >= 2 &&
130
+ pollOptionsWithinLimit(resolvedPollOptions);
131
+
132
+ const canSubmit = useMemo(() => {
133
+ if (!post || !postData || isPosting || attachmentsProcessing) {
134
+ return false;
135
+ }
136
+ if (postData.data.type === 'question') {
137
+ return trimmedContent.length > 0 && pollOptionsValid;
138
+ }
139
+ return (
140
+ (trimmedContent.length > 0 && trimmedContent.length <= 500) ||
141
+ (postData.data.attachments?.length ?? 0) > 0
142
+ );
143
+ }, [
144
+ attachmentsProcessing,
145
+ isPosting,
146
+ pollOptionsValid,
147
+ post,
148
+ postData,
149
+ trimmedContent.length,
150
+ ]);
151
+
117
152
  const handlePostCreation = async () => {
118
- if (!post) {
119
- Toast.show({ type: 'error', text1: t('posts.create.error') });
153
+ if (!post || !canSubmit) {
120
154
  return;
121
155
  }
122
156
 
@@ -132,14 +166,14 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
132
166
 
133
167
  handlePostSuccess();
134
168
  } catch {
135
- Toast.show({ type: 'error', text1: t('posts.create.error') });
169
+ Toast.show({ type: 'error', text1: t('posts.replyModal.errorToast') });
136
170
  } finally {
137
171
  setIsPosting(false);
138
172
  }
139
173
  };
140
174
 
141
175
  const handlePostSuccess = async () => {
142
- Toast.show({ type: 'success', text1: t('posts.create.success') });
176
+ Toast.show({ type: 'success', text1: t('posts.replyModal.successToast') });
143
177
  resetReplyData(id);
144
178
  navigation.navigate('TabNavigator', {
145
179
  screen: 'Feed',
@@ -147,7 +181,6 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
147
181
  };
148
182
 
149
183
  const imagePickerModalRef = useRef<BottomSheetModal>(null);
150
- const videoPickerModalRef = useRef<BottomSheetModal>(null);
151
184
  const audioPickerModalRef = useRef<BottomSheetModal>(null);
152
185
  const documentPickerModalRef = useRef<DocumentPickerSheetHandle>(null);
153
186
 
@@ -158,13 +191,6 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
158
191
  }
159
192
  }, [t]);
160
193
 
161
- const handleVideoModalPress = useCallback(async () => {
162
- const hasPermission = await checkMediaPermissions(t, 'video');
163
- if (hasPermission) {
164
- videoPickerModalRef.current?.present();
165
- }
166
- }, [t]);
167
-
168
194
  const handleAudioModalPress = useCallback(async () => {
169
195
  const hasPermission = await checkMediaPermissions(t, 'audio');
170
196
  if (hasPermission) {
@@ -187,21 +213,18 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
187
213
  [postData, form, setPostData]
188
214
  );
189
215
 
190
- const handleSwitchPollPress = useCallback(() => {
191
- const newPostData =
192
- postData.data.type === 'question'
193
- ? toNote(postData)
194
- : toQuestion(postData);
195
- form.reset(newPostData);
196
- setPostData(newPostData);
197
- }, [postData, form, setPostData]);
198
-
199
- const handleSwithToArticlePress = useCallback(() => {
200
- const newPostData =
201
- postData.type === 'article' ? toNote(postData) : toArticle(postData);
202
- form.reset(newPostData);
203
- setPostData(newPostData);
204
- }, [postData, form, setPostData]);
216
+ const handleSelectComposerType = useCallback(
217
+ (next: 'note' | 'question') => {
218
+ if (!postData || postData.data.type === next) {
219
+ return;
220
+ }
221
+ const newPostData =
222
+ next === 'question' ? toQuestion(postData) : toNote(postData);
223
+ form.reset(newPostData);
224
+ setPostData(newPostData);
225
+ },
226
+ [postData, form, setPostData]
227
+ );
205
228
 
206
229
  const handleDocumentModalPress = useCallback(async () => {
207
230
  const hasPermission = await checkMediaPermissions(t, 'file');
@@ -222,7 +245,7 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
222
245
  : t('posts.create.submit')
223
246
  }
224
247
  onRightButtonPress={handlePostCreation}
225
- rightButtonDisabled={isPosting || attachmentsProcessing}
248
+ rightButtonDisabled={!canSubmit}
226
249
  />
227
250
  <KeyboardAwareScrollView
228
251
  ref={scrollRef}
@@ -254,7 +277,7 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
254
277
  onPress={() => {}}
255
278
  className="inline-flex items-center "
256
279
  >
257
- <ThemedText className="text-lg text-blue-600">
280
+ <ThemedText className="text-lg text-primary">
258
281
  {`@${post?.profile.handle}`}
259
282
  </ThemedText>
260
283
  </TouchableWithoutFeedback>
@@ -266,7 +289,7 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
266
289
  onPress={() => {}}
267
290
  className="inline-flex items-center "
268
291
  >
269
- <ThemedText className="text-lg text-blue-600">
292
+ <ThemedText className="text-lg text-primary">
270
293
  {post.group.displayName}
271
294
  </ThemedText>
272
295
  </TouchableWithoutFeedback>
@@ -289,23 +312,28 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
289
312
  <ReplyModal ref={replyModalRef} onSelect={() => {}} id={id} />
290
313
  </KeyboardAwareScrollView>
291
314
  <Footer
292
- content={postData}
293
- postType={postData?.data?.type}
315
+ hideMedia={postData?.data.type === 'question'}
294
316
  onImagePress={handleImageModalPress}
295
- onMicPress={handleAudioModalPress}
296
- onVideoPress={handleVideoModalPress}
297
- onPollPress={handleSwitchPollPress}
317
+ onAudioPress={handleAudioModalPress}
298
318
  onDocumentPress={handleDocumentModalPress}
299
- onArticlePress={handleSwithToArticlePress}
319
+ typeSwitcher={
320
+ postData ? (
321
+ <PostTypeSwitcher
322
+ type={postData.data.type === 'question' ? 'question' : 'note'}
323
+ onSelect={handleSelectComposerType}
324
+ onClose={() => undefined}
325
+ showEventType={false}
326
+ showArticleType={false}
327
+ visibility={postData.visibility}
328
+ groupId={postData.groupId ?? undefined}
329
+ />
330
+ ) : undefined
331
+ }
300
332
  />
301
333
  <ImagePickerSheet
302
334
  ref={imagePickerModalRef}
303
335
  onSelect={handleAddAttachments}
304
336
  />
305
- <VideoPickerSheet
306
- ref={videoPickerModalRef}
307
- onSelect={handleAddAttachments}
308
- />
309
337
  <AudioPickerSheet
310
338
  ref={audioPickerModalRef}
311
339
  onSelect={handleAddAttachments}
@@ -35,7 +35,10 @@ export const Followers: React.FC<ProfileFollowersProps> = ({ route }) => {
35
35
  return <ProfileCard key={index} profile={follower} />;
36
36
  })}
37
37
  {profileFollowers?.length === 0 && (
38
- <EmptyStateContainer type="followers" />
38
+ <EmptyStateContainer
39
+ type="followers"
40
+ copyKey="profile.followers.noFollowing"
41
+ />
39
42
  )}
40
43
  </KeyboardAwareScrollView>
41
44
  </ThemedSafeAreaView>
@@ -34,7 +34,10 @@ export const Following: React.FC<ProfileFollowingProps> = ({ route }) => {
34
34
  return <ProfileCard key={index} profile={following} />;
35
35
  })}
36
36
  {profileFollowing?.length === 0 && (
37
- <EmptyStateContainer type="following" />
37
+ <EmptyStateContainer
38
+ type="following"
39
+ copyKey="profile.following.noFollowers"
40
+ />
38
41
  )}
39
42
  </KeyboardAwareScrollView>
40
43
  </ThemedSafeAreaView>