@openpeepshq/rn-components 0.3.6 → 0.3.8

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 (46) 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/common/index.ts +1 -0
  4. package/src/components/custom/common/plus-fab.tsx +23 -0
  5. package/src/components/custom/headers/tab-screens-header.tsx +3 -4
  6. package/src/components/custom/navigation/side-menu.tsx +40 -78
  7. package/src/components/icons/index.ts +6 -0
  8. package/src/components/jams/CreateNewJam.tsx +3 -4
  9. package/src/components/navigation/auth-wrapper.tsx +1 -1
  10. package/src/components/notifications/NotificationItem.tsx +1 -1
  11. package/src/components/notifications/NotificationsList.tsx +5 -1
  12. package/src/components/post/Feed.tsx +3 -1
  13. package/src/components/post/FeedPost.tsx +32 -37
  14. package/src/components/post/FeedPostContent.tsx +6 -8
  15. package/src/components/post/NewEventButton.tsx +3 -8
  16. package/src/components/post/NewNoteButton.tsx +3 -5
  17. package/src/components/post/feed/events/EventsFeed.tsx +1 -0
  18. package/src/components/post/pieces/PostActions.tsx +46 -121
  19. package/src/components/post/pieces/PostInfoHeader.tsx +9 -5
  20. package/src/components/post/post-form/Footer.tsx +47 -64
  21. package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +3 -0
  22. package/src/components/post/post-form/PollComposerFields.tsx +2 -2
  23. package/src/components/post/post-form/PostForm.tsx +133 -129
  24. package/src/components/post/types/Note.tsx +1 -1
  25. package/src/components/post/types/Poll.tsx +1 -1
  26. package/src/components/post/types/article/CardArticle.tsx +1 -1
  27. package/src/components/post/types/event/CardEvent.tsx +1 -1
  28. package/src/components/post/types/event/FullEvent.tsx +21 -20
  29. package/src/components/profile/ProfileCard.tsx +1 -1
  30. package/src/components/profile/ProfileHeader.tsx +8 -10
  31. package/src/pages/Explore.tsx +30 -5
  32. package/src/pages/Members.tsx +2 -2
  33. package/src/pages/Tags.tsx +8 -2
  34. package/src/pages/articles/Index.tsx +18 -2
  35. package/src/pages/conversations/Index.tsx +21 -4
  36. package/src/pages/conversations/New.tsx +8 -1
  37. package/src/pages/feeds/Local.tsx +8 -2
  38. package/src/pages/feeds/My.tsx +13 -3
  39. package/src/pages/groups/Index.tsx +23 -1
  40. package/src/pages/groups/Info.tsx +4 -4
  41. package/src/pages/groups/Show.tsx +42 -3
  42. package/src/pages/posts/Edit.tsx +43 -5
  43. package/src/pages/posts/New.tsx +121 -74
  44. package/src/pages/posts/Reply.tsx +77 -49
  45. package/src/pages/profile/Followers.tsx +4 -1
  46. package/src/pages/profile/Following.tsx +4 -1
@@ -8,17 +8,22 @@ import React, { useEffect, useRef } from 'react';
8
8
  import {
9
9
  TabScreensHeader,
10
10
  EmptyStateContainer,
11
+ PlusFab,
11
12
  } from '../../components/custom/index';
12
13
  import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
13
- import { useOpenpeeps } from '@openpeepshq/react';
14
- import { XIcon, SearchIcon } from '../../components/icons/index';
14
+ import { useAuthData, useOpenpeeps } from '@openpeepshq/react';
15
+ import {
16
+ MessageSquarePlusIcon,
17
+ SearchIcon,
18
+ XIcon,
19
+ } from '../../components/icons/index';
15
20
  import { CompositeScreenProps } from '@react-navigation/native';
16
21
  import { NativeStackScreenProps } from '@react-navigation/native-stack';
17
22
  import {
18
23
  TabStackParamList,
19
24
  MainStackParamList,
20
25
  } from '../../components/navigation/types/index';
21
- import { PublicPost } from '@openpeepshq/common';
26
+ import { canCreatePost, PublicPost } from '@openpeepshq/common';
22
27
  import { Input } from '../../components/ui/input';
23
28
  import { ThemedText } from '../../components/ui/themed-text';
24
29
  import { profileMatchesQuery } from '../../lib/utils';
@@ -27,6 +32,7 @@ import { BottomSheetModal } from '@gorhom/bottom-sheet';
27
32
  import {
28
33
  ConversationPreviewCard,
29
34
  DirectMessagesHeaderActions,
35
+ useCreateNewConversation,
30
36
  } from '../../components/conversations/index';
31
37
  import { useTranslation } from 'react-i18next';
32
38
 
@@ -39,6 +45,9 @@ type MessagesProps = CompositeScreenProps<
39
45
  export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
40
46
  const { openpeepsApi } = useOpenpeeps();
41
47
  const { t } = useTranslation();
48
+ const authData = useAuthData();
49
+ const canCreate = canCreatePost(authData, 'note', 'direct');
50
+ const { openCreateConversation } = useCreateNewConversation();
42
51
  const settingsRef = useRef<BottomSheetModal>(null);
43
52
  const [refreshing, setRefreshing] = React.useState(false);
44
53
  const [filteredConversations, setFilteredConversations] = React.useState<
@@ -136,7 +145,7 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
136
145
  >
137
146
  {isLoading && <ActivityIndicator size={'small'} />}
138
147
  {!isLoading && filteredConversations?.length === 0 && (
139
- <EmptyStateContainer type="messages" />
148
+ <EmptyStateContainer type="messages" copyKey="conversations.empty" />
140
149
  )}
141
150
  {!isLoading &&
142
151
  filteredConversations?.map((conversation, idx) => (
@@ -156,6 +165,14 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
156
165
  />
157
166
  ))}
158
167
  </KeyboardAwareScrollView>
168
+ {canCreate ? (
169
+ <PlusFab
170
+ accessibilityLabel={t('conversations.newMessage')}
171
+ onPress={() => openCreateConversation()}
172
+ >
173
+ <MessageSquarePlusIcon size={24} className="text-background" />
174
+ </PlusFab>
175
+ ) : null}
159
176
  <ConversationSettingsSheet
160
177
  ref={settingsRef}
161
178
  onMessageRequestChange={(value) => {
@@ -118,7 +118,14 @@ export const NewConversation = ({
118
118
 
119
119
  {!isLoading && filteredProfiles?.length === 0 && (
120
120
  <View className="flex-1 items-center justify-center mt-4 pb-12">
121
- <EmptyStateContainer type="profiles" />
121
+ <EmptyStateContainer
122
+ type="profiles"
123
+ copyKey={
124
+ searchQuery
125
+ ? 'profile.selector.emptySearch'
126
+ : 'profile.selector.empty'
127
+ }
128
+ />
122
129
  </View>
123
130
  )}
124
131
  </KeyboardAwareScrollView>
@@ -4,12 +4,16 @@ import {
4
4
  TabStackParamList,
5
5
  MainStackParamList,
6
6
  } from '../../components/navigation/types/index';
7
- import { useFeedListParams, useOpenpeeps } from '@openpeepshq/react';
7
+ import {
8
+ useDefaultVisibility,
9
+ useFeedListParams,
10
+ useOpenpeeps,
11
+ } from '@openpeepshq/react';
8
12
  import { CompositeScreenProps } from '@react-navigation/native';
9
13
  import { TabScreensHeader } from '../../components/custom/index';
10
14
  import { ThemedText } from '../../components/ui/themed-text';
11
15
  import { useTranslation } from 'react-i18next';
12
- import { Feed } from '../../components/post/index';
16
+ import { Feed, NewNoteButton } from '../../components/post/index';
13
17
 
14
18
  type HomeScreenProps = CompositeScreenProps<
15
19
  NativeStackScreenProps<TabStackParamList, 'Home'>,
@@ -23,6 +27,7 @@ export const FeedsLocal: React.FC<HomeScreenProps> = () => {
23
27
  openpeepsApi.useServerInfo();
24
28
 
25
29
  const pinnedPostId = serverInfo?.communityConfig?.content?.pinnedPost;
30
+ const visibility = useDefaultVisibility();
26
31
 
27
32
  const query = openpeepsApi.useLocalFeed(useFeedListParams({ limit: 15 }));
28
33
 
@@ -41,6 +46,7 @@ export const FeedsLocal: React.FC<HomeScreenProps> = () => {
41
46
  pinnedPostId={pinnedPostId}
42
47
  refetchServerInfo={refetchServerInfo}
43
48
  />
49
+ <NewNoteButton visibility={visibility} />
44
50
  </>
45
51
  );
46
52
  };
@@ -4,30 +4,40 @@ import {
4
4
  TabStackParamList,
5
5
  MainStackParamList,
6
6
  } from '../../components/navigation/types/index';
7
- import { useFeedListParams, useOpenpeeps } from '@openpeepshq/react';
7
+ import {
8
+ useDefaultVisibility,
9
+ useFeedListParams,
10
+ useOpenpeeps,
11
+ } from '@openpeepshq/react';
8
12
  import { CompositeScreenProps } from '@react-navigation/native';
9
13
  import { TabScreensHeader } from '../../components/custom/index';
10
14
  import { ThemedText } from '../../components/ui/themed-text';
11
15
 
12
- import { Feed } from '../../components/post/index';
16
+ import { useTranslation } from 'react-i18next';
17
+ import { Feed, NewNoteButton } from '../../components/post/index';
13
18
  type HomeScreenProps = CompositeScreenProps<
14
19
  NativeStackScreenProps<TabStackParamList, 'Feed'>,
15
20
  NativeStackScreenProps<MainStackParamList>
16
21
  >;
17
22
 
18
23
  export const FeedsMy: React.FC<HomeScreenProps> = () => {
24
+ const { t } = useTranslation();
19
25
  const { openpeepsApi } = useOpenpeeps();
20
26
 
21
27
  const query = openpeepsApi.useMyFeed(useFeedListParams({ limit: 15 }));
28
+ const visibility = useDefaultVisibility();
22
29
 
23
30
  return (
24
31
  <>
25
32
  <TabScreensHeader
26
33
  children={
27
- <ThemedText className="text-xl font-bold">My feed</ThemedText>
34
+ <ThemedText className="text-xl font-bold">
35
+ {t('navigation.myFeed')}
36
+ </ThemedText>
28
37
  }
29
38
  />
30
39
  <Feed query={query} />
40
+ <NewNoteButton visibility={visibility} />
31
41
  </>
32
42
  );
33
43
  };
@@ -9,14 +9,17 @@ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view
9
9
  import { CompositeScreenProps } from '@react-navigation/native';
10
10
  import { NativeStackScreenProps } from '@react-navigation/native-stack';
11
11
 
12
+ import { checkRoleCapabilities } from '@openpeepshq/common';
12
13
  import {
13
14
  CheckIcon,
14
15
  MoreVerticalIcon,
16
+ PlusIcon,
15
17
  SearchIcon,
16
18
  XIcon,
17
19
  } from '../../components/icons/index';
18
20
  import {
19
21
  EmptyStateContainer,
22
+ PlusFab,
20
23
  TabScreensHeader,
21
24
  } from '../../components/custom/index';
22
25
  import { ThemedView } from '../../components/ui/themed-view';
@@ -29,6 +32,7 @@ import {
29
32
  DropdownMenuItem,
30
33
  DropdownMenuTrigger,
31
34
  } from '../../components/ui/dropdown-menu';
35
+ import { useTranslation } from 'react-i18next';
32
36
  import { useOpenpeeps } from '@openpeepshq/react';
33
37
  import {
34
38
  MainStackParamList,
@@ -42,6 +46,7 @@ type GroupsProps = CompositeScreenProps<
42
46
  >;
43
47
 
44
48
  export const GroupsIndex: React.FC<GroupsProps> = ({ navigation }) => {
49
+ const { t } = useTranslation();
45
50
  const { openpeepsApi, currentProfile } = useOpenpeeps();
46
51
  const { data: groups, refetch, isLoading } = openpeepsApi.useGroups();
47
52
  const unseenCountsQuery = openpeepsApi.useUnseenPostCounts();
@@ -151,7 +156,14 @@ export const GroupsIndex: React.FC<GroupsProps> = ({ navigation }) => {
151
156
  >
152
157
  {isLoading && <ActivityIndicator size={'small'} />}
153
158
  {!isLoading && visibleGroups.length === 0 && (
154
- <EmptyStateContainer type="groups" />
159
+ <EmptyStateContainer
160
+ type="groups"
161
+ copyKey={
162
+ !searchQuery && filterBy === 'my-groups'
163
+ ? 'groups.noGroupsYet'
164
+ : 'groups.noGroupsFound'
165
+ }
166
+ />
155
167
  )}
156
168
  {!isLoading &&
157
169
  visibleGroups.map((group) => (
@@ -169,6 +181,16 @@ export const GroupsIndex: React.FC<GroupsProps> = ({ navigation }) => {
169
181
  ))}
170
182
  <View className="mb-24" />
171
183
  </KeyboardAwareScrollView>
184
+ {checkRoleCapabilities(currentProfile?.roles ?? [], [
185
+ 'core-groups-create',
186
+ ]).success ? (
187
+ <PlusFab
188
+ accessibilityLabel={t('groups.new')}
189
+ onPress={() => navigation.navigate('CreateGroup')}
190
+ >
191
+ <PlusIcon size={24} className="text-background" />
192
+ </PlusFab>
193
+ ) : null}
172
194
  </ThemedView>
173
195
  );
174
196
  };
@@ -51,13 +51,13 @@ export const GroupInfo = ({ route }: GroupInfoProps) => {
51
51
  <>
52
52
  <ThemedText className="text-2xl">About Group</ThemedText>
53
53
 
54
- <View className="py-4 my-4 border-b-2 border-b-gray-500">
54
+ <View className="my-4 border-b border-border py-4">
55
55
  <ThemedText className="text-lg font-semibold">
56
56
  Description
57
57
  </ThemedText>
58
58
  <OpenpeepsMarkdown source={groupData?.description || ''} />
59
59
  </View>
60
- <View className="py-4 my-4 border-b-2 border-b-gray-500 space-y-6">
60
+ <View className="my-4 space-y-6 border-b border-border py-4">
61
61
  <ThemedText className="text-lg font-semibold">Details</ThemedText>
62
62
 
63
63
  <ThemedText className="">
@@ -130,7 +130,7 @@ export const GroupInfoAsComponent: React.FC<GroupInfoAsComponentProps> = ({
130
130
  {isLoading && <ActivityIndicator size={'small'} />}
131
131
  {!isLoading && (
132
132
  <>
133
- <View className="border-b-2 border-b-gray-500">
133
+ <View className="border-b border-border">
134
134
  <ThemedText className="text-lg font-semibold">
135
135
  Description
136
136
  </ThemedText>
@@ -140,7 +140,7 @@ export const GroupInfoAsComponent: React.FC<GroupInfoAsComponentProps> = ({
140
140
  }
141
141
  />
142
142
  </View>
143
- <View className="py-4 my-2 border-b-2 border-b-gray-500 flex gap-y-2">
143
+ <View className="my-2 flex gap-y-2 border-b border-border py-4">
144
144
  <ThemedText className="text-lg font-semibold">Details</ThemedText>
145
145
  <View>
146
146
  <ThemedText className="font-semibold">Created</ThemedText>
@@ -1,5 +1,10 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { ActivityIndicator, RefreshControl, View } from 'react-native';
2
+ import {
3
+ ActivityIndicator,
4
+ Pressable,
5
+ RefreshControl,
6
+ View,
7
+ } from 'react-native';
3
8
  import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
4
9
  import { useTranslation } from 'react-i18next';
5
10
  import { CompositeScreenProps } from '@react-navigation/native';
@@ -52,6 +57,8 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
52
57
  const upcomingEvents = openpeepsApi.useGroupUpcomingEventsFeed(
53
58
  group?.id ?? ''
54
59
  );
60
+ const pastEvents = openpeepsApi.useGroupPastEventsFeed(group?.id ?? '');
61
+ const [eventsTab, setEventsTab] = useState<'upcoming' | 'past'>('upcoming');
55
62
 
56
63
  useEffect(
57
64
  () =>
@@ -68,7 +75,7 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
68
75
  };
69
76
 
70
77
  const tabClass = (value: Tab) =>
71
- tab === value ? 'border-b-2 border-foreground' : '';
78
+ tab === value ? 'border-b-2 border-primary font-semibold' : '';
72
79
 
73
80
  return (
74
81
  <ThemedSafeAreaView className="relative flex-1">
@@ -117,7 +124,39 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
117
124
  <GroupFeed group={group} />
118
125
  </TabsContent>
119
126
  <TabsContent value="events" className="p-2">
120
- <EventsFeed query={upcomingEvents} />
127
+ <View className="mb-2 flex-row border-b border-border">
128
+ <Pressable
129
+ className={`px-4 py-2 ${
130
+ eventsTab === 'upcoming'
131
+ ? 'border-b-2 border-primary'
132
+ : ''
133
+ }`}
134
+ onPress={() => setEventsTab('upcoming')}
135
+ >
136
+ <ThemedText
137
+ className={
138
+ eventsTab === 'upcoming' ? 'font-semibold' : ''
139
+ }
140
+ >
141
+ {t('events.feed.upcoming')}
142
+ </ThemedText>
143
+ </Pressable>
144
+ <Pressable
145
+ className={`px-4 py-2 ${
146
+ eventsTab === 'past' ? 'border-b-2 border-primary' : ''
147
+ }`}
148
+ onPress={() => setEventsTab('past')}
149
+ >
150
+ <ThemedText
151
+ className={eventsTab === 'past' ? 'font-semibold' : ''}
152
+ >
153
+ {t('events.feed.past')}
154
+ </ThemedText>
155
+ </Pressable>
156
+ </View>
157
+ <EventsFeed
158
+ query={eventsTab === 'upcoming' ? upcomingEvents : pastEvents}
159
+ />
121
160
  </TabsContent>
122
161
  <TabsContent value="description" className="p-2">
123
162
  <GroupInfoAsComponent id={group.id} />
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import { useOpenpeeps } from '@openpeepshq/react';
3
3
  import { GenericHeader } from '../../components/custom/index';
4
4
  import Toast from 'react-native-toast-message';
@@ -6,7 +6,12 @@ import { ThemedSafeAreaView } from '../../components/ui/themed-safe-area-view';
6
6
  import { PostForm } from '../../components/post/post-form/PostForm';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { MainScreenProps } from '../../components/navigation/types/index';
9
- import { PostCreationData, postCreationDataSchema } from '@openpeepshq/common';
9
+ import {
10
+ PostCreationData,
11
+ pollOptionsWithinLimit,
12
+ postCreationDataSchema,
13
+ resolvePollOptionContents,
14
+ } from '@openpeepshq/common';
10
15
  import { ActivityIndicator } from 'react-native';
11
16
  import { useForm } from 'react-hook-form';
12
17
  import { hasProcessingAttachments } from '../../lib/post';
@@ -41,9 +46,42 @@ export const EditPost = ({ route, navigation }: PostProps) => {
41
46
  const [isPosting, setIsPosting] = useState(false);
42
47
  const attachmentsProcessing = hasProcessingAttachments(postData);
43
48
 
49
+ const trimmedContent = (postData?.data.content ?? '').trim();
50
+ const pollOptions =
51
+ postData?.data.type === 'question'
52
+ ? postData.data.options.map((option) => option.content)
53
+ : [];
54
+ const resolvedPollOptions = resolvePollOptionContents(pollOptions, (index) =>
55
+ t('posts.form.poll.option', { number: index + 1 })
56
+ );
57
+ const pollOptionsValid =
58
+ resolvedPollOptions.length >= 2 &&
59
+ pollOptionsWithinLimit(resolvedPollOptions);
60
+
61
+ const canSubmit = useMemo(() => {
62
+ if (!postData || isPosting || attachmentsProcessing) {
63
+ return false;
64
+ }
65
+ if (postData.data.type === 'question') {
66
+ return trimmedContent.length > 0 && pollOptionsValid;
67
+ }
68
+ if (postData.type === 'article') {
69
+ return trimmedContent.length > 0;
70
+ }
71
+ return (
72
+ (trimmedContent.length > 0 && trimmedContent.length <= 500) ||
73
+ (postData.data.attachments?.length ?? 0) > 0
74
+ );
75
+ }, [
76
+ attachmentsProcessing,
77
+ isPosting,
78
+ pollOptionsValid,
79
+ postData,
80
+ trimmedContent.length,
81
+ ]);
82
+
44
83
  const handlePostUpdate = async () => {
45
- if (!postData || !post?.data) {
46
- Toast.show({ type: 'error', text1: t('posts.create.error') });
84
+ if (!postData || !post?.data || !canSubmit) {
47
85
  return;
48
86
  }
49
87
 
@@ -89,7 +127,7 @@ export const EditPost = ({ route, navigation }: PostProps) => {
89
127
  : t('posts.edit.submit')
90
128
  }
91
129
  onRightButtonPress={handlePostUpdate}
92
- rightButtonDisabled={isPosting || attachmentsProcessing}
130
+ rightButtonDisabled={!canSubmit}
93
131
  />
94
132
  {postData && (
95
133
  <>